在 Rails 2.3.3 项目中安装 Mocha 0.9.7
我使用以下方法安装了 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。 问题是我找不到它。
我的猜测正确吗? 如果是的话,这个旧版本的 Mocha 在哪里? 或者,我怎样才能找到它在哪里?
I installed the Mocha 0.9.7 Rails plug-in using:
$ script/plugin install git://github.com/floehopper/mocha.git
(Just followed instruction in http://mocha.rubyforge.org/)
Then, I have the following set-up defined in my functional test
def setup
@controller.expects(:logged_in?).returns(true)
@controller.expects(:admin_user?).returns(true)
end
Running the test generates the ff. error:
NameError: uninitialized constant Mocha::Mockery::ImpersonatingName
/test/functional/xxxx_controller_test.rb:x:in `setup'
Before that, I see the ff. error at the top of the test log:
/usr/local/lib/ruby/gems/1.8/gems/activesupport-2.3.3/lib/active_support/test_case.rb:12: warning: already initialized constant Mocha
This has led me to believe that I have an old version of Mocha somewhere in Ruby's or Rails' path. The problem is I can't find it.
Is my guess correct? If so, where is this old version of Mocha? Alternatively, how can I found out where it is?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据 http://selfamusementpark.com/blog/2009/07/30/rails233mochaconfusion /,我的猜测不正确。 问题实际上是 Mocha 在测试框架之前加载,这不是前者所期望的。 解决方案是编辑 RAILS_ROOT/vendor/plugin/mocha/init.rb 以注释掉 ff。 line:
然后,必须在测试文件或帮助程序中明确要求Mocha,以确保测试框架已预先加载。
According to http://selfamusementpark.com/blog/2009/07/30/rails233mochaconfusion/, my guess is not correct. The problem really is that Mocha is being loaded before the testing framework which is not what the former expects. The solution is to edit RAILS_ROOT/vendor/plugin/mocha/init.rb to comment out the ff. line:
Then, Mocha will have to be explicitly required in the test files or helpers to ensure that the testing framework will have been loaded beforehand.