Trying to test that page contains
with:
# spec/features/reports_spec.rb
require \'spec_helper\'
feature \"A
I see two possible issues here:
tag is present on the page but the text My Title
is somewhere else on the page, not within the tag. That would explain why the other tests pass: there is a
tag on the page so have_selector('title')
passes, and there is the My Title
text on the page so have_text(base_title)
passes.
tag contains the text My Title
as well as something else, which would also explain the results you see: there is a
tag on the page so have_selector('title')
passes, and there is the text My Title
so the have_text(base_title)
also passes, however the text
option in have_selector
is strict, therefore it will fail if it finds a string which does not exactly equal My Title
.You can check the latter of these two possibilities using the xpath selector: should have_xpath("//title[contains(.,'#{base_title}')]")
. If that passes, then you probably have some whitespace or newlines around your title text which are tripping have_selector
up (I thought it ignored those, but I could be wrong).
Hope that helps.