Skip to content

Commit

Permalink
Add spec for raising errors
Browse files Browse the repository at this point in the history
  • Loading branch information
sparrovv committed Nov 9, 2011
1 parent b348877 commit 8d57733
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/nbp_exchange/currency.rb
Expand Up @@ -18,7 +18,7 @@ def initialize(symbol)
end

def name
@name ||= CurrencieNames[symbol]
@name ||= SymbolsNames[symbol]
end

def rate(date)
Expand Down
20 changes: 16 additions & 4 deletions spec/nbp_exchange/currency_spec.rb
Expand Up @@ -12,11 +12,23 @@ module NbpExchange
end

describe "#rate" do
let(:expected){Rate.new(currency, EXCHANGE_DATE, 4.4146)}
context "When rate exists" do
let(:expected){Rate.new(currency, EXCHANGE_DATE, 4.4146)}

it "should return average rate for given date" do
r = currency.rate(EXCHANGE_DATE)
r.average_exchange_rate.should == expected.average_exchange_rate
end
end

context "when rate doesn't exists for this date" do

it "should raise error" do
lambda {
r = currency.rate("2001-01-01")
}.should raise_error(NbpExchange::NoXMLForThisDate)
end

it "should return average rate for given date" do
r = currency.rate(EXCHANGE_DATE)
r.average_exchange_rate.should == expected.average_exchange_rate
end
end
end
Expand Down

0 comments on commit 8d57733

Please sign in to comment.