lib/rubocop/cop/rspec/capybara/visibility_matcher.rb in rubocop-rspec-1.39.0 vs lib/rubocop/cop/rspec/capybara/visibility_matcher.rb in rubocop-rspec-1.40.0

- old
+ new

@@ -16,37 +16,52 @@ # # @example # # # bad # expect(page).to have_selector('.foo', visible: false) + # expect(page).to have_css('.foo', visible: true) + # expect(page).to have_link('my link', 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) + # expect(page).to have_css('.foo', visible: :all) + # expect(page).to have_link('my link', visible: :hidden) # class VisibilityMatcher < Cop MSG_FALSE = 'Use `:all` or `:hidden` instead of `false`.' MSG_TRUE = 'Use `:visible` instead of `true`.' + CAPYBARA_MATCHER_METHODS = %i[ + have_selector + have_css + have_xpath + have_link + have_button + have_field + have_select + have_table + have_checked_field + have_unchecked_field + have_text + have_content + ].freeze def_node_matcher :visible_true?, <<~PATTERN - (send nil? :have_selector ... (hash <$(pair (sym :visible) true) ...>)) + (send nil? #capybara_matcher? ... (hash <$(pair (sym :visible) true) ...>)) PATTERN def_node_matcher :visible_false?, <<~PATTERN - (send nil? :have_selector ... (hash <$(pair (sym :visible) false) ...>)) + (send nil? #capybara_matcher? ... (hash <$(pair (sym :visible) false) ...>)) PATTERN def on_send(node) visible_false?(node) { |arg| add_offense(arg, message: MSG_FALSE) } visible_true?(node) { |arg| add_offense(arg, message: MSG_TRUE) } + end + + private + + def capybara_matcher?(method_name) + CAPYBARA_MATCHER_METHODS.include? method_name end end end end end