gpt4 book ai didi

ruby-on-rails - 在 Rails 2.3.3 项目中安装 Mocha 0.9.7

转载 作者:行者123 更新时间:2023-11-28 20:47:43 26 4
gpt4 key购买 nike

我使用以下方法安装了 Mocha 0.9.7 Rails 插件:

$ script/plugin install git://github.com/floehopper/mocha.git

(只是按照 http://mocha.rubyforge.org/ 中的说明操作)

然后,我在功能测试中定义了以下设置

def setup
@controller.expects(:logged_in?).returns(true)
@controller.expects(:admin_user?).returns(true)
end

运行测试生成 ff。错误:

NameError: uninitialized constant Mocha::Mockery::ImpersonatingName
/test/functional/xxxx_controller_test.rb:x:in `setup'

在那之前,我看到了ff。测试日志顶部的错误:

/usr/local/lib/ruby/gems/1.8/gems/activesupport-2.3.3/lib/active_support/test_case.rb:12: warning: already initialized constant Mocha

这让我相信我在 Ruby 或 Rails 的路径中有一个旧版本的 Mocha。问题是我找不到它。

我的猜测正确吗?如果是这样,这个旧版本的摩卡在哪里?或者,我怎样才能找到它的位置?

最佳答案

根据 http://selfamusementpark.com/blog/2009/07/30/rails233mochaconfusion/ ,我的猜测是不正确的。问题实际上是 Mocha 在测试框架之前加载,这不是前者所期望的。解决方案是编辑 RAILS_ROOT/vendor/plugin/mocha/init.rb 注释掉 ff。行:

require 'mocha'

然后,必须在测试文件或帮助程序中明确要求 Mocha,以确保预先加载测试框架。

关于ruby-on-rails - 在 Rails 2.3.3 项目中安装 Mocha 0.9.7,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1288848/

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