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

Commit a9f9d5a

Browse files
committed
Merge pull request #2144 from rspec/abort-with-profile
Ensure ExecutionResult timing is always populated
2 parents bb214a2 + 8cdb63a commit a9f9d5a

File tree

3 files changed

+36
-5
lines changed

3 files changed

+36
-5
lines changed

Changelog.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
### Development
2+
[Full Changelog](http://github.com/rspec/rspec-core/compare/v3.4.1...master)
3+
4+
Bug Fixes:
5+
6+
* Fix `rspec --profile` when an example calls `abort` or `exit`.
7+
(Bradley Schaefer, #2144)
8+
19
### 3.4.1 / 2015-11-18
210
[Full Changelog](http://github.com/rspec/rspec-core/compare/v3.4.0...v3.4.1)
311

lib/rspec/core/example.rb

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module Core
99
#
1010
# This allows us to provide rich metadata about each individual
1111
# example without adding tons of methods directly to the ExampleGroup
12-
# that users may inadvertantly redefine.
12+
# that users may inadvertently redefine.
1313
#
1414
# Useful for configuring logging and/or taking some action based
1515
# on the state of an example's metadata.
@@ -260,6 +260,7 @@ def run(example_group_instance, reporter)
260260

261261
finish(reporter)
262262
ensure
263+
execution_result.ensure_timing_set(clock)
263264
RSpec.current_example = nil
264265
end
265266

@@ -565,13 +566,23 @@ def example_skipped?
565566
# @api private
566567
# Records the finished status of the example.
567568
def record_finished(status, finished_at)
568-
self.status = status
569-
self.finished_at = finished_at
570-
self.run_time = (finished_at - started_at).to_f
569+
self.status = status
570+
calculate_run_time(finished_at)
571+
end
572+
573+
# @api private
574+
# Populates finished_at and run_time if it has not yet been set
575+
def ensure_timing_set(clock)
576+
calculate_run_time(clock.now) unless finished_at
571577
end
572578

573579
private
574580

581+
def calculate_run_time(finished_at)
582+
self.finished_at = finished_at
583+
self.run_time = (finished_at - started_at).to_f
584+
end
585+
575586
# For backwards compatibility we present `status` as a string
576587
# when presenting the legacy hash interface.
577588
def hash_for_delegation

spec/rspec/core/example_spec.rb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,18 @@ def metadata_hash(*args)
5858
end
5959
end
6060

61+
it "captures example timing even for exceptions unhandled by RSpec" do
62+
unhandled = RSpec::Support::AllExceptionsExceptOnesWeMustNotRescue::AVOID_RESCUING.first
63+
example = example_group.example { raise unhandled }
64+
65+
begin
66+
example_group.run
67+
rescue unhandled
68+
# no-op, prevent from bubbling up
69+
end
70+
expect(example.execution_result.finished_at).not_to be_nil
71+
end
72+
6173
describe "#exception" do
6274
it "supplies the exception raised, if there is one" do
6375
example = example_group.example { raise "first" }
@@ -784,7 +796,7 @@ def expect_pending_result(example)
784796
end
785797

786798
describe "exposing the examples reporter" do
787-
it "returns a null reporter when the example hasnt run yet" do
799+
it "returns a null reporter when the example has not run yet" do
788800
example = RSpec.describe.example
789801
expect(example.reporter).to be RSpec::Core::NullReporter
790802
end

0 commit comments

Comments
 (0)