Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby Build a Simple Ruby on Rails Application Writing Tests Validating Format

ArgumentError: wrong number of arguments (1 for 0)

I have followed the video but I got this error

1) Error:
UserTest#test_a_user_should_have_a_profile_name_without_spaces:
ArgumentError: wrong number of arguments (1 for 0)
    test/models/user_test.rb:35:in `block in <class:UserTest>

The code:

user_test

test "a user should have a profile name without spaces" do
    user = User.new
    user.profile_name = "My Profile With Spaces"
    assert !user.save
    assert !user.errors(:profile_name).empty?
    assert user.errors[:profile_name].include?("Must be formatted correctly.")
end

user.rb

validates :profile_name, presence: true,
                           uniqueness: true,
                           format: {
                                with: /a-zA-Z0-9_-/,
                                message: "Must be formatted correctly."
                           }

I'm using the latest rails and ruby versions. Any help?

4 Answers

Kang-Kyu Lee
Kang-Kyu Lee
52,045 Points
  validates :profile_name, format: {
    with: /\A[a-zA-Z\-\_]+\Z/,
    message: "must be formatted correctly."
  }

teacher's note of the video has different regular expression. (Not sure it's related.)

Kang-Kyu Lee
Kang-Kyu Lee
52,045 Points

Another thing we can try is this:

assert !user.errors(:profile_name).empty?

on this line of your code, change (parentheses) into [braket] because :profile_name is a hash key.

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

You need to use Rails 3.2 (ideally the virtual machine that Treehouse provides for this course) if you want to follow this course unless you know exactly how to translate things from 3.2 to the newest 4.1.x version.

Kang-Kyu Lee
Kang-Kyu Lee
52,045 Points

However this block doesn't have any variable. I don't see any. That's why that error message ArgumentError: wrong number of arguments (1 for 0) doesn't have a clue to me...