我有一堆用rspec編寫的組合控制器/視圖測試。我添加了水豚寶石,並寫了一些整合測試,通過罰款。唯一的問題是,現在在我所有的控制器的測試,在那裏我有安裝Capybara後控制器損壞?
response.should have_selector(「一些選擇」)
rspec的給錯誤,如:
NoMethodError:
undefined method `has_selector?' for #<ActionController::TestResponse:0xa03e7ec>
當我運行控制器試驗。我猜測Capybara正在我的控制器測試中使用,並且已經覆蓋了一些Rspec方法。我怎樣才能解決這個問題?
# gemfile.rb
group :test do
gem 'rspec'
gem "capybara"
gem "launchy"
gem 'factory_girl_rails', '1.0'
end
# spec_helper.rb
RSpec.configure do |config|
config.include IntegrationSpecHelper, :type => :request
end
下面是一個失敗的測試的例子:
# spec/controllers/books_controller_spec.rb
require 'spec_helper'
describe BooksController do
render_views
it "should have the right page title" do
get :show, :id => @book.ean
response.should have_selector("title", :content => "Lexicase | " + @book.title)
end
end
和它相關的錯誤:
1) BooksController GET 'show' should have the right page title
Failure/Error: response.should have_selector("title", :content => "Lexicase | " + @book.title)
NoMethodError:
undefined method `has_selector?' for #<ActionController::TestResponse:0xa8488c0>
# ./spec/controllers/books_controller_spec.rb:23:in `block (3 levels) in <top (required)>'
您可以添加失敗的測試嗎? – shingara 2011-03-22 08:46:06
更新了原來的帖子。 – 2011-03-22 08:57:51