Skip to content

Commit

Permalink
Revert "RSpec/SubjectStub. Code review. Use #on_top_level_describe in…
Browse files Browse the repository at this point in the history
…stead of #on_block callback"

This reverts commit 341ae44.
  • Loading branch information
andrykonchin committed Jun 9, 2020
1 parent 341ae44 commit 358d129
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions lib/rubocop/cop/rspec/subject_stub.rb
Expand Up @@ -22,8 +22,6 @@ module RSpec
# end
#
class SubjectStub < Cop
include RuboCop::RSpec::TopLevelDescribe

MSG = 'Do not stub methods of the object under test.'

# @!method subject(node)
Expand Down Expand Up @@ -77,16 +75,24 @@ class SubjectStub < Cop
} ...)
PATTERN

def on_top_level_describe(node, _args)
@explicit_subjects = find_all_explicit_subjects(node.parent)
def on_block(node)
return unless example_group?(node)
return unless (processed_example_groups & node.ancestors).empty?

processed_example_groups << node
@explicit_subjects = find_all_explicit_subjects(node)

find_subject_expectations(node.parent) do |stub|
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).each_with_object({}) do |child, h|
name = subject(child)
Expand Down

0 comments on commit 358d129

Please sign in to comment.