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

General Discussion

Jon Thomas
Jon Thomas
8,916 Points

Treebook user_test for profile name gets Failed assertion, no message given

In the video under the "Building a profile page" section, I can't seem to get the test to pass. Even though I've updated the regular expression according to the video, I still get a failing test. However, I'm able to create a new user now.

Here is my validation code:

  validates :profile_name, presence: true, 
                       uniqueness: true,
                       format: {
                            with: /^[a-zA-z0-9_-]+$/,
                            message: 'Must be formatted correctly.'
                       }

and my test code

    test "a user can have a correctly formatted profile name" do
    user = User.new(first_name: 'Jon', last_name: 'Thomas', email: 'jon@clearfirestudios.com')
    user.password = user.password_confirmation = 'asdfasdf'

    user.profile_name = 'jon'
    assert user.valid?
end

and here is the output of running my test

F.....

Finished tests in 0.154115s, 38.9320 tests/s, 77.8639 assertions/s.

1) Failure: test_a_user_can_have_a_correctly_formatted_profile_name(UserTest) [test/unit/user_test.rb:44]: Failed assertion, no message given.

6 tests, 12 assertions, 1 failures, 0 errors, 0 skips

5 Answers

Jon Thomas
Jon Thomas
8,916 Points

I figured out what the issue was. Instead of using my real email address for the test, I needed to use a bogus different email address. Otherwise, it won't validate.

So, in my above code, where I was using jon@clearfirestudios.com, I had to change it to jon2@clearfirestudios.com, which they do in the video tutorial. I just was busy trying to type to keep up with the video and missed it. :-o

I had exactly the same issue! Thanks Jon

Brad Halstead
Brad Halstead
5,662 Points

Thanks Jon! I had the same problem too. Seemed that it passed earlier... I was so confused. I too, missed the part in the video that they changed the email address. Although upon changing the email address like you mentioned in your post and then ran the test, I still got the same failure. Then I changed the user profile name as well, and it passed! But again, thanks for pointing me in the right direction!!

Jon Thomas
Jon Thomas
8,916 Points

Interesting. I can't remember if I had to change the profile name as well. Glad it helped though!

Lisa Rossiter
Lisa Rossiter
3,630 Points

Cheers buddy, that helped I think there should be a side not on the video or something :)

Michael Sarlitt
Michael Sarlitt
3,140 Points

Agreed! I'd been pulling my hair out for a while until I saw this thread.