Sha256: e15e2814076cf7840fc8ed6f3c5c739736e7d7f9187e64e57024b4207fe2ae97

Contents?: true

Size: 983 Bytes

Versions: 3

Compression:

Stored size: 983 Bytes

Contents

module ExitMatcher
  class ExitWithStatus
    attr_reader :expected
    attr_reader :actual
    
    def initialize(expected)
      @expected = expected
    end
    
    def matches?(given_proc)
      status = nil
      
      begin
        given_proc.call
      rescue SystemExit
        status = $!.status
      end
      
      @actual = status
      
      @actual == @expected
    end
    
    def failure_message_for_should
      if actual.nil?
        "expected block to exit with #{expected.inspect} status, but didn't exit"
      else
        "expected block to exit with #{expected.inspect} status, but did it with #{actual.inspect}"
      end
    end
    
    def failure_message_for_should_not
      "expected block to not exit with #{actual.inspect} status, but did it"
    end
    
    private
      def negative_expectation?
        caller.first(3).find { |s| s =~ /should_not/ }
      end
  end
  
  def exit_with(expected)
    ExitWithStatus.new(expected)
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
kitabu-0.4.7 spec/exit_matcher.rb
kitabu-0.4.6 spec/exit_matcher.rb
kitabu-0.4.5 spec/exit_matcher.rb