spec/danconia/exchanges/exchange_spec.rb in danconia-0.2.9 vs spec/danconia/exchanges/exchange_spec.rb in danconia-0.3.0

- old
+ new

@@ -1,7 +1,5 @@ -require 'spec_helper' - module Danconia module Exchanges describe Exchange do context 'rate' do it 'returns the exchange rate value for the supplied currencies' do @@ -28,10 +26,24 @@ expect(exchange.rate('BRL', 'ARS')).to eq 1.5 expect(exchange.rate('EUR', 'BRL')).to eq 3 / 1.5 end it 'raises an error if the conversion cannot be made' do - expect { subject.rate('USD', 'EUR') }.to raise_error Errors::ExchangeRateNotFound + expect { fake_exchange({}).rate('USD', 'EUR') }.to raise_error Errors::ExchangeRateNotFound + end + + it 'should allow to pass options to filter the rates' do + exchange = Class.new(Exchange) do + def rates type: + case type + when 'divisa' then {'USDARS' => 7} + when 'billete' then {'USDARS' => 8} + end + end + end.new + + expect(exchange.rate('USD', 'ARS', type: 'divisa')).to eq 7 + expect(exchange.rate('USD', 'ARS', type: 'billete')).to eq 8 end def fake_exchange(rates) FixedRates.new(rates: rates) end