尝试启动rails服务器时出现mocha期望错误

时间:2013-02-04 18:38:23

标签: ruby-on-rails ruby-on-rails-3 rvm mocha

我有一个完美运行的rails项目,但是我必须重新安装几个宝石并在rbenv和rvm之间切换。我以前运行rvm,然后我切换到rbenv,开始得到一堆异常,尝试切换回rvm但仍然收到相同的错误。

我倾向于认为这不是rvm / rbenv问题,而是我的宝石安装方式的变化。

这是完整的堆栈跟踪:

> 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>'

我的宝石版本:

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

过去3天这件事一直困扰着我,不胜感激任何帮助...

2 个答案:

答案 0 :(得分:2)

我有一个类似的堆栈,在从rails-3.0.9升级到3.0.20的上下文中,但在测试应用程序时(rspec)

测试

[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)

解决方案是

[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

运行

运行服务器不需要mocha

检查您的Gemfile

mocha测试组中占有一席之地(group :test do; gem 'mocha', '~> 0.10.0', require: false; end

答案 1 :(得分:1)

如果您的RVM设置以前有效,您应该:

  1. 仅使用RVM环境打开新的控制台/ ssh会话
  2. rvm gemset remove my-gemset
  3. rvm gemset create my-gemset
  4. cd(应自动加载.rvmrc文件或rvm gemset使用my-gemset)
  5. 捆绑安装
  6. 这应该重建此应用程序的工作gemset。