Class: RuboCop::Cop::Workit::RSpecCapybaraMatchStyle

Inherits:
Base
  • Object
show all
Extended by:
AutoCorrector
Defined in:
lib/rubocop/cop/workit/rspec_capybara_match_style.rb

Overview

Checks for usage of deprecated style methods.

Examples:

when using ‘assert_style`

# bad
page.find(:css, '#first').assert_style(display: 'block')

# good
page.find(:css, '#first').assert_matches_style(display: 'block')

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

when using ‘have_style`

# bad
expect(page).to have_style(display: 'block')

# good
expect(page).to match_style(display: 'block')

Constant Summary collapse

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

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/rubocop/cop/workit/rspec_capybara_match_style.rb', line 42

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