Class: RuboCop::Cop::RSpec::SingleArgumentMessageChain
- Defined in:
- lib/rubocop/cop/rspec/single_argument_message_chain.rb
Overview
Checks that chains of messages contain more than one element.
Constant Summary collapse
- MSG =
'Use `%<recommended>s` instead of calling '\ '`%<called>s` with a single argument.'.freeze
Constants inherited from Cop
Cop::DEFAULT_CONFIGURATION, Cop::DEFAULT_PATTERN_RE
Constants included from RSpec::Language
Instance Method Summary collapse
Methods inherited from Cop
Instance Method Details
#autocorrect(node) ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/rubocop/cop/rspec/single_argument_message_chain.rb', line 37 def autocorrect(node) lambda do |corrector| corrector.replace(node.loc.selector, replacement(node.method_name)) (node) do |arg| autocorrect_hash_arg(corrector, arg) if single_key_hash?(arg) end end end |
#on_send(node) ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/rubocop/cop/rspec/single_argument_message_chain.rb', line 27 def on_send(node) (node) do |arg| return if arg.to_s.include?('.') return if arg.hash_type? && !single_key_hash?(arg) add_offense(node, location: :selector) end end |