From 5ece56c134f8c45c67308c55a78cf03d7d5abfe8 Mon Sep 17 00:00:00 2001 From: Martin Mauch Date: Tue, 27 Sep 2011 14:44:09 +0200 Subject: [PATCH] Add test and fix for github issue #41 --- features/rspec_fails_on_initialization.feature | 14 ++++++++++++++ lib/simplecov/defaults.rb | 8 ++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 features/rspec_fails_on_initialization.feature diff --git a/features/rspec_fails_on_initialization.feature b/features/rspec_fails_on_initialization.feature new file mode 100644 index 00000000..1ed8cdfd --- /dev/null +++ b/features/rspec_fails_on_initialization.feature @@ -0,0 +1,14 @@ +@rspec +Feature: + + Running specs with a failing rspec setup + + Scenario: Fail if rspec fails before starting its tests + Given a file named "spec/spec_helper.rb" with: + """ + require 'simplecov' + SimpleCov.start + raise "some exception in the class loading before the tests start" + """ + When I run `bundle exec rspec spec` + Then the exit status should not be 0 diff --git a/lib/simplecov/defaults.rb b/lib/simplecov/defaults.rb index 61f2d256..c64dc1cf 100644 --- a/lib/simplecov/defaults.rb +++ b/lib/simplecov/defaults.rb @@ -36,10 +36,14 @@ # Exclude files outside of SimpleCov.root load_adapter 'root_filter' end - at_exit do # Store the exit status of the test run since it goes away after calling the at_exit proc... - @exit_status = $!.status if $!.is_a?(SystemExit) + if $! #was an exception thrown? + #if it was a SystemExit, use the accompanying status + #otherwise set a non-zero status representing termination by some other exception + #(see github issue 41) + @exit_status = $!.is_a?(SystemExit) ? $!.status : 1 + end SimpleCov.at_exit.call exit @exit_status if @exit_status # Force exit with stored status (see github issue #5) end