I'm writing tests which need to test the rescues in my code.
Model code:
rescue Coinbase::Error => e
#debugger
if e == "You don't have that many bitcoins in your account to sell."
...
end
Rspec code:
allow_any_instance_of(Order).to receive(:sell).and_raise(Coinbase::Error, "You don't have that many bitcoins in your account to sell.")
Adding the debugger where I did and looking at the value of e
in console, I see
#<Coinbase::UnauthorizedError: Coinbase::UnauthorizedError>
So the message isn't being passed in.
I've been googling for this for the last 40 minutes and everything I've found only covers sending the error class in, not the message. Presumably there are situations where there are the same error class but different messages.
Any suggestions would be great. Thanks!
I think you want to do:
Coinbase::Error.new("You don't have that many bitcoins in your account to sell.")
inside the raise call.Update, I think you also want
e.message == ""
note == ""
because you are comparing an error to a string not an error message.