Pattern: Unclear visibility in capybara finder
Issue: -
Checks for boolean visibility in capybara finders.
Capybara lets you find elements that match a certain visibility using
the :visible
option. :visible
accepts both boolean and symbols as
values, however using booleans can have unwanted effects. visible: false
does not find just invisible elements, but both visible and
invisible elements. For expressiveness and clarity, use one of the
symbol values, :all
, :hidden
or :visible
.
# bad
expect(page).to have_selector('.foo', visible: false)
# bad
expect(page).to have_selector('.foo', visible: true)
# good
expect(page).to have_selector('.foo', visible: :all)
# good
expect(page).to have_selector('.foo', visible: :hidden)
# good
expect(page).to have_selector('.foo', visible: :visible)