Capybara's README used to make a point of saying that you should use page.should have_no_content
and have_no_selector
when asserting the lack of some element/content (because these methods wait for the elements to disappear, if the selected Capybara driver supports waiting).
Now, Capybara's RSpec matchers have been improved so (per the documentation) saying page.should_not have_content
is now functionally equivalent to saying page.should have_no_content
(because it will call page.has_no_content?
instead of reversing the result of page.has_content?
which is not the same because of waiting).
Anywho, Capybara's code looks clear but here's a spec just to double check! 😃
Capybara RSpec Matcher
TEST: page.should_not have_content (should be the same as page.has_no_content?)
Capybara::Node::Document#has_no_content?(["Content that will go away after a few seconds"], &nil)
Capybara::Node::Document#has_no_selector?([:xpath, ./descendant-or-self::*[contains(normalize-space(.), 'Content that will go away after a few seconds')], {}], &nil)
page.should_not have_content (should be the same as page.has_no_content?)
TEST: page.should have_content (should be the same as page.has_content?)
Capybara::Node::Document#has_content?(["Content that will APPEAR after a few seconds"], &nil)
Capybara::Node::Document#has_selector?([:xpath, ./descendant-or-self::*[contains(normalize-space(.), 'Content that will APPEAR after a few seconds')], {}], &nil)
page.should have_content (should be the same as page.has_content?)
TEST: page.should_not have_selector (should be the same as page.has_no_selector?)
Capybara::Node::Document#has_no_selector?(["#selector-that-will-go-away-after-a-few-seconds"], &nil)
page.should_not have_selector (should be the same as page.has_no_selector?)
TEST: page.should have_selector (should be the same as page.has_selector?)
Capybara::Node::Document#has_selector?(["#selector-that-will-APPEAR-after-a-few-seconds"], &nil)
page.should have_selector (should be the same as page.has_selector?)
Finished in 9.39 seconds
4 examples, 0 failures