Class: RuboCop::Cop::RSpec::RepeatedIncludeExample
- Defined in:
- lib/rubocop/cop/rspec/repeated_include_example.rb
Overview
Check for repeated include of shared examples.
Constant Summary collapse
- MSG =
'Repeated include of shared_examples %<name>s ' \ 'on line(s) %<repeat>s'
Instance Method Summary collapse
- #include_examples?(node) ⇒ Object
- #on_begin(node) ⇒ Object
- #several_include_examples?(node) ⇒ Object
- #shared_examples_name(node) ⇒ Object
Methods inherited from Base
inherited, #on_new_investigation
Methods included from RSpec::Language::NodePattern
#block_or_numblock_pattern, #block_pattern, #numblock_pattern, #send_pattern
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
#include_examples?(node) ⇒ Object
58 59 |
# File 'lib/rubocop/cop/rspec/repeated_include_example.rb', line 58 def_node_matcher :include_examples?, '(send nil? #Includes.examples ...)' |
#on_begin(node) ⇒ Object
65 66 67 68 69 70 71 |
# File 'lib/rubocop/cop/rspec/repeated_include_example.rb', line 65 def on_begin(node) return unless several_include_examples?(node) repeated_include_examples(node).each do |item, repeats| add_offense(item, message: (item, repeats)) end end |
#several_include_examples?(node) ⇒ Object
53 54 55 |
# File 'lib/rubocop/cop/rspec/repeated_include_example.rb', line 53 def_node_matcher :several_include_examples?, <<~PATTERN (begin <#include_examples? #include_examples? ...>) PATTERN |
#shared_examples_name(node) ⇒ Object
62 63 |
# File 'lib/rubocop/cop/rspec/repeated_include_example.rb', line 62 def_node_matcher :shared_examples_name, '(send nil? #Includes.examples $_name ...)' |