Skip to content

Instantly share code, notes, and snippets.

@myronmarston
Last active August 29, 2015 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save myronmarston/9ff026166f30a55ba46c to your computer and use it in GitHub Desktop.
Save myronmarston/9ff026166f30a55ba46c to your computer and use it in GitHub Desktop.

Demonstration of why RSpec does not exit with a status of 0 when all specs pass. (For rspec/rspec-core#1918)

Normally, we get a non-zero exit status from SimpleCov due to our min coverage being too low:

➜  bundle exec ruby use_rspec_and_simplecov.rb; echo $?
Coverage report generated for RSpec to /Users/myron/code/rspec-scratch/rspec-exit-0-behavior/coverage. 2 / 3 LOC (66.67%) covered.
Coverage (66.67%) is below the expected minimum coverage (100.00%).
.

Finished in 0.00046 seconds (files took 0.1162 seconds to load)
1 example, 0 failures

2

However, if we activate our monkey patch that forces RSpec to always exit, we get an exit code of 0.

➜  MAKE_RSPEC_ALWAYS_EXIT=1 bundle exec ruby use_rspec_and_simplecov.rb; echo $?
Coverage report generated for RSpec to /Users/myron/code/rspec-scratch/rspec-exit-0-behavior/coverage. 2 / 3 LOC (66.67%) covered.
Coverage (66.67%) is below the expected minimum coverage (100.00%).
.

Finished in 0.00043 seconds (files took 0.10172 seconds to load)
1 example, 0 failures

0
class Foo
def do_stuff
3 + 4 # uncovered
end
end
# A sample Gemfile
source "https://rubygems.org"
gem 'rspec'
gem 'simplecov'
GEM
remote: https://rubygems.org/
specs:
diff-lcs (1.2.5)
docile (1.1.5)
multi_json (1.11.0)
rspec (3.2.0)
rspec-core (~> 3.2.0)
rspec-expectations (~> 3.2.0)
rspec-mocks (~> 3.2.0)
rspec-core (3.2.2)
rspec-support (~> 3.2.0)
rspec-expectations (3.2.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.2.0)
rspec-mocks (3.2.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.2.0)
rspec-support (3.2.2)
simplecov (0.9.2)
docile (~> 1.1.0)
multi_json (~> 1.0)
simplecov-html (~> 0.9.0)
simplecov-html (0.9.0)
PLATFORMS
ruby
DEPENDENCIES
rspec
simplecov
require 'rspec/autorun'
if ENV['MAKE_RSPEC_ALWAYS_EXIT']
def (RSpec::Core::Runner).invoke
disable_autorun!
status = run(ARGV, $stderr, $stdout).to_i
exit(status)
end
end
require 'simplecov'
SimpleCov.start do
minimum_coverage 100
end
require_relative 'foo'
RSpec.describe "Some group" do
example { }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment