Class: RuboCop::Cop::RSpec::VerifiedDoubleReference
- Extended by:
- AutoCorrector
- Defined in:
- lib/rubocop/cop/rspec/verified_double_reference.rb
Overview
Checks for consistent verified double reference style.
Constant Summary collapse
- MSG =
'Use a constant class reference for verified doubles. ' \ 'String references are not verifying unless the class is loaded.'
- RESTRICT_ON_SEND =
Set[ :class_double, :class_spy, :instance_double, :instance_spy, :mock_model, :object_double, :object_spy, :stub_model ].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
#autocorrect(corrector, node) ⇒ Object
66 67 68 |
# File 'lib/rubocop/cop/rspec/verified_double_reference.rb', line 66 def autocorrect(corrector, node) corrector.replace(node, node.value) end |
#on_send(node) ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/rubocop/cop/rspec/verified_double_reference.rb', line 58 def on_send(node) verified_double(node) do |string_argument_node| add_offense(string_argument_node) do |corrector| autocorrect(corrector, string_argument_node) end end end |
#verified_double(node) ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/rubocop/cop/rspec/verified_double_reference.rb', line 50 def_node_matcher :verified_double, <<~PATTERN (send nil? RESTRICT_ON_SEND $str ...) PATTERN |