【发布时间】:2014-12-30 23:00:04
【问题描述】:
我正在尝试在 rails 中测试我的静态页面的标题。我正在使用 Capybara 2.4.4 和 rspec 3。
我的测试如下所示 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
【问题讨论】:
-
你应该期望 page(page).to have_content 代替
-
或许贴出视图代码?
-
@trueinViso 我尝试了最新的答案并收到预期的“”以包含“索引”错误
-
你试过
expect(page).to have_title "Index"?你正在测试的页面上有<title>Index<\title>?只是为了确保您在测试中执行了save_and_open_page并检查了元素以确保 html 存在?
标签: ruby-on-rails ruby-on-rails-4 rspec capybara