File tree Expand file tree Collapse file tree 1 file changed +5
-11
lines changed Expand file tree Collapse file tree 1 file changed +5
-11
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,8 @@ module RSpec
2222 # end
2323 #
2424 class SubjectStub < Cop
25+ include RuboCop ::RSpec ::TopLevelDescribe
26+
2527 MSG = 'Do not stub methods of the object under test.'
2628
2729 # @!method subject(node)
@@ -75,24 +77,16 @@ class SubjectStub < Cop
7577 } ...)
7678 PATTERN
7779
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 )
80+ def on_top_level_describe ( node , _args )
81+ @explicit_subjects = find_all_explicit_subjects ( node . parent )
8482
85- find_subject_expectations ( node ) do |stub |
83+ find_subject_expectations ( node . parent ) do |stub |
8684 add_offense ( stub )
8785 end
8886 end
8987
9088 private
9189
92- def processed_example_groups
93- @processed_example_groups ||= Set . new
94- end
95-
9690 def find_all_explicit_subjects ( node )
9791 node . each_descendant ( :block ) . each_with_object ( { } ) do |child , h |
9892 name = subject ( child )
You can’t perform that action at this time.
0 commit comments