问题
I have a method that will sometimes call exit(numeric_value)
.
Is it possible for rspec to validate that when the method is invoked, the process is exiting with the correct value?
I have seen these other posts, but they do not answer this specific question.
- How can I validate exits and aborts in RSpec?
- How to spec methods that exit or abort
回答1:
Given sample ruby code:
def it_will_exit
puts "before exit"
exit(false)
puts "never get here"
end
rspec test case can be:
it "it must exit" do
expect { it_will_exit }.raise_exception(SystemExit)
end
it "the exit value should be false" do
begin
it_will_exit
rescue SystemExit=>e
expect(e.status).to eq(1)
end
end
来源:https://stackoverflow.com/questions/20432358/how-can-i-validate-exit-value-in-rspec