Class: RuboCop::Cop::RSpec::RepeatedExampleGroupBody
- Inherits:
-
Base
- Object
- Base
- Base
- RuboCop::Cop::RSpec::RepeatedExampleGroupBody
show all
- Includes:
- SkipOrPending
- Defined in:
- lib/rubocop/cop/rspec/repeated_example_group_body.rb
Overview
Check for repeated describe and context block body.
Constant Summary
collapse
- MSG =
'Repeated %<group>s block body on line(s) %<loc>s'
Instance Method Summary
collapse
#skip_or_pending_inside_block?, #skipped_in_metadata?
Methods inherited from Base
inherited, #on_new_investigation
#example?, #example_group?, #example_group_with_body?, #explicit_rspec?, #hook?, #include?, #let?, #rspec?, #shared_group?, #spec_group?, #subject?
Instance Method Details
#body(node) ⇒ Object
59
|
# File 'lib/rubocop/cop/rspec/repeated_example_group_body.rb', line 59
def_node_matcher :body, '(block _ args $...)'
|
#const_arg(node) ⇒ Object
62
|
# File 'lib/rubocop/cop/rspec/repeated_example_group_body.rb', line 62
def_node_matcher :const_arg, '(block (send _ _ $const ...) ...)'
|
56
|
# File 'lib/rubocop/cop/rspec/repeated_example_group_body.rb', line 56
def_node_matcher :metadata, '(block (send _ _ _ $...) ...)'
|
#on_begin(node) ⇒ Object
64
65
66
67
68
69
70
|
# File 'lib/rubocop/cop/rspec/repeated_example_group_body.rb', line 64
def on_begin(node)
return unless several_example_groups?(node)
repeated_group_bodies(node).each do |group, repeats|
add_offense(group, message: message(group, repeats))
end
end
|
#several_example_groups?(node) ⇒ Object
51
52
53
|
# File 'lib/rubocop/cop/rspec/repeated_example_group_body.rb', line 51
def_node_matcher :several_example_groups?, <<~PATTERN
(begin <#example_group_with_body? #example_group_with_body? ...>)
PATTERN
|