Sha256: a018406f0532bd45b9fb815521e5d412aa4cc4bcfe7537e4f1e56639fd7e1f31

Contents?: true

Size: 1.68 KB

Versions: 5

Compression:

Stored size: 1.68 KB

Contents

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

describe Currency::ExchangeBank do
  before :each do
    @bank = Currency::ExchangeBank.new
  end
  
  it "returns the previously specified conversion rate" do
    @bank.add_rate("USD", "EUR", 0.788332676)
    @bank.add_rate("EUR", "YEN", 122.631477)
    @bank.get_rate("USD", "EUR").should == 0.788332676
    @bank.get_rate("EUR", "YEN").should == 122.631477
  end
  
  it "treats currency names case-insensitively" do
    @bank.add_rate("usd", "eur", 1)
    @bank.get_rate("USD", "EUR").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", "EUR").should be_nil
  end
  
  it "exchanges money from one currency to another according to the specified conversion rates" do
    @bank.add_rate("USD", "EUR", 0.5)
    @bank.add_rate("EUR", "YEN", 10)
    @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", "EUR", 0.788332676)
    @bank.add_rate("EUR", "YEN", 122.631477)
    @bank.exchange(10_00, "USD", "EUR").should == 788
    @bank.exchange(500_00, "EUR", "YEN").should == 6131573
  end
  
  it "should lookup exchange rate if one isn't set" do
    block = lambda { @bank.exchange(10, "USD", "EUR") }
    block.should_not raise_error
  end
  
  it "raises Money::UnknownRate upon conversion if the conversion rate is unknown" do
    block = lambda { @bank.exchange(10, "USD", "BUTTON") }
    block.should raise_error(Money::UnknownRate)
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
currencies-0.3.0 spec/exchange_bank_spec.rb
currencies-0.2.1 spec/exchange_bank_spec.rb
currencies-0.2.0 spec/exchange_bank_spec.rb
currencies-0.1.1 spec/exchange_bank_spec.rb
currencies-0.1.0 spec/exchange_bank_spec.rb