Class: BlueShell::Matchers::ExitCodeMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/blue-shell/matchers/exit_code_matcher.rb

Instance Method Summary collapse

Constructor Details

#initialize(expected_code) ⇒ ExitCodeMatcher

Returns a new instance of ExitCodeMatcher.



4
5
6
# File 'lib/blue-shell/matchers/exit_code_matcher.rb', line 4

def initialize(expected_code)
  @expected_code = expected_code
end

Instance Method Details

#failure_messageObject



23
24
25
26
27
28
29
# 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) ⇒ Boolean

Returns:

  • (Boolean)

Raises:



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# 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_messageObject



31
32
33
34
35
36
37
# 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