Rspec 测试因方法缺失而失败,但不是来自 RubyMine Spork
我有一个非常简单的 RSpec/Rails3 测试,当像这样运行时会失败:
bundle exec ruby -I spec /home/user/project/my_test_spec.rb
但是当使用 spork 服务器在 RubyMine 中运行时测试通过得很好,但在没有 spork 的情况下运行时会失败。
失败是:
undefined method `name' for nil:NilClass
其中“name”是数据库列名,对象是通过调用检索的 ActiveRecord
subject { MyTable.find_by_table_id 123 }
,测试看起来像
it "blah blah" do
subject.name.should == "Correct Name"
end
必须有一个简单的解决方案。测试顶部需要spec_helper,它确实会调用:
require File.expand_path("../../config/environment", __FILE__)
需要更多信息吗?
I've got a very simple RSpec/Rails3 test that fails when run like this:
bundle exec ruby -I spec /home/user/project/my_test_spec.rb
but the test passes just fine when run within RubyMine using the spork server, but fails when run without spork.
The failure is:
undefined method `name' for nil:NilClass
Where "name" is a db column name, and the object is an ActiveRecord retrieved by calling
subject { MyTable.find_by_table_id 123 }
and the test looks like
it "blah blah" do
subject.name.should == "Correct Name"
end
There must be a simple solution for this. The spec_helper is required at the top of the test and it does call:
require File.expand_path("../../config/environment", __FILE__)
Any more info needed?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论