2

Michael Hartl の Rails スクリーンキャストの古いバージョン (Rails 3 用) をフォローしています。ただし、私は Ruby 2 と Rails 4 ( rspec-rails3.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
4

1 に答える 1

2

have_selectorマッチャーは Capybara によって提供されます。それを Gemfile に追加します。

于 2014-06-18T18:07:41.283 に答える