Cucumber/Capybara: check that a page does NOT have content? Cucumber/Capybara: check that a page does NOT have content? ruby-on-rails ruby-on-rails

Cucumber/Capybara: check that a page does NOT have content?


http://rubydoc.info/github/jnicklas/capybara/master/Capybara/Node/Matchers#has_no_text%3F-instance_method

There is a has_no_content matcher in Capybara. So you can write

  Then /^I should not see "(.*?)"$/ do |arg1|    page.should have_no_content(arg1)  end


In Rspec 3.4 currently (2016) this is the recommended way to test for not having content:

expect(page).not_to have_content(arg1)


You can also use should_not if you want it read a little better:

Then /^I should not see "(.*?)"$/ do |arg1|  page.should_not have_content(arg1)end

Some more info: https://www.relishapp.com/rspec/rspec-expectations/docs