Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Expect Capybara to not find something?

Say I have a "log in" button in my app, which can be enabled / disabled by the admins. What's the best way to test that this button is not rendered when the log in function is disabled? (The page should render fine, but the button should not be there.)

I can't seem to find a way to expect the find to fail. Am I approaching this wrong?

like image 318
Sauce McBoss Avatar asked Sep 16 '25 00:09

Sauce McBoss


1 Answers

Well, if your button has a class or an id then you can check if the page does not include that class or id:

expect(page).not_to have_selector "#botton_id" or ".button_class"

or if the name of your button is unique you could check if that doesn't appear on the page:

expect(page).not_to have_content('Button Name')
like image 151
atw Avatar answered Sep 18 '25 15:09

atw