Class: RuboCop::Cop::RSpec::ContainExactly
- Extended by:
- AutoCorrector
- Defined in:
- lib/rubocop/cop/rspec/contain_exactly.rb
Overview
Checks where ‘contain_exactly` is used.
This cop checks for the following:
-
Prefer ‘match_array` when matching array values.
-
Prefer ‘be_empty` when using `contain_exactly` with no arguments.
Constant Summary collapse
- MSG =
'Prefer `match_array` when matching array values.'- RESTRICT_ON_SEND =
%i[contain_exactly].freeze
Instance Method Summary collapse
Methods inherited from Base
inherited, #on_new_investigation
Methods included from RSpec::Language
#example?, #example_group?, #example_group_with_body?, #explicit_rspec?, #hook?, #include?, #let?, #rspec?, #shared_group?, #spec_group?, #subject?
Instance Method Details
#on_send(node) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/rubocop/cop/rspec/contain_exactly.rb', line 32 def on_send(node) return unless node.arguments.one? && node.first_argument.splat_type? add_offense(node) do |corrector| array = node.first_argument.children.first corrector.replace(node, "match_array(#{array.source})") end end |