webgirl
webgirl

Reputation: 405

Capybara has_css? passing when it should fail

Why does the following step pass:

page.has_css?("doesnt exist")

when this correctly fails:

page.should have_css("doesnt exist")

If I run:

puts page.has_css?("doesnt exist")

it prints "false", but the step still passes.

Any idea why?

Upvotes: 1

Views: 1502

Answers (1)

coder_tim
coder_tim

Reputation: 1720

You should probably have:

assert page.has_css?("doesnt exist")

If you write "2 == 3" in a test, it will evaluate to false, but the test method will not necessarily fail. You need an assert. I think the "should" style syntax are doing some kind of assert under the hood as well.

Upvotes: 2

Related Questions