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
Unsubscribed User
8,167 PointsLast section of the social features with ruby tutorial - Getting Failure
Hey, I'm getting an error while testing the user_test.rb file in the video "Displaying Correct Statuses"
It has one failure with the message
Failure:
test: #has_blocked? should return true if a user has blocked another user. (UserTest) [test/unit/user_test.rb:75]:
Failed assertion, no message given.
19 tests, 25 assertions, 1 failures, 0 errors, 0 skips
Does anyone know where I went wrong? Thanks
Unsubscribed User
8,167 PointsHere is my User Model (user.rb)
def has_blocked?(other_user)
blocked_friends.include?(other_user)
end
Here is my User Test (user_test.rb)
context "#has_blocked?" do
should "return true if a user has blocked another user" do
assert users(:justin).has_blocked?(users(:blocked_friend))
end
should "return false if a user has not blocked another user" do
assert !users(:justin).has_blocked?(users(:zach))
end
end
Brandon Barrette
20,485 PointsAnd you have
should have_many :blocked_friends
at the top of user_test.rb
Brandon Barrette
20,485 PointsAnd you have blocked_friend in your user.yml file? Make sure you don't do any tabbing there. YML files only like spaces.
2 Answers
Unsubscribed User
8,167 PointsI finally figured out the error. In the User model in the has_many :blocked_friends....I still had one of them saying pending_user_friendships where I had copied the code from the above 'has_many'. Thanks for your help Brandon.
Brandon Barrette
20,485 PointsI made this same mistake too when copying and pasting code. Glad you figured it out!
Unsubscribed User
8,167 PointsHere is the line at the top of the user_test.rb
should have_many(:blocked_friends)
and yes unfortunately the spacing is correct (I say unfort. because that would be an easy fix and I could keep on with the videos)
Unsubscribed User
8,167 PointsAnd here is the users fixture..of course the fourth & last user
blocked_friend:
first_name: "Blocked"
last_name: "Friend"
email: "blocked@teamtreehouse.com"
profile_name: "youblockedme"
Unsubscribed User
8,167 PointsAnd finally here is the User_friendships fixture
one:
user: justin
friend: zach
blocked_by_justin:
user: justin
friend: blocked_friend
state: 'blocked'
Brandon Barrette
20,485 PointsBrandon Barrette
20,485 PointsWhat is your test code?