Reputation: 3105
I'm currently using the following piece to code to check if my page has a specific piece of text:
it { should have_selector('test_container', text: 'hiya') }
All I'm checking is a span on my page:
<span id="test_container">hiya</span>
How do I do I test for the contents of a specific span tag like this? I don't want to check the entire page for the text 'hiya' but a specific span tag like the above.
Thanks!
Upvotes: 2
Views: 3148
Reputation: 6034
Capybara gives you two possibilities here, you can either use the find method:
find('#text_container').should have_content('hiya')
or you can scoping to restrict a block to an html container:
within '#text_container' do
page.should have_content 'hiya'
end
Note that although you're saying page.should
in the block, it is restricted to the scoped element.
Upvotes: 5