[英]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.