Skip to content

Commit 358d129

Browse files
committed
Revert "RSpec/SubjectStub. Code review. Use #on_top_level_describe instead of #on_block callback"
This reverts commit 341ae44.
1 parent 341ae44 commit 358d129

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

lib/rubocop/cop/rspec/subject_stub.rb

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ module RSpec
2222
# end
2323
#
2424
class SubjectStub < Cop
25-
include RuboCop::RSpec::TopLevelDescribe
26-
2725
MSG = 'Do not stub methods of the object under test.'
2826

2927
# @!method subject(node)
@@ -77,16 +75,24 @@ class SubjectStub < Cop
7775
} ...)
7876
PATTERN
7977

80-
def on_top_level_describe(node, _args)
81-
@explicit_subjects = find_all_explicit_subjects(node.parent)
78+
def on_block(node)
79+
return unless example_group?(node)
80+
return unless (processed_example_groups & node.ancestors).empty?
81+
82+
processed_example_groups << node
83+
@explicit_subjects = find_all_explicit_subjects(node)
8284

83-
find_subject_expectations(node.parent) do |stub|
85+
find_subject_expectations(node) do |stub|
8486
add_offense(stub)
8587
end
8688
end
8789

8890
private
8991

92+
def processed_example_groups
93+
@processed_example_groups ||= Set.new
94+
end
95+
9096
def find_all_explicit_subjects(node)
9197
node.each_descendant(:block).each_with_object({}) do |child, h|
9298
name = subject(child)

0 commit comments

Comments
 (0)