I am writing a small ruby script that will be accepting input from
postfix’s pipe command (ie, not running via the shell, directly
One of the things I need to do it spec the exit codes to make sure I
am returing the correct exit codes for each condition as Postfix will
then return SMTP errors as appropriate.
I have two files that concern this bit of the program, init.rb and
init.rb right now looks like this:
init_spec.rb looks like this:
describe Init do
it “should exit on status code 1 without parameters”
command = “ruby mail_dump/init.rb” # not portable
status, stdout, stderr = systemu command
status.should == # what do I put here?
I have tried a number of things, from trying to stub exit to aliasing
kernel.exit to something else and replacing it… all without joy.
The spec runs and hits the “exit 1” in init.rb and does what it is
mean to do… exit. But that also exits RSpec and so the test is
The only thing I found DID work is if I alias Kernel.exit inside the
init.rb file to “real_exit” and then redefine Kernel exit like so:
alias real_exit exit
return true if arg == 1
and then test exit by mocking it and making sure it returns true…
but a spec that has to modify the test code isn’t going to scale too
well… and this doesn’t seem right.
Has anyone else had this problem? How did you solve it?