Sha256: 2d596dcef133d276a7b112bf7dc95ffb29edb0812ca418e6677adbfaff5c5ebd

Contents?: true

Size: 1.62 KB

Versions: 14

Compression:

Stored size: 1.62 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Capybara
      # Checks for usage of deprecated style methods.
      #
      # @example when using `assert_style`
      #   # bad
      #   page.find(:css, '#first').assert_style(display: 'block')
      #
      #   # good
      #   page.find(:css, '#first').assert_matches_style(display: 'block')
      #
      # @example when using `has_style?`
      #   # bad
      #   expect(page.find(:css, 'first')
      #     .has_style?(display: 'block')).to be true
      #
      #   # good
      #   expect(page.find(:css, 'first')
      #     .matches_style?(display: 'block')).to be true
      #
      # @example when using `have_style`
      #   # bad
      #   expect(page).to have_style(display: 'block')
      #
      #   # good
      #   expect(page).to match_style(display: 'block')
      #
      class MatchStyle < ::RuboCop::Cop::Base
        extend AutoCorrector

        MSG = 'Use `%<good>s` instead of `%<bad>s`.'
        RESTRICT_ON_SEND = %i[assert_style has_style? have_style].freeze
        PREFERRED_METHOD = {
          'assert_style' => 'assert_matches_style',
          'has_style?' => 'matches_style?',
          'have_style' => 'match_style'
        }.freeze

        def on_send(node)
          method_node = node.loc.selector
          add_offense(method_node) do |corrector|
            corrector.replace(method_node,
                              PREFERRED_METHOD[method_node.source])
          end
        end

        private

        def message(node)
          format(MSG, good: PREFERRED_METHOD[node.source], bad: node.source)
        end
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 6 rubygems

Version Path
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/rubocop-capybara-2.21.0/lib/rubocop/cop/capybara/match_style.rb
katalyst-govuk-formbuilder-1.9.2 vendor/bundle/ruby/3.3.0/gems/rubocop-capybara-2.21.0/lib/rubocop/cop/capybara/match_style.rb
rubocop-capybara-2.21.0 lib/rubocop/cop/capybara/match_style.rb
mlh-rubocop-config-1.0.3 vendor/bundle/ruby/3.2.0/gems/rubocop-capybara-2.20.0/lib/rubocop/cop/capybara/match_style.rb
rubocop-capybara-2.20.0 lib/rubocop/cop/capybara/match_style.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rubocop-capybara-2.18.0/lib/rubocop/cop/capybara/match_style.rb
rubocop-capybara-2.19.0 lib/rubocop/cop/capybara/match_style.rb
mlh-rubocop-config-1.0.2 vendor/bundle/ruby/3.2.0/gems/rubocop-capybara-2.18.0/lib/rubocop/cop/capybara/match_style.rb
fablicop-1.10.3 vendor/bundle/ruby/3.2.0/gems/rubocop-capybara-2.18.0/lib/rubocop/cop/capybara/match_style.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rubocop-capybara-2.18.0/lib/rubocop/cop/capybara/match_style.rb
fablicop-1.10.2 vendor/bundle/ruby/3.2.0/gems/rubocop-capybara-2.18.0/lib/rubocop/cop/capybara/match_style.rb
rubocop-capybara-2.18.0 lib/rubocop/cop/capybara/match_style.rb
rubocop-capybara-2.17.1 lib/rubocop/cop/capybara/match_style.rb
rubocop-capybara-2.17.0 lib/rubocop/cop/capybara/match_style.rb