Skip to content

Commit

Permalink
Don't mutate the user metadata :pending wrongly.
Browse files Browse the repository at this point in the history
In the metadata, `:pending` expresses user intent,
not the result of the running the example. The result
goes in execution_result. So, we should not mutate
this key based on the result of the example.

There was also some missing test coverage that I added here.

Fixes #1376.
  • Loading branch information
myronmarston committed Mar 16, 2014
1 parent 92af3fe commit 2ebf741
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
9 changes: 2 additions & 7 deletions lib/rspec/core/example.rb
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def around_each_hooks
# Used internally to set an exception in an after hook, which
# captures the exception but doesn't raise it.
def set_exception(exception, context=nil)
if pending?
if pending? && !(Pending::PendingExampleFixedError === exception)
execution_result.pending_exception = exception
else
if @exception && context != :dont_print
Expand Down Expand Up @@ -321,13 +321,8 @@ def run_after_each
def verify_mocks
@example_group_instance.verify_mocks_for_rspec
rescue Exception => e
if execution_result.pending_message
if pending?
execution_result.pending_fixed = false
# TODO: should we really change this? In the user metadata,
# `:pending` indicates the user intends to make the example
# pending, not that it actually was -- that's what the
# execution_result is for.
metadata[:pending] = true
@exception = nil
else
set_exception(e, :dont_print)
Expand Down
1 change: 0 additions & 1 deletion lib/rspec/core/pending.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ def self.mark_pending!(example, message_or_bool)
#
# @param example [RSpec::Core::Example] the example to mark as fixed
def self.mark_fixed!(example)
example.metadata[:pending] = false
example.execution_result.pending_fixed = true
end
end
Expand Down
13 changes: 13 additions & 0 deletions spec/rspec/core/pending_example_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,19 @@
example.run(group.new, double.as_null_object)
expect(example).to be_pending_with('No reason given')
end

it "passes if a mock expectation is not satisifed" do
group = RSpec::Core::ExampleGroup.describe('group') do
example "example", :pending => "because" do
expect(RSpec).to receive(:a_message_in_a_bottle)
end
end

example = group.examples.first
example.run(group.new, double.as_null_object)
expect(example).to be_pending_with('because')
expect(example.execution_result.status).to eq('pending')
end
end

context "with no block" do
Expand Down

0 comments on commit 2ebf741

Please sign in to comment.