0

运行 '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>
4

1 回答 1

1

您期待带有 has_content 的标题并期待带有 has_title 的内容。

尝试

expect(page).to have_title('Contact')

expect(page).to have_content("Ruby on Rails Tutorial Sample App | Contact")

实际上,您需要稍微改写最后一个,因为这不是您在视图中拥有的内容,但您明白了。

于 2013-08-25T08:06:27.717 回答