Skip to content
This repository was archived by the owner on Nov 30, 2024. It is now read-only.

Revert "Always verify mocks at the end of each example." #1988

Merged
merged 2 commits into from
Jun 11, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/rspec/core/example.rb
Original file line number Diff line number Diff line change
Expand Up @@ -441,11 +441,15 @@ def run_after_example
end

def verify_mocks
@example_group_instance.verify_mocks_for_rspec
@example_group_instance.verify_mocks_for_rspec if mocks_need_verification?
rescue Exception => e
set_exception(e)
end

def mocks_need_verification?
exception.nil? || execution_result.pending_fixed?
end

def assign_generated_description
if metadata[:description].empty? && (description = generate_description)
metadata[:description] = description
Expand Down
27 changes: 12 additions & 15 deletions spec/rspec/core/example_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -723,22 +723,19 @@ def expect_pending_result(example)
expect(ex).to fail_with(RSpec::Mocks::MockExpectationError)
end

context "when the example has already failed" do
it 'appends the mock error to a `MultipleExceptionError` so the user can see both' do
ex = nil
boom = StandardError.new("boom")

RSpec.describe do
ex = example do
dbl = double
expect(dbl).to receive(:Foo)
raise boom
end
end.run
it 'skips mock verification if the example has already failed' do
ex = nil
boom = StandardError.new("boom")

expect(ex.exception).to be_a(RSpec::Core::MultipleExceptionError)
expect(ex.exception.all_exceptions).to match [boom, an_instance_of(RSpec::Mocks::MockExpectationError)]
end
RSpec.describe do
ex = example do
dbl = double
expect(dbl).to receive(:Foo)
raise boom
end
end.run

expect(ex.exception).to be boom
end

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