Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Using Cucumber and Capybara, is there a way to verify that a string is NOT present on a page?

For example, how would I write the opposite of this step:

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

This passes if arg1 is present.

How would I write a step that fails if arg1 is found?

like image 774
dB' Avatar asked Aug 16 '12 02:08

dB'


2 Answers

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
like image 65
Piotr Jakubowski Avatar answered Oct 21 '22 09:10

Piotr Jakubowski


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

expect(page).not_to have_content(arg1)
like image 16
Micah Avatar answered Oct 21 '22 09:10

Micah