我有一堆用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