Sha256: b08e5fd31b4a2fbe3326d49efa42836228a0e83e4b2f3f1751fc2c05c8641e38

Contents?: true

Size: 1.5 KB

Versions: 3

Compression:

Stored size: 1.5 KB

Contents

require File.dirname(__FILE__) + '/../spec_helper.rb'

describe Money::VariableExchangeBank do
  before :each do
    @bank = Money::VariableExchangeBank.new
  end

  it "returns the previously specified conversion rate" do
    @bank.add_rate("USD", 0.788332676)
    @bank.add_rate("EUR", 122.631477)
    @bank.get_rate("USD").should == 0.788332676
    @bank.get_rate("EUR").should == 122.631477
  end

  it "treats currency names case-insensitively" do
    @bank.add_rate("usd", 1)
    @bank.get_rate("USD").should == 1
    @bank.same_currency?("USD", "usd").should be_true
    @bank.same_currency?("EUR", "usd").should be_false
  end

  it "returns nil if the conversion rate is unknown" do
    @bank.get_rate("American Pesos").should be_nil
  end

  it "exchanges money from one currency to another according to the specified conversion rates" do
    @bank.add_rate("USD", 1.0)
    @bank.add_rate("EUR", 0.5)
    @bank.add_rate("YEN", 5)
    @bank.exchange(10_00, "USD", "EUR").should == 5_00
    @bank.exchange(500_00, "EUR", "YEN").should == 5000_00
  end

  it "rounds the exchanged result down" do
    @bank.add_rate("USD", 1.0)
    @bank.add_rate("EUR", 0.788332676)
    @bank.add_rate("YEN", 122.631477)
    @bank.exchange(10_00, "USD", "EUR").should == 788
    @bank.exchange(500_00, "EUR", "YEN").should == 7777901
  end

  it "raises Money::UnknownRate upon conversion if the conversion rate is unknown" do
    block = lambda { @bank.exchange(10, "USD", "ABC") }
    block.should raise_error(Money::UnknownRate)
  end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
ShadowBelmolve-money-2.3.3 spec/money/exchange_bank_spec.rb
ShadowBelmolve-money-2.3.4 spec/money/exchange_bank_spec.rb
samlown-money-2.3.3.2 spec/money/exchange_bank_spec.rb