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

Unhandled SystemExit causes susbequent tests to silently not run. #2246

Closed
@marcparadise

Description

@marcparadise

This appears related to the change for #2063.

When testing components that might be expected to call Kernel.exit in the normal course of operations, a SystemExit is raised. The policy of not rescuing SystemExit in this case means any tests that were supposed to run after that point will not run -- and will not report a failure. The only indication is that the number of tests executed is lower than it should be.

In automated test runs, this is almost impossible to catch - and even in local runs when the difference is a matter of just a handful of tests not being run, it's easy to miss.

Simple repro:

describe "a scenario that should run two tests and fail one" do 
  it "should report this as failed and  keep running" do 
    Kernel.exit 1 
  end 
  it "does not do either, and I see a succesful exit with one test passed" do
  end 
end

Result:

rspec test_spec.rb

Finished in 0.00039 seconds (files took 0.06405 seconds to load)
1 example, 0 failures

The easy answer is to also handle SystemExit, but that would re-introduce #2063. That led me to consider submitting a patch where a SystemExit handling option could be specified via configuration., and handled similarly to:

 rescue Support::AllExceptionsExceptOnesWeMustNotRescue => ex
...
rescue Support::AnyExceptionWeMustNotRescue  => ex
   raise unless RSpec.configuration.allow_exceptions.include?(ex.class) 

Another option would be a final check of number of executed tests against the number we expected to execute, failing on a mismatch. This may not catch scenarios related to nested runs though.

Before submitting a patch, I wanted to open this issue for feedback and discussion of best approach.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions