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 trialChris Dziewa
17,781 PointsNameError
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:in
run'
/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:in
block 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:in
run_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:in
block 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:in
each'
/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:in
block 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:in
run'
/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:in
block (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:in
block 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
5,280 PointsChange your gem file to include mocha, for example:
group :test do
gem 'shoulda'
gem 'mocha'
end
Chris Dziewa
17,781 PointsI just realized I forgot to put the key user:
after the create method.
Chris Dziewa
17,781 PointsI fixed it. Thanks for offering your help Mike Rogers!
Chris Dziewa
17,781 PointsChris Dziewa
17,781 PointsIt is funny you mention that. I had done that and I got a new error. This is that error: