0

Getting the following errors when I run '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'

I can't figure out how to get the two tests to pass here.

Trying to get through the tutorial here, learning, very new (I believe this is the code):

 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

Additionally, the html file:

<% 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>
6
  • 1
    without seeing the specs and the code the specs are working on, no-one can help you. Commented Aug 25, 2013 at 7:29
  • 1
    I can't figure out as well without knowing code and test. Commented Aug 25, 2013 at 7:29
  • 1
    You need to post the view aswell; we need to see what it is you are trying to test, not just the tests. Commented Aug 25, 2013 at 7:36
  • Thanks; I believe I have the two components previously requested. Is there anything else? Commented Aug 25, 2013 at 7:37
  • 2
    Those specs don't seem to match the failure messages you're getting: the spec is testing for a title of 'Ruby on Rails Tutorial Sample App | Contact' but the failure says the title should be 'Contact page'. Which is your app actually displaying? Commented Aug 25, 2013 at 9:02

1 Answer 1

1

You're expecting the title with have_content and expecting the content with have_title.

Try

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

and

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

Actually you need to reword this last one a little because this is not the content you have in the view but you get the idea.

Sign up to request clarification or add additional context in comments.

4 Comments

Could you edit your post to have the exact view and test code you have now please. Also, could you include the layout - for the the title are you actually yielding it?
Both have been updated, is there anything else I should change?
Your specs don't match the code, and what you are reporting as the failure doesn't match the spec. For example, your failure is saying "Contact page should have the title 'Contact page'", but the spec would output "Contact page should have the title 'Contact'" (i.e. the word page is missing). Given these mismatches it's difficult to know what is actually going wrong.
Also, you are testing for content "Ruby on Rails Tutorial Sample App | Contact" but your view is putting out different content entirely.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.