Skip to content

Instantly share code, notes, and snippets.

@myronmarston
Created July 14, 2014 19:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save myronmarston/6b8116224e7ec0b00650 to your computer and use it in GitHub Desktop.
Save myronmarston/6b8116224e7ec0b00650 to your computer and use it in GitHub Desktop.
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