Class: BlueShell::Matchers::ExitCodeMatcher
- Inherits:
-
Object
- Object
- BlueShell::Matchers::ExitCodeMatcher
- Defined in:
- lib/blue-shell/matchers/exit_code_matcher.rb
Instance Method Summary collapse
- #failure_message ⇒ Object
-
#initialize(expected_code) ⇒ ExitCodeMatcher
constructor
A new instance of ExitCodeMatcher.
- #matches?(runner) ⇒ Boolean
- #negative_failure_message ⇒ Object
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_message ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/blue-shell/matchers/exit_code_matcher.rb', line 23 def 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
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_message ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/blue-shell/matchers/exit_code_matcher.rb', line 31 def 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 |