我想在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