class BlueShell::Matchers::ExitCodeMatcher

Public Class Methods

new(expected_code) click to toggle source
# File lib/blue-shell/matchers/exit_code_matcher.rb, line 4
def initialize(expected_code)
  @expected_code = expected_code
end

Public Instance Methods

failure_message() click to toggle source
# File lib/blue-shell/matchers/exit_code_matcher.rb, line 23
def failure_message
  if @timed_out
    "expected process to exit with status #@expected_code, but it did not exit within 5 seconds"
  else
    "expected process to exit with status #{@expected_code}, but it exited with status #{@actual_code}"
  end
end
matches?(runner) click to toggle source
# File lib/blue-shell/matchers/exit_code_matcher.rb, line 8
def matches?(runner)
  raise Errors::InvalidInputError unless runner.respond_to?(:exit_code)

  begin
    Timeout.timeout(BlueShell.timeout) do
      @actual_code = runner.exit_code
    end

    @actual_code == @expected_code
  rescue Timeout::Error
    @timed_out = true
    false
  end
end
negative_failure_message() click to toggle source
# File lib/blue-shell/matchers/exit_code_matcher.rb, line 31
def negative_failure_message
  if @timed_out
    "expected process to exit with status #@expected_code, but it did not exit within 5 seconds"
  else
    "expected process to not exit with status #{@expected_code}, but it did"
  end
end