Class: RuboCop::Cop::RSpec::OverwritingSetup
- Defined in:
- lib/rubocop/cop/rspec/overwriting_setup.rb
Overview
Checks if there is a let/subject that overwrites an existing one.
Constant Summary collapse
- MSG =
'`%<name>s` is already defined.'
Instance Method Summary collapse
Methods inherited from Base
inherited, #on_new_investigation
Methods included from RSpec::Language::NodePattern
Methods included from RSpec::Language
#example?, #example_group?, #example_group_with_body?, #hook?, #include?, #let?, #rspec?, #shared_group?, #spec_group?, #subject?
Instance Method Details
#first_argument_name(node) ⇒ Object
31 |
# File 'lib/rubocop/cop/rspec/overwriting_setup.rb', line 31 def_node_matcher :first_argument_name, '(send _ _ ({str sym} $_))' |
#on_block(node) ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/rubocop/cop/rspec/overwriting_setup.rb', line 33 def on_block(node) return unless example_group_with_body?(node) find_duplicates(node.body) do |duplicate, name| add_offense( duplicate, message: format(MSG, name: name) ) end end |
#setup?(node) ⇒ Object
28 |
# File 'lib/rubocop/cop/rspec/overwriting_setup.rb', line 28 def_node_matcher :setup?, block_pattern('{#Helpers.all #Subjects.all}') |