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

Commit e5b18b7

Browse files
committed
Merge pull request #1106 from lgierth/dont-extend-exception
Don't extend exception Conflicts: Changelog.md lib/rspec/core/pending.rb
1 parent 0f99d62 commit e5b18b7

File tree

6 files changed

+48
-27
lines changed

6 files changed

+48
-27
lines changed

Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Deprecations
2828
RSpec 3 will not support having this option set to `false` (Myron Marston).
2929
* Deprecate accessing a `let` or `subject` declaration in
3030
a `after(:all)` hook. (Myron Marston, Jon Rowe)
31+
* Fix an issue that prevented the use of frozen error objects. (Lars Gierth)
3132

3233
### 2.14.5 / 2013-08-13
3334
[full changelog](http://github.com/rspec/rspec-core/compare/v2.14.4...v2.14.5)

lib/rspec/core/example.rb

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -261,14 +261,8 @@ def start(reporter)
261261
record :started_at => RSpec::Core::Time.now
262262
end
263263

264-
# @private
265-
module NotPendingExampleFixed
266-
def pending_fixed?; false; end
267-
end
268-
269264
def finish(reporter)
270265
if @exception
271-
@exception.extend(NotPendingExampleFixed) unless @exception.respond_to?(:pending_fixed?)
272266
record_finished 'failed', :exception => @exception
273267
reporter.example_failed self
274268
false

lib/rspec/core/formatters/base_text_formatter.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ def dump_pending_fixed(example, index)
285285
end
286286

287287
def pending_fixed?(example)
288-
example.execution_result[:exception].pending_fixed?
288+
example.execution_result[:pending_fixed]
289289
end
290290

291291
def dump_failure(example, index)

lib/rspec/core/formatters/html_formatter.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def example_failed(example)
9494
extra = extra_failure_content(exception)
9595

9696
@printer.print_example_failed(
97-
exception.pending_fixed?,
97+
example.execution_result[:pending_fixed],
9898
example.description,
9999
example.execution_result[:run_time],
100100
@failed_examples.size,

lib/rspec/core/pending.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ class PendingExampleFixedError < Test::Unit::AssertionFailedError; end
1111
class PendingExampleFixedError < StandardError; end
1212
end
1313

14-
class PendingExampleFixedError
15-
def pending_fixed?; true; end
16-
end
17-
1814
NO_REASON_GIVEN = 'No reason given'
1915
NOT_YET_IMPLEMENTED = 'Not yet implemented'
2016

@@ -87,6 +83,7 @@ def pending(*args)
8783

8884
RSpec.current_example.metadata[:pending] = true
8985
RSpec.current_example.metadata[:execution_result][:pending_message] = message
86+
RSpec.current_example.execution_result[:pending_fixed] = false
9087
if block_given?
9188
begin
9289
result = begin
@@ -99,7 +96,10 @@ def pending(*args)
9996
ensure
10097
teardown_mocks_for_rspec
10198
end
102-
raise PendingExampleFixedError.new if result
99+
if result
100+
RSpec.current_example.execution_result[:pending_fixed] = true
101+
raise PendingExampleFixedError.new
102+
end
103103
end
104104
raise PendingDeclaredInExample.new(message)
105105
end

spec/rspec/core/example_spec.rb

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,6 @@ def capture_stdout
4545
example_group.run
4646
expect(example.exception).to be_nil
4747
end
48-
49-
it "returns false for pending_fixed? if not pending fixed" do
50-
example = example_group.example { fail }
51-
example_group.run
52-
expect(example.exception).not_to be_pending_fixed
53-
end
54-
55-
it "returns true for pending_fixed? if pending fixed" do
56-
example = example_group.example do
57-
pending("fixed") {}
58-
end
59-
example_group.run
60-
expect(example.exception).to be_pending_fixed
61-
end
6248
end
6349

6450
describe "when there is an explicit description" do
@@ -345,6 +331,22 @@ def run_and_capture_reported_message(group)
345331
message = run_and_capture_reported_message(group)
346332
expect(message).to be_nil
347333
end
334+
335+
it "leaves a raised exception unmodified (GH-1103)" do
336+
# set the backtrace, otherwise MRI will build a whole new object,
337+
# and thus mess with our expectations. Rubinius and JRuby are not
338+
# affected.
339+
exception = StandardError.new
340+
exception.set_backtrace([])
341+
342+
group = RSpec::Core::ExampleGroup.describe do
343+
example { raise exception.freeze }
344+
end
345+
group.run
346+
347+
actual = group.examples.first.metadata[:execution_result][:exception]
348+
expect(actual.__id__).to eq(exception.__id__)
349+
end
348350
end
349351
end
350352

@@ -370,6 +372,30 @@ def run_and_capture_reported_message(group)
370372
group.run
371373
expect(blah).to be(:success)
372374
end
375+
376+
context "with a block" do
377+
it "sets the example to pending if block fails" do
378+
group = RSpec::Core::ExampleGroup.describe do
379+
example do
380+
pending { expect(1).to eq(2) }
381+
end
382+
end
383+
group.run
384+
expect(group.examples.first.metadata[:execution_result][:status]).to eq('pending')
385+
expect(group.examples.first.metadata[:execution_result][:pending_fixed]).to eq(false)
386+
end
387+
388+
it "fails if block is fixed, i.e. does not raise" do
389+
group = RSpec::Core::ExampleGroup.describe do
390+
example do
391+
pending {}
392+
end
393+
end
394+
group.run
395+
expect(group.examples.first.metadata[:execution_result][:status]).to eq('failed')
396+
expect(group.examples.first.metadata[:execution_result][:pending_fixed]).to eq(true)
397+
end
398+
end
373399
end
374400

375401
context "in before(:each)" do

0 commit comments

Comments
 (0)