Skip to content

Commit

Permalink
Refactor and improve performance
Browse files Browse the repository at this point in the history
  • Loading branch information
pirj committed Jan 16, 2022
1 parent 9192504 commit 92b787c
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions lib/rubocop/cop/rspec/subject_stub.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class SubjectStub < Base
def_node_matcher :message_expectation?, <<-PATTERN
(send
{
(send nil? { :expect :allow } (send nil? {% :subject}))
(send nil? { :expect :allow } (send nil? %))
(send nil? :is_expected)
}
#Runners.all
Expand Down Expand Up @@ -120,7 +120,7 @@ def find_all_explicit_subjects(node)
name = subject(child)
next unless name

outer_example_group = child.each_ancestor.find do |a|
outer_example_group = child.each_ancestor(:block).find do |a|
example_group?(a)
end

Expand All @@ -132,12 +132,11 @@ def find_all_explicit_subjects(node)
def find_subject_expectations(node, subject_names = [], &block)
subject_names = @explicit_subjects[node] if @explicit_subjects[node]

expectation_detected = (subject_names + [:subject]).any? do |name|
message_expectation?(node, name)
end
names = Set[*[*subject_names, :subject]]
expectation_detected = message_expectation?(node, names)
return yield(node) if expectation_detected

node.each_child_node do |child|
node.each_child_node(:send, :block, :begin) do |child|
find_subject_expectations(child, subject_names, &block)
end
end
Expand Down

0 comments on commit 92b787c

Please sign in to comment.