Skip to content

Commit

Permalink
Revert "Always verify mocks at the end of each example."
Browse files Browse the repository at this point in the history
This reverts commit f989168.

This is necessary to avoid the issue discussed in rspec/rspec-mocks#203.
I'm reverting it so we can release 3.3. We may bring this back for
3.4 if we can find a better solution.
  • Loading branch information
myronmarston committed Jun 10, 2015
1 parent 5778abd commit 11a268f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 19 deletions.
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
33 changes: 15 additions & 18 deletions spec/rspec/core/example_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -723,35 +723,32 @@ 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
ex = nil

RSpec.describe do
let(:the_dbl) { double }
let(:dbl) { double }

ex = example do
expect(the_dbl).to receive(:foo)
expect(dbl).to receive(:foo)
end

after { the_dbl.foo }
after { dbl.foo }
end.run

expect(ex).to pass
Expand Down

0 comments on commit 11a268f

Please sign in to comment.