[英]Rspec does not work correctly with Rails3, FactoryGirl
我试图启动Rspec并运行,但是从命令行调用rspec spec
时遇到了以下问题:
Failure/Error: Unable to find matching line from backtrace
undefined method `request=' for #<Name:0x000001033c1be0>
结合使用某些宝石似乎是一个问题,但是我无法弄清楚我的设置出了什么问题:
这里是:
rails -v
Rails 3.0.9
ruby -v
ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-darwin10.7.0]
rvm -v
rvm 1.6.2
我的Gemfile看起来像这样(我跳过了无关的宝石):
group :development, :test do
gem 'factory_girl_rails'
gem 'rspec-rails', '~> 2.6'
gem 'webrat'
end
加成:
我将以下行添加到spec_helper.rb,以修复此处描述的错误。
config.include RSpec::Rails::ControllerExampleGroup
有什么提示吗?
同时我解决了这个问题。
当我设置我的第一个控制器测试时,发生了上述问题。
describe MyController do
describe "#index" do
it "responses successfully" do
get :index
response.should be_success
end
end
end
为了解决这个问题,我不得不将上述代码从spec_helper直接移到ControllerSpec中。
describe MyController do
include RSpec::Rails::ControllerExampleGroup
describe "#index" do
it "responses successfully" do
get :index
response.should be_success
end
end
end
回去工作 ;-)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.