KG -
KG -

Reputation: 7170

mocha expectation error when trying to bring up rails server

I had a perfectly running rails project, but along the lines i had to reinstall a couple of gems and switched between rbenv and rvm. I was previously running rvm, then i switched to rbenv, started getting a bunch of exceptions, tried switching back to rvm but still receiving the same errors.

I'm inclined to believe this is not an rvm/rbenv issue, but rather a change in how my gems are getting installed.

Here's the full stack trace:

> rails s thin                                                                                                                                                                                                  kaush@Air-Kode
DEPRECATION WARNING: Yajl's JSON gem compatibility API is going to be removed in 2.0
~/.rvm/gems/ruby-1.9.2-p180@my-gemset/gems/mocha-0.10.0/lib/mocha/expectation_error.rb:5:in `<module:Mocha>': superclass mismatch for class ExpectationError (TypeError)
    from ~/.rvm/gems/ruby-1.9.2-p180@my-gemset/gems/mocha-0.10.0/lib/mocha/expectation_error.rb:3:in `<top (required)>'
    from ~/.rvm/gems/ruby-1.9.2-p180@my-gemset/gems/activesupport-3.0.20/lib/active_support/dependencies.rb:242:in `require'
    from ~/.rvm/gems/ruby-1.9.2-p180@my-gemset/gems/activesupport-3.0.20/lib/active_support/dependencies.rb:242:in `block in require'
    from ~/.rvm/gems/ruby-1.9.2-p180@my-gemset/gems/activesupport-3.0.20/lib/active_support/dependencies.rb:225:in `block in load_dependency'
    from ~/.rvm/gems/ruby-1.9.2-p180@my-gemset/gems/activesupport-3.0.20/lib/active_support/dependencies.rb:597:in `new_constants_in'
    from ~/.rvm/gems/ruby-1.9.2-p180@my-gemset/gems/activesupport-3.0.20/lib/active_support/dependencies.rb:225:in `load_dependency'
    from ~/.rvm/gems/ruby-1.9.2-p180@my-gemset/gems/activesupport-3.0.20/lib/active_support/dependencies.rb:242:in `require'
    from ~/.rvm/gems/ruby-1.9.2-p180@my-gemset/gems/mocha-0.10.0/lib/mocha/expectation.rb:3:in `<top (required)>'
    from ~/.rvm/gems/ruby-1.9.2-p180@my-gemset/gems/activesupport-3.0.20/lib/active_support/dependencies.rb:242:in `require'
    from ~/.rvm/gems/ruby-1.9.2-p180@my-gemset/gems/activesupport-3.0.20/lib/active_support/dependencies.rb:242:in `block in require'
    from ~/.rvm/gems/ruby-1.9.2-p180@my-gemset/gems/activesupport-3.0.20/lib/active_support/dependencies.rb:225:in `block in load_dependency'
    from ~/.rvm/gems/ruby-1.9.2-p180@my-gemset/gems/activesupport-3.0.20/lib/active_support/dependencies.rb:597:in `new_constants_in'
    from ~/.rvm/gems/ruby-1.9.2-p180@my-gemset/gems/activesupport-3.0.20/lib/active_support/dependencies.rb:225:in `load_dependency'
    from ~/.rvm/gems/ruby-1.9.2-p180@my-gemset/gems/activesupport-3.0.20/lib/active_support/dependencies.rb:242:in `require'
    from ~/.rvm/gems/ruby-1.9.2-p180@my-gemset/gems/mocha-0.10.0/lib/mocha/mock.rb:2:in `<top (required)>'
    from ~/.rvm/gems/ruby-1.9.2-p180@my-gemset/gems/activesupport-3.0.20/lib/active_support/dependencies.rb:242:in `require'
    from ~/.rvm/gems/ruby-1.9.2-p180@my-gemset/gems/activesupport-3.0.20/lib/active_support/dependencies.rb:242:in `block in require'
    from ~/.rvm/gems/ruby-1.9.2-p180@my-gemset/gems/activesupport-3.0.20/lib/active_support/dependencies.rb:225:in `block in load_dependency'
    from ~/.rvm/gems/ruby-1.9.2-p180@my-gemset/gems/activesupport-3.0.20/lib/active_support/dependencies.rb:597:in `new_constants_in'
    from ~/.rvm/gems/ruby-1.9.2-p180@my-gemset/gems/activesupport-3.0.20/lib/active_support/dependencies.rb:225:in `load_dependency'
    from ~/.rvm/gems/ruby-1.9.2-p180@my-gemset/gems/activesupport-3.0.20/lib/active_support/dependencies.rb:242:in `require'
    from ~/.rvm/gems/ruby-1.9.2-p180@my-gemset/gems/mocha-0.10.0/lib/mocha/mockery.rb:2:in `<top (required)>'
    from ~/.rvm/gems/ruby-1.9.2-p180@my-gemset/gems/activesupport-3.0.20/lib/active_support/dependencies.rb:242:in `require'
    from ~/.rvm/gems/ruby-1.9.2-p180@my-gemset/gems/activesupport-3.0.20/lib/active_support/dependencies.rb:242:in `block in require'
    from ~/.rvm/gems/ruby-1.9.2-p180@my-gemset/gems/activesupport-3.0.20/lib/active_support/dependencies.rb:225:in `block in load_dependency'
    from ~/.rvm/gems/ruby-1.9.2-p180@my-gemset/gems/activesupport-3.0.20/lib/active_support/dependencies.rb:597:in `new_constants_in'
    from ~/.rvm/gems/ruby-1.9.2-p180@my-gemset/gems/activesupport-3.0.20/lib/active_support/dependencies.rb:225:in `load_dependency'
    from ~/.rvm/gems/ruby-1.9.2-p180@my-gemset/gems/activesupport-3.0.20/lib/active_support/dependencies.rb:242:in `require'
    from ~/.rvm/gems/ruby-1.9.2-p180@my-gemset/gems/mocha-0.10.0/lib/mocha/api.rb:2:in `<top (required)>'
    from ~/.rvm/gems/ruby-1.9.2-p180@my-gemset/gems/activesupport-3.0.20/lib/active_support/dependencies.rb:242:in `require'
    from ~/.rvm/gems/ruby-1.9.2-p180@my-gemset/gems/activesupport-3.0.20/lib/active_support/dependencies.rb:242:in `block in require'
    from ~/.rvm/gems/ruby-1.9.2-p180@my-gemset/gems/activesupport-3.0.20/lib/active_support/dependencies.rb:225:in `block in load_dependency'
    from ~/.rvm/gems/ruby-1.9.2-p180@my-gemset/gems/activesupport-3.0.20/lib/active_support/dependencies.rb:597:in `new_constants_in'
    from ~/.rvm/gems/ruby-1.9.2-p180@my-gemset/gems/activesupport-3.0.20/lib/active_support/dependencies.rb:225:in `load_dependency'
    from ~/.rvm/gems/ruby-1.9.2-p180@my-gemset/gems/activesupport-3.0.20/lib/active_support/dependencies.rb:242:in `require'
    from ~/.rvm/gems/ruby-1.9.2-p180@my-gemset/gems/mocha-0.10.0/lib/mocha_standalone.rb:1:in `<top (required)>'
    from ~/.rvm/gems/ruby-1.9.2-p180@my-gemset/gems/activesupport-3.0.20/lib/active_support/dependencies.rb:242:in `require'
    from ~/.rvm/gems/ruby-1.9.2-p180@my-gemset/gems/activesupport-3.0.20/lib/active_support/dependencies.rb:242:in `block in require'
    from ~/.rvm/gems/ruby-1.9.2-p180@my-gemset/gems/activesupport-3.0.20/lib/active_support/dependencies.rb:225:in `block in load_dependency'
    from ~/.rvm/gems/ruby-1.9.2-p180@my-gemset/gems/activesupport-3.0.20/lib/active_support/dependencies.rb:597:in `new_constants_in'
    from ~/.rvm/gems/ruby-1.9.2-p180@my-gemset/gems/activesupport-3.0.20/lib/active_support/dependencies.rb:225:in `load_dependency'
    from ~/.rvm/gems/ruby-1.9.2-p180@my-gemset/gems/activesupport-3.0.20/lib/active_support/dependencies.rb:242:in `require'
    from ~/.rvm/gems/ruby-1.9.2-p180@my-gemset/gems/mocha-0.10.0/lib/mocha.rb:2:in `<top (required)>'
    from ~/.rvm/gems/ruby-1.9.2-p180@global/gems/bundler-1.2.3/lib/bundler/runtime.rb:68:in `require'
    from ~/.rvm/gems/ruby-1.9.2-p180@global/gems/bundler-1.2.3/lib/bundler/runtime.rb:68:in `block (2 levels) in require'
    from ~/.rvm/gems/ruby-1.9.2-p180@global/gems/bundler-1.2.3/lib/bundler/runtime.rb:66:in `each'
    from ~/.rvm/gems/ruby-1.9.2-p180@global/gems/bundler-1.2.3/lib/bundler/runtime.rb:66:in `block in require'
    from ~/.rvm/gems/ruby-1.9.2-p180@global/gems/bundler-1.2.3/lib/bundler/runtime.rb:55:in `each'
    from ~/.rvm/gems/ruby-1.9.2-p180@global/gems/bundler-1.2.3/lib/bundler/runtime.rb:55:in `require'
    from ~/.rvm/gems/ruby-1.9.2-p180@global/gems/bundler-1.2.3/lib/bundler.rb:128:in `require'
    from ~/my_project/config/application.rb:7:in `<top (required)>'
    from ~/.rvm/gems/ruby-1.9.2-p180@my-gemset/gems/railties-3.0.20/lib/rails/commands.rb:28:in `require'
    from ~/.rvm/gems/ruby-1.9.2-p180@my-gemset/gems/railties-3.0.20/lib/rails/commands.rb:28:in `block in <top (required)>'
    from ~/.rvm/gems/ruby-1.9.2-p180@my-gemset/gems/railties-3.0.20/lib/rails/commands.rb:27:in `tap'
    from ~/.rvm/gems/ruby-1.9.2-p180@my-gemset/gems/railties-3.0.20/lib/rails/commands.rb:27:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'

My gem versions:

   gem 'rails', '3.0.20'
   gem 'mocha'

This thing has been bugging me for the past 3 days, would appreciate any help...

Upvotes: 2

Views: 1235

Answers (2)

thierry.henrio
thierry.henrio

Reputation: 66

I had a similar stack, in the context of upgrading from rails-3.0.9 to 3.0.20, but while testing the app ( rspec )

testing

[sec] $ rm lib/mocha/setup.rb
[sec*]$ bundle exec rspec spec/
/Users/thenrio/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/mocha-0.10.5/lib/mocha/expectation_error.rb:5:in `<module:Mocha>': superclass mismatch for class ExpectationError (TypeError)

A solution was

[sec*]$ git checkout -f
[sec]$ cat lib/mocha/setup.rb
# patching nightmare
#
# XXX remove when rails > 3.2.0
#
# https://github.com/freerange/mocha/issues/138
#

[sec]$ bundle exec rspec spec
Finished in 8.85 seconds
421 examples, 0 failures

run

mocha is not required to run the server

Check your Gemfile

mocha has its place in the test group ( group :test do; gem 'mocha', '~> 0.10.0', require: false; end)

Upvotes: 2

Winfield
Winfield

Reputation: 19145

If your RVM setup was previously working, you should:

  1. Open a new console/ssh session with only RVM environment
  2. rvm gemset remove my-gemset
  3. rvm gemset create my-gemset
  4. cd (should automatically load .rvmrc file OR rvm gemset use my-gemset)
  5. bundle install

This should rebuild the working gemset for this application.

Upvotes: 1

Related Questions