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

failed code question

can someone help with this I have been trying this for hours it seemed to be working fine until I got to this part so when I write the validates :profile_name, presence: true,uniqueness: true, format{ with: /a-zA-z0-9_-/, message: "Must be formatted correctly"} it says to use /[a-zA-Z0-9_-]+/, I get 1 failed message and 1 error message when I use /^[a-zA-z0-9_-]+$ I get the failed message. Finished tests in 0.124008s, 48.3840 tests/s, 96.7680 assertions/s.

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

6 tests, 12 assertions, 1 failures, 0 errors, 0 skips is there something I'm missing

7 Answers

Hi, here's a paste of my part of that code. Looks like the RegEx is a bit different than the ones you have there. Why don't you give this one a try and see if it works :)

format: {
  with: /^[a-zA-Z0-9_-]+$/,
  message: 'must be formatted correctly.'
}

ok i will try it afterwork and let u know if it worked did u see the bottom about assert user.valid? not working and assert user!valid? works

I don't see that, but that is very strange. "user!valid?" , is that even correct syntax? Looks like it could be some very strange way of doing "user.invalid?" which I guess could make it pass. But I wouldn't expect that syntax to work at all. Perhaps try with the RegEx first and see if it throws any errors?

Is this the part you are referring to? Here you have a paste from my code anyway, just to compare :)

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

  user.profile_name = "testuser_1"
  assert user.valid?
end

yes that one will not pass im on my cell so i see only part of the regex code the one im using is /^a-zA-Z0-9_-/+$ something like that let u know if it fixed it thank you for the help

yeah I just looked and that exactly what I have so this is the 2 failures I'm getting Finished tests in 0.160001s, 37.4998 tests/s, 74.9995 assertions/s.

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

2) Failure: test_a_user_should_have_a_profile_name_without_spaces(UserTest) [test/unit/user_test.rb:33]: Failed assertion, no message given.

6 tests, 12 assertions, 2 failures, 0 errors, 0 skips also statuses_controller_test failure i'm gettig 1) Failure: test_should_create_status_when_logged_in(StatusesControllerTest) [test/functional/statuses_controller_test.rb:35]: "Status.count" didn't change by 1. <3> expected but was <2>.

11 tests, 17 assertions, 1 failures, 0 errors, 0 skips

I don't really know enough about testing to say what this could be. It's also a bit hard to say when I can't look at the code. You can have a look at the Treebook repo I have on Github though. See if there is any difference anywhere. Perhaps you'll find some difference in the user model code or the test code. Feel free to post your github repo as well if you have one :)

https://github.com/mhovland/treebook

Thanks for trying to help. I zipped my files up and sent it to team support for Jason to look at them. again Thank you