运行'bundle exec rspec spec / requests / static_pages_spec.rb时出现以下错误:
9 examples, 2 failures
Failed examples:
rspec ./spec/requests/static_pages_spec.rb:56 # Static pages Contact page should have the title 'Contact page'
rspec ./spec/requests/static_pages_spec.rb:51 # Static pages Contact page should have the content 'Contact page'
我无法弄清楚如何让这两个测试通过。
尝试在这里学习,学习,非常新(我相信这是代码):
describe "Contact page" do
it "should have the content 'Contact'" do
visit '/static_pages/contact'
expect(page).to have_content('Contact')
end
it "should have the title 'Contact'" do
visit '/static_pages/contact'
expect(page).to have_content("Ruby on Rails Tutorial Sample App | Contact")
end
end
end
此外,html文件:
<% provide(:title, 'Contact') %>
<h1>Contact</h1>
<p>
Contact Ruby on Rails Tutorial about the sample app at the
<a href="http://railstutorial.org/contact">contact page</a>.
</p>
答案 0 :(得分:1)
您期望使用have_content标题并期望内容为have_title。
尝试
expect(page).to have_title('Contact')
和
expect(page).to have_content("Ruby on Rails Tutorial Sample App | Contact")
实际上你需要重新考虑最后一个,因为这不是你在视图中的内容,但你明白了。