Created
July 14, 2014 19:59
-
-
Save myronmarston/6b8116224e7ec0b00650 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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