我正在关注Michael Hartl的Rails截屏的旧版本(针对Rails 3)。但是,我正在使用Ruby 2和Rails 4(rspec-rails
3.0.1),通过Google搜索在课程和练习之间进行插值。
我遇到了一个可能错误的匹配器。这是我失败的规范:
RSpec.describe PagesController do
render_views
it "has the correct page title" do
get 'home'
expect(response).to have_selector('title')
end
end
end
以下是错误消息:
Failures:
1) PagesController GET 'home' has the correct page title
Failure/Error: expect(response).to have_selector('title')
expected #<ActionController::TestResponse:0x9e1202c> to respond to `has_selector?`
# ./spec/controllers/pages_controller_spec.rb:13:in `block (3 levels) in <top (required)>'
# -e:1:in `<main>'
似乎rspec-rails3
中没有像have_selector这样的匹配器。我在their Github page上查了一下,似乎没有提到这个匹配器。
Gemfile
:
source 'https://rubygems.org'
ruby '2.0.0'
gem 'rails', '4.0.0'
gem 'sqlite3'
gem 'sass-rails', '~> 4.0.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.0.0'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder'
group :doc do
gem 'sdoc', require: false
end
group :development do
gem 'spring-commands-rspec'
end
group :development, :test do
gem 'rspec'
gem 'rspec-rails'
end
答案 0 :(得分:2)
have_selector
匹配器由Capybara提供。将其添加到您的Gemfile。