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 trialColin Stodd
3,160 PointsShould my "models/status.rb" file be named the same as my "fixtures/statuses.yml" file?
I'm having trouble trying to get my tests to pass on "Build a simiple rails app", And I've gone over everything dozens of times. But I noticed that my "models/status.rb" file is different than the "fixtures/statuses.yml" file. Should the file names be the exact same, as in should I change my fixtures/statuses.yml to: fixtures/status.yml?
5 Answers
Adam Kelm
29,082 PointsYou should definitely not rename any of the files. This would probably cause all sorts of havoc, due to the convention over configuration principle. Rails expects certain things to be in certain places, and if those places change, you'll have problems. Which tests are failing? Are they failures or errors? Without actually knowing what's happening, it's impossible to say what's causing it.
Colin Stodd
3,160 PointsSee below (accidently answered meant to comment).
Adam Kelm
29,082 PointsOkay, so it's the "a user should have a unique profile name" test that's failing. One thing I see right off the bat is that the passwords you have give in the user_test doesn't match the password for the fixtures. But all the information doesn't really need to be there anyway. Because you already have the test profile in your fixtures, all you need to do in the user_test is to refer to the user located in the fixtures. So your code would look something like this:
test "a user should have a unique profile name" do
user = User.new
user.profile_name = users(:colin).profile_name
assert !user.save
assert !user.errors[:profile_name].empty?
end
Let me know if this helps. Good luck!
Colin Stodd
3,160 PointsThanks for your help again Adam. I changed the passwords and made the appropriate corrections to the code and I'm getting 4 errors:
1) Error: test_a_user_should_enter_a_first_name(UserTest): ActiveRecord::Fixture::FormatError: a YAML error occurred parsing /home/colin/ruby/rails/treebook/test/fixtures/users.yml. Please note that YAML must be consistently indented using spaces. Tabs are not allowed. Please have a look at http://www.yaml.org/faq.html The exact error was: Psych::SyntaxError: (<unknown>): found character that cannot start any token while scanning for the next token at line 2 column 1
2) Error: test_a_user_should_enter_a_last_name(UserTest): ActiveRecord::Fixture::FormatError: a YAML error occurred parsing /home/colin/ruby/rails/treebook/test/fixtures/users.yml. Please note that YAML must be consistently indented using spaces. Tabs are not allowed. Please have a look at http://www.yaml.org/faq.html The exact error was: Psych::SyntaxError: (<unknown>): found character that cannot start any token while scanning for the next token at line 2 column 1
3) Error: test_a_user_should_enter_a_profile_name(UserTest): ActiveRecord::Fixture::FormatError: a YAML error occurred parsing /home/colin/ruby/rails/treebook/test/fixtures/users.yml. Please note that YAML must be consistently indented using spaces. Tabs are not allowed. Please have a look at http://www.yaml.org/faq.html The exact error was: Psych::SyntaxError: (<unknown>): found character that cannot start any token while scanning for the next token at line 2 column 1
4) Error: test_a_user_should_enter_a_unique_profile_name(UserTest): ActiveRecord::Fixture::FormatError: a YAML error occurred parsing /home/colin/ruby/rails/treebook/test/fixtures/users.yml. Please note that YAML must be consistently indented using spaces. Tabs are not allowed. Please have a look at http://www.yaml.org/faq.html The exact error was: Psych::SyntaxError: (<unknown>): found character that cannot start any token while scanning for the next token at line 2 column 1
4 tests, 0 assertions, 0 failures, 4 errors, 0 skips
so it now looks like:
test "a user should enter a unique profile name" do
user = User.new
user.profile_name = users(:colin).profile_name
assert !user.save
assert !user.errors[:profile_name].empty?
end
end
Adam Kelm
29,082 PointsIt looks like you have a syntax error in your users.yml file now. Make sure you're using spaces instead of tab characters and that you aren't missing any characters? Any chance you can link me to your repo on Github?
Adam Kelm
29,082 PointsWhen I looked for your fixtures, the users.yml file didn't have any information under it, and it should look like:
colin:
first_name: "Colin"
last_name: "Stodd"
email: "cbstodd@gmail"
profile_name: "cbstodd"
password: "password"
password_confirmation: "password"
And without the information here to feed to the test, it could be throwing you the syntax error.
Colin Stodd
3,160 PointsSorry and thank you Adam, you have been awesome!
Not sure when you checked Github, but it should be pushed up by now. For some reason I accidently deleted (didn't save) that file as I was moving from work to home. But it is in there now.... Problem still persisted.
Neverthless, I did notice in the Instructors notes that there is something that addresses this problem. it says to just take out the "password" and "password_confirmation" lines from the users.yml file. Furthermore, I also had to delete the "profile_name" line.
So I guess this problem has existed, just not sure why this is the only workaround.
I would like to see Treehouse use Rspec instead of this testing method. I Think I may just go back to Michael Hartl's tutorials. Was hoping this would shed some light onto the TDD side of things.
Colin Stodd
3,160 PointsColin Stodd
3,160 PointsHey Adam, Thanks for your reply. Its actually an error:
1) Failure: test_a_user_should_enter_a_unique_profile_name(UserTest) [test/unit/user_test.rb:32]: Failed assertion, no message given.
4 tests, 8 assertions, 1 failures, 0 errors, 0 skips
test/unit/user_test.rb:
--UPDATE -- I changed the passwords to correctly coincide with the users.yml file. --
test/fixtures/users.yml:
app/model/user.rb: