File tree Expand file tree Collapse file tree 1 file changed +11
-5
lines changed Expand file tree Collapse file tree 1 file changed +11
-5
lines changed Original file line number Diff line number Diff 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 )
You can’t perform that action at this time.
0 commit comments