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

Errors in "Testing Friendships"

I'm getting errors when I shouldn't. Getting the following errors: 1) Error: test: UserFriendship should belong to friend. (UserFriendshipTest): ArgumentError: assertion message must be String or Proc, but NilClass was given.

This is after adding "belongs_to :friend" in the user_friendship model.

Any ideas or help?

2 Answers

Jason Seifer
STAFF
Jason Seifer
Treehouse Guest Teacher

@Brandon Barrette it looks like it's a problem with the updated version of the shoulda gem. Open up your Gemfile and change the following line:

gem 'shoulda'

To:

gem 'shoulda', '3.3.2'

Then run bundle and your tests should pass. Except for the user_test which has a typo on line 4 (should have_many(:user_friendships) :)

Thank you Jason Seifer! My test passed now! And thanks for catching my typo! These happen all too often!

Jason Seifer
STAFF
Jason Seifer
Treehouse Guest Teacher

Hey @Brandon Barrette can you paste your error message, userfriendship class, and the test that is failing here?

Here's the errors:

Finished tests in 0.430257s, 6.9726 tests/s, 2.3242 assertions/s.

1) Error: test: UserFriendship should belong to friend. (UserFriendshipTest): ArgumentError: assertion message must be String or Proc, but NilClass was given. /usr/local/rvm/gems/ruby-1.9.3-p392/gems/shoulda-context-1.1.3/lib/shoulda/context/assertions.rb:89:in safe_assert_block' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/shoulda-context-1.1.3/lib/shoulda/context/assertions.rb:55:inassert_accepts' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/shoulda-context-1.1.3/lib/shoulda/context/context.rb:339:in block in should' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/shoulda-context-1.1.3/lib/shoulda/context/context.rb:400:incall' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/shoulda-context-1.1.3/lib/shoulda/context/context.rb:400:in block in create_test_from_should_hash' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activesupport-3.2.12/lib/active_support/testing/setup_and_teardown.rb:36:inblock in run' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activesupport-3.2.12/lib/active_support/callbacks.rb:425:in _run__1916967253025563626__setup__4395528327017246691__callbacks' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activesupport-3.2.12/lib/active_support/callbacks.rb:405:in__run_callback' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activesupport-3.2.12/lib/active_support/callbacks.rb:385:in _run_setup_callbacks' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activesupport-3.2.12/lib/active_support/callbacks.rb:81:inrun_callbacks' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activesupport-3.2.12/lib/active_support/testing/setup_and_teardown.rb:35:in `run'

2) Error: test: UserFriendship should belong to user. (UserFriendshipTest): ArgumentError: assertion message must be String or Proc, but NilClass was given. /usr/local/rvm/gems/ruby-1.9.3-p392/gems/shoulda-context-1.1.3/lib/shoulda/context/assertions.rb:89:in safe_assert_block' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/shoulda-context-1.1.3/lib/shoulda/context/assertions.rb:55:inassert_accepts' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/shoulda-context-1.1.3/lib/shoulda/context/context.rb:339:in block in should' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/shoulda-context-1.1.3/lib/shoulda/context/context.rb:400:incall' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/shoulda-context-1.1.3/lib/shoulda/context/context.rb:400:in block in create_test_from_should_hash' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activesupport-3.2.12/lib/active_support/testing/setup_and_teardown.rb:36:inblock in run' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activesupport-3.2.12/lib/active_support/callbacks.rb:425:in _run__1916967253025563626__setup__4395528327017246691__callbacks' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activesupport-3.2.12/lib/active_support/callbacks.rb:405:in__run_callback' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activesupport-3.2.12/lib/active_support/callbacks.rb:385:in _run_setup_callbacks' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activesupport-3.2.12/lib/active_support/callbacks.rb:81:inrun_callbacks' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activesupport-3.2.12/lib/active_support/testing/setup_and_teardown.rb:35:in `run'

3 tests, 1 assertions, 0 failures, 2 errors, 0 skips

and here's the user_friendship class

class UserFriendship < ActiveRecord::Base
  belongs_to :user
  belongs_to :friend, class_name: 'User', foreign_key: 'friend_id'

  attr_accessible :user, :friend
end

and user_friendship_test.rb

require 'test_helper'

class UserFriendshipTest < ActiveSupport::TestCase
  should belong_to(:user)
  should belong_to(:friend)


  test "that creating a friendship works without raising an exception" do 
    assert_nothing_raised do
        UserFriendship.create user: users(:brandon), friend: users(:mike)
   end
  end
end

Thanks for any help!

Jason Seifer
Jason Seifer
Treehouse Guest Teacher

Thanks for pasting this. I'm afraid I can't determine the problem from this output, though. Can you zip up your project and email it to help@teamtreehouse.com or paste a link to your project on GitHub here?

Here's the link, just committed with these errors so it's the most up to date. Thanks for your help!