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 Building Social Features in Ruby on Rails Creating Friendships Testing Friendships

Chris Dziewa
Chris Dziewa
17,781 Points

NameError

I am getting the following rails error when I do my test on friendships:

1) Error: test_that_creating_a_friendship_works_without_raising_an_exception(UserFriendshipTest): NameError: uninitialized constant Mocha::Integration /Users/chrisdziewa/.rvm/gems/ruby-2.0.0-p353/gems/mocha-0.10.5/lib/mocha/integration/mini_test/version_230_to_262.rb:36:in rescue in run' /Users/chrisdziewa/.rvm/gems/ruby-2.0.0-p353/gems/mocha-0.10.5/lib/mocha/integration/mini_test/version_230_to_262.rb:47:inrun' /Users/chrisdziewa/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/test/unit/testcase.rb:17:in run' /Users/chrisdziewa/.rvm/gems/ruby-2.0.0-p353/gems/activesupport-3.2.13/lib/active_support/testing/setup_and_teardown.rb:36:inblock in run' /Users/chrisdziewa/.rvm/gems/ruby-2.0.0-p353/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:425:in _run__2226949997155820290__setup__3145843997473138674__callbacks' /Users/chrisdziewa/.rvm/gems/ruby-2.0.0-p353/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:405:in__run_callback' /Users/chrisdziewa/.rvm/gems/ruby-2.0.0-p353/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:385:in _run_setup_callbacks' /Users/chrisdziewa/.rvm/gems/ruby-2.0.0-p353/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:81:inrun_callbacks' /Users/chrisdziewa/.rvm/gems/ruby-2.0.0-p353/gems/activesupport-3.2.13/lib/active_support/testing/setup_and_teardown.rb:35:in run' /Users/chrisdziewa/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/minitest/unit.rb:919:inblock in _run_suite' /Users/chrisdziewa/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/minitest/unit.rb:912:in map' /Users/chrisdziewa/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/minitest/unit.rb:912:in_run_suite' /Users/chrisdziewa/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/test/unit.rb:657:in block in _run_suites' /Users/chrisdziewa/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/test/unit.rb:655:ineach' /Users/chrisdziewa/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/test/unit.rb:655:in _run_suites' /Users/chrisdziewa/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/minitest/unit.rb:867:in_run_anything' /Users/chrisdziewa/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/minitest/unit.rb:1060:in run_tests' /Users/chrisdziewa/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/minitest/unit.rb:1047:inblock in _run' /Users/chrisdziewa/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/minitest/unit.rb:1046:in each' /Users/chrisdziewa/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/minitest/unit.rb:1046:in_run' /Users/chrisdziewa/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/minitest/unit.rb:1035:in run' /Users/chrisdziewa/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/test/unit.rb:21:inrun' /Users/chrisdziewa/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/test/unit.rb:774:in run' /Users/chrisdziewa/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/test/unit.rb:366:inblock (2 levels) in autorun' /Users/chrisdziewa/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/test/unit.rb:27:in run_once' /Users/chrisdziewa/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/test/unit.rb:365:inblock in autorun'

Finished tests in 0.115463s, 25.9823 tests/s, 25.9823 assertions/s. 3 tests, 3 assertions, 0 failures, 1 errors, 0 skips

#My gemfile

source 'https://rubygems.org'

gem 'rails', '3.2.13'

# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'


gem 'devise'
gem 'simple_form'
group :test do 
    gem 'shoulda'
end

group :development, :test do 
    gem 'sqlite3'
end

group :production do 
    gem 'pg'
end

# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails',   '~> 3.2.3'
  gem 'coffee-rails', '~> 3.2.1'

  # See https://github.com/sstephenson/execjs#readme for more supported runtimes
  # gem 'therubyracer', :platforms => :ruby

  gem 'uglifier', '>= 1.0.3'
end

gem 'jquery-rails'
#This is my user_friendship_test.rb file

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 users(:chris), friend: users(:mike)
        end
    end
end
#Here is my user_friendship.rb file

class UserFriendship < ActiveRecord::Base

  belongs_to :user
  belongs_to :friend

  attr_accessible :user, :friend
end

Any help would be greatly appreciated! Thanks guys!

2 Answers

Mike Rogers
Mike Rogers
5,280 Points

Change your gem file to include mocha, for example:

group :test do 
    gem 'shoulda'
    gem 'mocha'
end
Chris Dziewa
Chris Dziewa
17,781 Points

It is funny you mention that. I had done that and I got a new error. This is that error:

<#<NoMethodError: undefined method `stringify_keys' for #<User:0x007fe27cf36d60>>>. ``` 

I also got the failure I was looking for.
Chris Dziewa
Chris Dziewa
17,781 Points

I just realized I forgot to put the key user: after the create method.

Chris Dziewa
Chris Dziewa
17,781 Points

I fixed it. Thanks for offering your help Mike Rogers!