Class: Gitlab::Styles::Rubocop::Cop::RSpec::HaveLinkParameters

Inherits:
RuboCop::Cop::RSpec::Cop
  • Object
show all
Defined in:
lib/gitlab/styles/rubocop/cop/rspec/have_link_parameters.rb

Overview

This cop checks for unused parameters to the ‘have_link` matcher.

Examples:


# bad
expect(page).to have_link('Link', 'https://example.com')

# good
expect(page).to have_link('Link', href: 'https://example.com')
expect(page).to have_link('Example')

Constant Summary collapse

MESSAGE =
"The second argument to `have_link` should be a Hash.".freeze

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'lib/gitlab/styles/rubocop/cop/rspec/have_link_parameters.rb', line 27

def on_send(node)
  return unless unused_parameters?(node)

  location = node.arguments[1..-1]
    .map(&:source_range)
    .reduce(:join)

  add_offense(node, location: location, message: MESSAGE)
end