I am trying to spec behaviors for command line arguments my script receives to ensure that all validation passes. Some of my command line arguments will result in abort
or exit
being invoked because the parameters supplied are missing or incorrect.
I am trying something like this which isn't working:
# something_spec.rb
require 'something'
describe Something do
before do
Kernel.stub!(:exit)
end
it "should exit cleanly when -h is used" do
s = Something.new
Kernel.should_receive(:exit)
s.process_arguments(["-h"])
end
end
The exit
method is firing cleanly preventing RSpec from validating the test (I get "SystemExit: exit").
I have also tried to mock(Kernel)
but that too is not working as I'd like (I don't see any discernible difference, but that's likely because I'm not sure how exactly to mock Kernel and make sure the mocked Kernel is used in my Something
class).