Sha256: 1b8a30ef23d5d06ea3f182c550b418352968e299d1f2b5b58f3009139b3db0e3

Contents?: true

Size: 1.33 KB

Versions: 6

Compression:

Stored size: 1.33 KB

Contents

require 'spec_helper'

describe "Exchange::ExternalAPI::Base" do
  subject { Exchange::ExternalAPI::Base.new }
  before(:all) do
    Exchange.configuration = Exchange::Configuration.new{|c|
      c.cache = {:subclass => :no_cache}
    }
  end
  after(:all) do
    Exchange.configuration.reset
  end
  before(:each) do
    subject.instance_variable_set("@rates", {:eur => BigDecimal.new("3.45"), :chf => BigDecimal.new("5.565")})
    subject.instance_variable_set("@base", :usd)
  end
  describe "rate" do
    it "should put out an exchange rate for the two currencies" do
      subject.should_receive(:update).once
      subject.rate(:eur, :chf).round(3).should == 1.613
    end
    it "should put out an exchange rate for the two currencies and pass on opts" do
      time = Time.now
      subject.should_receive(:update).with(:at => time).once
      subject.rate(:eur, :chf, :at => time).round(3).should == 1.613
    end
  end
  describe "convert" do
    it "should convert according to the given rates" do
      subject.should_receive(:update).once
      subject.convert(80,:chf, :eur).round(2).should == 49.6
    end
    it "should convert according to the given rates and pass opts" do
      time = Time.now
      subject.should_receive(:update).with(:at => time).once
      subject.convert(80,:chf, :eur, :at => time).round(2).should == 49.6
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
exchange-0.12.0 spec/exchange/external_api/base_spec.rb
exchange-0.11.0 spec/exchange/external_api/base_spec.rb
exchange-0.10.2 spec/exchange/external_api/base_spec.rb
exchange-0.10.1 spec/exchange/external_api/base_spec.rb
exchange-0.10.0 spec/exchange/external_api/base_spec.rb
exchange-0.9.0 spec/exchange/external_api/base_spec.rb