10000 Only safeguard internals from recursion · rspec/rspec@95f1e86 · GitHub
[go: up one dir, main page]

Skip to content

Commit 95f1e86

Browse files
committed
Only safeguard internals from recursion
1 parent d1dc312 commit 95f1e86

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

rspec-mocks/lib/rspec/mocks/message_expectation.rb

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ def initialize(error_generator, expectation_ordering, expected_from, method_doub
438438
@ordered = false
439439
@at_least = @at_most = @exactly = nil
440440

441-
self.invoking = false
441+
self.invoking_internals = false
442442

443443
# Initialized to nil so that we don't allocate an array for every
444444
# mock or stub. See also comment in `and_yield`.
@@ -475,7 +475,7 @@ def safe_invoke(parent_stub, *args, &block)
475475
ruby2_keywords :safe_invoke if respond_to?(:ruby2_keywords, true)
476476

477477
def invoke(parent_stub, *args, &block)
478-
if invoking
478+
if invoking_internals
479479
safe_invoke_without_incrementing_received_count(parent_stub, *args, &block)
480480
else
481481
invoke_incrementing_actual_calls_by(1, true, parent_stub, *args, &block)
@@ -486,6 +486,7 @@ def invoke(parent_stub, *args, &block)
486486
def safe_invoke_without_incrementing_received_count(parent_stub, *args, &block)
487487
invoke_incrementing_actual_calls_by(0, false, parent_stub, *args, &block)
488488
end
489+
ruby2_keywords :safe_invoke_without_incrementing_received_count if respond_to?(:ruby2_keywords, true)
489490

490491
def invoke_without_incrementing_received_count(parent_stub, *args, &block)
491492
invoke_incrementing_actual_calls_by(0, true, parent_stub, *args, &block)
@@ -613,18 +614,18 @@ def exception_source_id
613614
@exception_source_id ||= "#{self.class.name} #{__id__}"
614615
end
615616

616-
def invoking
617-
RSpec::Support.thread_local_data[:"__rspec_#{object_id}_invoking"]
617+
def invoking_internals
618+
RSpec::Support.thread_local_data[:"__rspec_#{object_id}_invoking_internals"]
618619
end
619620

620-
def invoking=(value)
621-
RSpec::Support.thread_local_data[:"__rspec_#{object_id}_invoking"] = value
621+
def invoking_internals=(value)
622+
RSpec::Support.thread_local_data[:"__rspec_#{object_id}_invoking_internals"] = value
622623
end
623624

624625
def invoke_incrementing_actual_calls_by(increment, allowed_to_fail, parent_stub, *args, &block)
625-
args.unshift(orig_object) if yield_receiver_to_implementation_block?
626+
self.invoking_internals = true
626627

627-
self.invoking = true
628+
args.unshift(orig_object) if yield_receiver_to_implementation_block?
628629

629630
if negative? || (allowed_to_fail && (@exactly || @at_most) && (@actual_received_count == @expected_received_count))
630631
# args are the args we actually received, @argument_list_matcher is the
@@ -639,13 +640,15 @@ def invoke_incrementing_actual_calls_by(increment, allowed_to_fail, parent_stub,
639640

640641
@order_group.handle_order_constraint self
641642

643+
self.invoking_internals = false
644+
642645
if implementation.present?
643646
implementation.call(*args, &block)
644647
elsif parent_stub
645648
parent_stub.invoke(nil, *args, &block)
646649
end
647650
ensure
648-
self.invoking = false
651+
self.invoking_internals = false
649652
@actual_received_count_write_mutex.synchronize do
650653
@actual_received_count += increment
651654
end

rspec-mocks/spec/rspec/mocks/partial_double_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,19 @@ def call(name)
6161
an_object.call :my_method
6262
end
6363

64+
# This is a regresion test for rspec/rspec#212 / rspec/rspec#213
65+
it "supports nesting" do
66+
nested = false
67+
expect(object).to receive(:nested).twice do
68+
unless nested
69+
nested = true
70+
object.nested
71+
end
72+
end
73+
74+
object.nested
75+
end
76+
6477
it "can disallow messages from being received" do
6578
expect(object).not_to receive(:fuhbar)
6679
expect_fast_failure_from(

0 commit comments

Comments
 (0)
0