Reputation: 34013
I'm trying out Capybara with Minitest as it's included in Rails 5.1. But being a newbie I'm a bit confused with how I should write the matchers/assertions.
I've found all of the following that seem to do the same thing (and all do work):
assert page.has_content?
has_content?
assert_content
Is there any difference between these or any "correct" way?
Upvotes: 1
Views: 261
Reputation: 49870
has_content?
is just a boolean method that returns true or false, it is not an assertion so that one's out.
assert page.has_content?
is an assertion on a boolean method, so it will assert an error, but the error message will just be that it expected true and got false
assert_content
will assert an error if the content is missing and give you detailed error messages about what failed, so that should be the one to use.
Basically prefer the asssertions defined in https://github.com/teamcapybara/capybara/blob/master/lib/capybara/minitest.rb when using with Minitest
Upvotes: 2