Sha256: 4c2c4735e276c3d5c1afd618b790bf9324de6c629b239146608d599eead1eafd
Contents?: true
Size: 1.54 KB
Versions: 1
Compression:
Stored size: 1.54 KB
Contents
require 'spec_helper' module Danconia module Exchanges describe Exchange do context 'rate' do it 'returns the exchange rate value for the supplied currencies' do exchange = fake_exchange('USDEUR' => 3, 'USDARS' => 4) expect(exchange.rate('USD', 'EUR')).to eq 3 expect(exchange.rate('USD', 'ARS')).to eq 4 end it 'if the direct conversion is not found, tries to find the inverse' do exchange = fake_exchange('USDEUR' => 3) expect(exchange.rate('EUR', 'USD')).to be_within(0.00001).of(1.0 / 3) end it 'if not direct nor inverse conversion is found, tries to convert through USD' do exchange = fake_exchange('USDEUR' => 3, 'USDARS' => 6) expect(exchange.rate('EUR', 'ARS')).to be_within(0.00001).of 2 expect(exchange.rate('ARS', 'EUR')).to be_within(0.00001).of 0.5 end it 'pairs can have a different common currency' do exchange = fake_exchange('EURARS' => 3, 'BRLARS' => 1.5) expect(exchange.rate('EUR', 'ARS')).to eq 3 expect(exchange.rate('ARS', 'EUR')).to be_within(0.00001).of(1.0 / 3) 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 end def fake_exchange(rates) FixedRates.new(rates: rates) end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
danconia-0.2.9 | spec/danconia/exchanges/exchange_spec.rb |