gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 05:12:44 25 4
gpt4 key购买 nike

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

我倾向于相信这不是 rvm/rbenv 问题,而是我的 gem 安装方式的变化。

这是完整的堆栈跟踪:

> 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 版本:
   gem 'rails', '3.0.20'
gem 'mocha'

这件事过去 3 天一直困扰着我,希望得到任何帮助...

最佳答案

在从 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 )

关于ruby-on-rails - 尝试启动 Rails 服务器时出现 mocha 期望错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14693252/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com