RSpec, as of v3.0, no longer uses at_exit (unless you require rspec/autorun—but that’s not necessary if you’re using the rspec command), so I’m not surprised the monkey patch to at_exit doesn’t work to fix your problem.
RSpec sets the exit code here:
https://github.com/rspec/rspec-core/blob/v3.6.0/lib/rspec/core/runner.rb#L45-L46
You can try adding some puts statements to your local copy of the RSpec source to debug it (bundle show rspec-core should show you where it’s installed). My guess is that you have some code either in your project or in a dependency that also calls exit or exit!, or that calls at_exit and interferes with the exit code in some fashion. If you don’t find any code doing this, my suggestion is to apply a binary search technique to your codebase. Define a simple, small spec file that always fails like:
require 'spec_helper' # not needed if you have `--require spec_helper` in `.rspec`
RSpec.describe "Failure" do
it "fails" do
expect(1).to eq 2
end
end
Run just that spec file and see what the exit code is. If it’s zero, it means it’s something loaded by spec_helper that’s interfering. Comment out half of spec_helper and repeat until you identify it. If it was non-zero, it means it’s something being loaded by your other spec files (or in one of the spec files) causing it. Try systematically loading (or deleting, assuming you are using source control) different halves of your spec files to see if you can identify where the issue is.
Please let us know if you find the issue, as it can help others in the future!
Myron
--
You received this message because you are subscribed to the Google Groups "rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rspec+unsubscribe@googlegroups.com.
To post to this group, send email to rs...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rspec/d196d5bf-b887-4625-a23e-58b7409cbfe9%40googlegroups.com.