【发布时间】:2011-03-22 08:40:22
【问题描述】:
我有一堆用 rspec 编写的组合控制器/视图测试。我添加了 Capybara gem 并编写了一些通过良好的集成测试。唯一的问题是,现在在我所有的控制器测试中,我都有
response.should have_selector("some 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)>'
【问题讨论】:
-
你能添加你失败的测试吗?
标签: ruby-on-rails ruby-on-rails-3 rspec capybara