1

私は Mike Hartl の Rails Tutorial をざっと読んでいますが、セクション 4.4では、rspec リクエスト ファイルを次の形式から変更したようです。

page.should have_selector('title', :text => "#{base_title}")

expect(page).to have_title("Ruby on Rails Tutorial Sample App")

「.to have_title」と「.to_not have_title」を使用すると、未定義のメソッド エラーが 2 つ発生します。念のため、Webrick、Spork、および Guard をシャットダウンして再起動しましたが、それでも機能しません。

カピバラ バージョン 1.1.2 Rspec バージョン 2.11.1

他の情報が必要な場合はお知らせください。

4

3 に答える 3

4

どうやら最近、チュートリアルが変更されたようです。

Googleキャッシュを介してページにアクセスすると、元のバージョンが明らかになります(これは私にとってはうまく機能します):

require 'spec_helper'

describe "Static pages" do

  describe "Home page" do

    it "should have the h1 'Sample App'" do
      visit '/static_pages/home'
      page.should have_selector('h1', :text => 'Sample App')
    end

    it "should have the base title" do
      visit '/static_pages/home'
      page.should have_selector('title',
                        :text => "Ruby on Rails Tutorial Sample App")
    end

    it "should not have a custom page title" do
      visit '/static_pages/home'
      page.should_not have_selector('title', :text => '| Home')
    end
  end
  .
  .
  .
end
于 2013-05-27T11:32:09.740 に答える
0

お使いのバージョンの問題かもしれません。https://github.com/jnicklas/capybara/issues/863にアクセスしてください

expect(first('title').native.text).to eq "my title"
于 2013-05-27T09:34:13.517 に答える