Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
require "rspec/exit_matchers/version"
# expect { exit(1) }.to exit_with_status(1)
module RSpec
module ExitMatchers
class ExitWithStatus
def initialize(expected_status)
@expected_status = expected_status
end
def matches?(actual)
begin
actual.call
rescue SystemExit => e
@exit_status = e.status
end
@exit_status && @expected_status == @exit_status
end
def failure_message
"expected block to exit with status #{@expected_status}, but it did not"
end
def supports_block_expectations?
true
end
end
def exit_with_status(expected_status)
ExitWithStatus.new expected_status
end
end
end
RSpec::configure do |config|
config.include(Rspec::ExitMatchers)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.