[英]Rspec does not work correctly with Rails3, FactoryGirl
I am trying to get Rspec up and running but ran into the following issue when calling rspec spec
from the command line: 我试图启动Rspec并运行,但是从命令行调用
rspec spec
时遇到了以下问题:
Failure/Error: Unable to find matching line from backtrace
undefined method `request=' for #<Name:0x000001033c1be0>
This seems to be an issue with a combination of certain gems but I cannot figure out what´s wrong with my setup: 结合使用某些宝石似乎是一个问题,但是我无法弄清楚我的设置出了什么问题:
Here it is: 这里是:
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
My Gemfile looks like this (I skip irrelevant gems): 我的Gemfile看起来像这样(我跳过了无关的宝石):
group :development, :test do
gem 'factory_girl_rails'
gem 'rspec-rails', '~> 2.6'
gem 'webrat'
end
Addition: 加成:
I added the following line to spec_helper.rb, in order to fix the error that is described here . 我将以下行添加到spec_helper.rb,以修复此处描述的错误。
config.include RSpec::Rails::ControllerExampleGroup
Any hints? 有什么提示吗?
In the meanwhile I solved the issue. 同时我解决了这个问题。
The above described issue occured when I set up my first controller test. 当我设置我的第一个控制器测试时,发生了上述问题。
describe MyController do
describe "#index" do
it "responses successfully" do
get :index
response.should be_success
end
end
end
To get rid of the problem I had to move the above mentioned line from spec_helper directly into the ControllerSpec. 为了解决这个问题,我不得不将上述代码从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
Go back to work ;-) 回去工作 ;-)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.