diff options
Diffstat (limited to 'spec')
| -rwxr-xr-x | spec/spec_helper.rb | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 01ffabc48..1dcf3c2d4 100755 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -80,3 +80,25 @@ RSpec::Matchers.define :have_matching_element do |expected| actual.any? { |item| item =~ expected } end end + +RSpec::Matchers.define :exit_with do |expected| + actual = nil + match do |block| + begin + block.call + rescue SystemExit => e + actual = e.status + end + actual and actual == expected + end + failure_message_for_should do |block| + "expected exit with code #{expected} but " + + (actual.nil? ? " exit was not called" : "we exited with #{actual} instead") + end + failure_message_for_should_not do |block| + "expected that exit would not be called with #{expected}" + end + description do + "expect exit with #{expected}" + end +end |
