Is there a way to set the value of $? in a mock in Ruby?
- by rleber
I am testing some scripts that interface with system commands. Their logic depends on the return code of the system commands, i.e. the value of $?. So, as a simplified example, the script might say:
def foo(command)
output=`#{command}`
if $?==0
'succeeded'
else
'failed'
end
end
In order to be able to test these methods properly,…