我想在rails中測試我的靜態頁面的標題。我使用的是水豚2.4.4和RSpec 3.測試頁面標題與水豚2.4和rspec 3和rails 4
我的測試看起來如下 static_pages_controller_spec.rb
require 'spec_helper'
require 'rails_helper'
describe StaticPagesController do
describe "GET 'Index'" do
it "should be successful" do
visit root_path
response.should be_success
end
it "should have the right title" do
visit root_path
expect(page).to have_selector('title',
:text => "Index",
:visible => false)
end
end
end
頁面確實有正確的標題集。 我得到的錯誤說下面
Failure/Error: expect(page).to have_selector('title',
expected to find css "title" with text "Index" but there were no matches
你應該期望頁面(頁面)。以have_content代替 – Joel
也許發佈視圖代碼? – roob
http://stackoverflow.com/questions/13573525/rspec-capybara-2-0-tripping-up-my-have-selector-tests 這應該有你的答案。 – trueinViso