Open dehengxu opened 10 years ago
Would exit
or abort
solve your problem?
See: http://www.ruby-doc.org/core-2.1.4/Kernel.html#method-i-exit
Sorry to comment on an old issue, but my problem is very similar.
exit or abort would work, except when testing Thor. If exit
is used, the tests will be interrupted and not finish. I'd like to propose a better solution, which is to evaluate the return value of the command and if it's falsey, exit with a status code of 1. That way, in the tests, if we're expecting a non-zero exit code, we can check for false.
I've also been running into this problem. I have a thor CLI that runs multiple processes via popen3
and I'd like to return a non-zero status code when any of those processes fail.
@dkniffin I actually figured out how to do it with exit
. exit
raises a SystemExit
error so I just catch that in my tests. i.e.
expect {
thor \
"spec", \
"spec/thor/fixtures/pass_1_spec_fixture.rb", \
"spec/thor/fixtures/fail_spec_fixture.rb"
}.to raise_error SystemExit
Ah, interesting. I'll check that out.
I use thor as command line tools in jenkins, but the command failed and jenkins cannot receive this error .