lib/rubocop/cop/rspec/subject_stub.rb in rubocop-rspec-1.40.0 vs lib/rubocop/cop/rspec/subject_stub.rb in rubocop-rspec-1.41.0
- old
+ new
@@ -20,10 +20,12 @@
# allow(bar).to receive(:qux?).and_return(true)
# end
# end
#
class SubjectStub < Cop
+ include RuboCop::RSpec::TopLevelGroup
+
MSG = 'Do not stub methods of the object under test.'
# @!method subject(node)
# Find a named or unnamed subject definition
#
@@ -73,26 +75,18 @@
(send nil? {
:receive :receive_messages :receive_message_chain :have_received
} ...)
PATTERN
- def on_block(node)
- return unless example_group?(node)
- return if (processed_example_groups & node.ancestors).any?
-
- processed_example_groups << node
+ def on_top_level_group(node)
@explicit_subjects = find_all_explicit_subjects(node)
find_subject_expectations(node) do |stub|
add_offense(stub)
end
end
private
-
- def processed_example_groups
- @processed_example_groups ||= Set.new
- end
def find_all_explicit_subjects(node)
node.each_descendant(:block).with_object({}) do |child, h|
name = subject(child)
next unless name