Closed fernandomm closed 9 years ago
Depends on which of the in
you want to stub:
If you want to stub the in in 1.in(:eur)
, the way to go is to stub new
on Exchange::Money
:
my_money = Exchange::Money.new(1.20, :eur) #put this in a let!: let!(:my_money) { ... }
allow(Exchange::Money).to receive(:new).and_return my_money
if you want to stub a conversion (e.g. 1.in(:eur).to(:usd)
) you could stub any instance like you did before.
If that doesn't work, I'd have to know a little bit more about your test setup.
Is there a way to stub the to/in methods when using rspec?
I tried something like:
But it keeps using the original methods.
Example: when i pass an invalid currency I still get an Exchange::NoCurrencyError exception.