Reputation: 15141
I'm learning from this site. I tested the following with rspec, and it passed.
describe "About page" do
it "should have the content 'About Us'" do
visit '/static_pages/about'
expect(page).to have_content('About Us')
end
end
I changed About Us
to <h1>About Us</h1>
to check whether it works as I expected, but the test fails even when about.html.erb
has the string <h1>About Us</h1>
. Could you show me how I can use html tag expression in rspec file?
Upvotes: 1
Views: 2679
Reputation: 5998
If I understand you correctly you would like to check that the page has text 'About Us' in tag h1. You can use rich Capybara functionality.
For example you can use within
within('h1') do
expect(page).to have_content('About Us')
end
There are another ways for example use css-selectors or xpath
Upvotes: 2