Skip to content

Commit 17e35a9

Browse files
committed
Merge pull request rspec#1988 from rspec/revert-always-verify-mocks
Revert "Always verify mocks at the end of each example."
2 parents ccda143 + ea1b3e2 commit 17e35a9

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

lib/rspec/core/example.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,11 +441,15 @@ def run_after_example
441441
end
442442

443443
def verify_mocks
444-
@example_group_instance.verify_mocks_for_rspec
444+
@example_group_instance.verify_mocks_for_rspec if mocks_need_verification?
445445
rescue Exception => e
446446
set_exception(e)
447447
end
448448

449+
def mocks_need_verification?
450+
exception.nil? || execution_result.pending_fixed?
451+
end
452+
449453
def assign_generated_description
450454
if metadata[:description].empty? && (description = generate_description)
451455
metadata[:description] = description

spec/rspec/core/example_spec.rb

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -723,22 +723,19 @@ def expect_pending_result(example)
723723
expect(ex).to fail_with(RSpec::Mocks::MockExpectationError)
724724
end
725725

726-
context "when the example has already failed" do
727-
it 'appends the mock error to a `MultipleExceptionError` so the user can see both' do
728-
ex = nil
729-
boom = StandardError.new("boom")
730-
731-
RSpec.describe do
732-
ex = example do
733-
dbl = double
734-
expect(dbl).to receive(:Foo)
735-
raise boom
736-
end
737-
end.run
726+
it 'skips mock verification if the example has already failed' do
727+
ex = nil
728+
boom = StandardError.new("boom")
738729

739-
expect(ex.exception).to be_a(RSpec::Core::MultipleExceptionError)
740-
expect(ex.exception.all_exceptions).to match [boom, an_instance_of(RSpec::Mocks::MockExpectationError)]
741-
end
730+
RSpec.describe do
731+
ex = example do
732+
dbl = double
733+
expect(dbl).to receive(:Foo)
734+
raise boom
735+
end
736+
end.run
737+
738+
expect(ex.exception).to be boom
742739
end
743740

744741
it 'allows `after(:example)` hooks to satisfy mock expectations, since examples are not complete until their `after` hooks run' do

0 commit comments

Comments
 (0)