Class: RuboCop::Cop::RSpec::PendingWithoutReason
- Inherits:
-
Base
- Object
- Base
- Base
- RuboCop::Cop::RSpec::PendingWithoutReason
show all
- Defined in:
- lib/rubocop/cop/rspec/pending_without_reason.rb
Overview
Checks for pending or skipped examples without reason.
Constant Summary
collapse
- MSG =
'Give the reason for pending or skip.'
Instance Method Summary
collapse
Methods inherited from Base
inherited, #on_new_investigation
#block_pattern, #numblock_pattern, #send_pattern
#example?, #example_group?, #example_group_with_body?, #hook?, #include?, #let?, #rspec?, #shared_group?, #spec_group?, #subject?
Instance Method Details
#on_send(node) ⇒ Object
95
96
97
98
99
100
101
102
103
104
|
# File 'lib/rubocop/cop/rspec/pending_without_reason.rb', line 95
def on_send(node)
if pending_without_reason?(node)
add_offense(node, message: 'Give the reason for pending.')
elsif skipped_without_reason?(node)
add_offense(node, message: 'Give the reason for skip.')
elsif without_reason?(node) && example?(node.parent)
add_offense(node,
message: "Give the reason for #{node.method_name}.")
end
end
|
#pending_by_example_method?(node) ⇒ Object
63
64
65
|
# File 'lib/rubocop/cop/rspec/pending_without_reason.rb', line 63
def_node_matcher :pending_by_example_method?, block_pattern(<<~PATTERN)
#Examples.pending
PATTERN
|
68
69
70
|
# File 'lib/rubocop/cop/rspec/pending_without_reason.rb', line 68
def_node_matcher :pending_by_metadata_without_reason?, <<~PATTERN
(send #rspec? {#ExampleGroups.all #Examples.all} ... {<(sym :pending) ...> (hash <(pair (sym :pending) true) ...>)})
PATTERN
|
#skipped_by_example_group_method?(node) ⇒ Object
78
79
80
81
82
83
|
# File 'lib/rubocop/cop/rspec/pending_without_reason.rb', line 78
def_node_matcher(
:skipped_by_example_group_method?,
block_pattern(<<~PATTERN)
#ExampleGroups.skipped
PATTERN
)
|
#skipped_by_example_method?(node) ⇒ Object
73
74
75
|
# File 'lib/rubocop/cop/rspec/pending_without_reason.rb', line 73
def_node_matcher :skipped_by_example_method?, block_pattern(<<~PATTERN)
#Examples.skipped
PATTERN
|
86
87
88
|
# File 'lib/rubocop/cop/rspec/pending_without_reason.rb', line 86
def_node_matcher :skipped_by_metadata_without_reason?, <<~PATTERN
(send #rspec? {#ExampleGroups.all #Examples.all} ... {<(sym :skip) ...> (hash <(pair (sym :skip) true) ...>)})
PATTERN
|
#without_reason?(node) ⇒ Object
91
92
93
|
# File 'lib/rubocop/cop/rspec/pending_without_reason.rb', line 91
def_node_matcher :without_reason?, <<~PATTERN
(send nil? ${:pending :skip})
PATTERN
|