Sha256: f138d7ea00806b2472d3b4253fe2e00c88a54e09b0121f9bf48ef822277cda63

Contents?: true

Size: 708 Bytes

Versions: 3

Compression:

Stored size: 708 Bytes

Contents

# See: How can I validate exits and aborts in RSpec?
# http://stackoverflow.com/questions/1480537

module ExitCodeMatchers
  RSpec::Matchers.define :exit_with_code do |code|
    actual = nil
    match do |block|
      begin
        block.call
      rescue SystemExit => e
        actual = e.status
      end
      actual and actual == code
    end
    failure_message_for_should do |block|
      "expected block to call exit(#{code}) but exit" +
        (actual.nil? ? " not called" : "(#{actual}) was called")
    end
    failure_message_for_should_not do |block|
      "expected block not to call exit(#{code})"
    end
    description do
      "expect block to call exit(#{code})"
    end    
  end  
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
scaffolder-tools-0.1.2 spec/support/exit_code_matcher.rb
scaffolder-tools-0.1.1 spec/support/exit_code_matcher.rb
scaffolder-tools-0.1.0 spec/support/exit_code_matcher.rb