Class: Wukong::SpecHelpers::ExitCodeMatcher
- Inherits:
-
IntegrationTestMatcher
- Object
- IntegrationTestMatcher
- Wukong::SpecHelpers::ExitCodeMatcher
- Defined in:
- lib/wukong/spec_helpers/integration_tests/integration_test_matchers.rb
Overview
A matcher for the exit code of a command.
Instance Attribute Summary
Attributes inherited from IntegrationTestMatcher
#expectations, #failed_expectation, #runner
Instance Method Summary collapse
-
#description ⇒ Object
:nodoc:.
-
#expected_exit_code ⇒ Object
:nodoc:.
-
#expected_exit_code_description ⇒ Object
:nodoc:.
-
#failure_message ⇒ Object
:nodoc:.
-
#initialize(code) ⇒ ExitCodeMatcher
constructor
Initialize this matcher with the given
code
. -
#matches?(runner) ⇒ true, false
Return whether or not the given command's exit code matches the expectation.
-
#negative_failure_message ⇒ Object
:nodoc:.
-
#non_zero_exit_code? ⇒ Boolean
:nodoc:.
-
#output_description ⇒ Object
:nodoc:.
Methods inherited from IntegrationTestMatcher
#formatted_command, #formatted_env, #formatted_error_output, #formatted_output, #match_function, #match_type
Constructor Details
#initialize(code) ⇒ ExitCodeMatcher
Initialize this matcher with the given code
.
If code
is the symbol :non_zero then the
expectation will be any non-zero exit code.
143 144 145 146 147 148 149 |
# File 'lib/wukong/spec_helpers/integration_tests/integration_test_matchers.rb', line 143 def initialize code if code == :non_zero @expected_code = :non_zero else @expected_code = code.to_i end end |
Instance Method Details
#description ⇒ Object
:nodoc:
197 198 199 |
# File 'lib/wukong/spec_helpers/integration_tests/integration_test_matchers.rb', line 197 def description "exit with #{expected_exit_code_description}" end |
#expected_exit_code ⇒ Object
:nodoc:
183 184 185 |
# File 'lib/wukong/spec_helpers/integration_tests/integration_test_matchers.rb', line 183 def expected_exit_code (@expected_code || 0).to_i end |
#expected_exit_code_description ⇒ Object
:nodoc:
188 189 190 191 192 193 194 |
# File 'lib/wukong/spec_helpers/integration_tests/integration_test_matchers.rb', line 188 def expected_exit_code_description if non_zero_exit_code? "a non-zero exit code" else "an exit code of #{expected_exit_code}" end end |
#failure_message ⇒ Object
:nodoc:
168 169 170 |
# File 'lib/wukong/spec_helpers/integration_tests/integration_test_matchers.rb', line 168 def "From within #{runner.cwd} ran\n\n#{formatted_env}\n#{formatted_command}\n\nexpecting #{expected_exit_code_description} Got #{runner.exit_code} instead.#{formatted_error_output}" end |
#matches?(runner) ⇒ true, false
Return whether or not the given command's exit code matches the expectation.
156 157 158 159 160 161 162 163 164 165 |
# File 'lib/wukong/spec_helpers/integration_tests/integration_test_matchers.rb', line 156 def matches?(runner) self.runner = runner runner.run! if non_zero_exit_code? @failed = true if runner.exit_code == 0 else @failed = true if runner.exit_code != expected_exit_code end @failed ? false : true end |
#negative_failure_message ⇒ Object
:nodoc:
173 174 175 |
# File 'lib/wukong/spec_helpers/integration_tests/integration_test_matchers.rb', line 173 def "From within #{runner.cwd} ran\n\n#{formatted_env}\n#{formatted_command}\n\nNOT expecting #{expected_exit_code_description}.#{formatted_error_output}" end |
#non_zero_exit_code? ⇒ Boolean
:nodoc:
178 179 180 |
# File 'lib/wukong/spec_helpers/integration_tests/integration_test_matchers.rb', line 178 def non_zero_exit_code? @expected_code == :non_zero end |
#output_description ⇒ Object
:nodoc:
202 203 204 |
# File 'lib/wukong/spec_helpers/integration_tests/integration_test_matchers.rb', line 202 def output_description "STDOUT" end |