阅读第5章第5.3.4节(漂亮规范)中的Harlts教程。 即使遵循所有说明我也会收到此错误。
Static pages Contact page
Failure/Error: it { should have_title(full_title('Contact')) }
expected #has_title?("Ruby on Rails Tutorial Sample App | Contact") to return true, got false
# ./spec/requests/static_pages_spec.rb:39:in `block (3 levels) in <top (required)>'
Finished in 0.29544 seconds
11 examples, 3 failures
Failed examples:
rspec ./spec/requests/static_pages_spec.rb:25 # Static pages Help page
rspec ./spec/requests/static_pages_spec.rb:32 # Static pages About page
rspec ./spec/requests/static_pages_spec.rb:39 # Static pages Contact page
以下是 spec / support / utilities.rb 文件
的内容def full_title(page_title)
base_title = "Ruby on Rails Tutorial Sample App"
if page_title.empty?
base_title
else
"#{base_title} | #{page_title}"
end
end
以及 static_pages_spec.rb 文件的内容
require 'spec_helper'
describe "Static pages" do
subject { page }
describe "Home page" do
before { visit root_path }
it { should have_content('Sample App') }
it { should have_title(full_title('home')) }
it { should_not have_title('| Home') }
end
describe "Help page" do
before { visit help_path }
it { should have_content('Help') }
it { should have_title(full_title('Help')) }
end
describe "About page" do
before { visit about_path }
it { should have_content('About') }
it { should have_title(full_title('About')) }
end
describe "Contact page" do
before { visit contact_path }
it { should have_content('Contact') }
it { should have_title(full_title('Contact')) }
end
end
答案 0 :(得分:0)
主页标题文字只显示Ruby on Rails Tutorial Sample App
而没有| Home
部分。
所以改变
describe "Home page" do
before { visit root_path }
it { should have_content('Sample App') }
it { should have_title(full_title('home')) }
it { should_not have_title('| Home') }
end
到
describe "Home page" do
before { visit root_path }
it { should have_content('Sample App') }
it { should have_title(full_title('')) }
it { should_not have_title('| Home') }
end
所以删除第5行的home