我正在关注 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>'
似乎没有像 have_selector 这样的匹配器rspec-rails3
。我在他们的 Github 页面上查找过,似乎没有提到这个匹配器。
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