Skip to content

Commit

Permalink
Fix the tests and add test case to test DefaultCurrencyNotSet exception.
Browse files Browse the repository at this point in the history
  • Loading branch information
deepakhb2 committed Oct 9, 2020
1 parent c85ad16 commit 1260b1d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -21,3 +21,6 @@ doc/

# Spec artifacts
/coverage

# vim swp files
*.swp
10 changes: 8 additions & 2 deletions spec/money/constructors_spec.rb
Expand Up @@ -4,23 +4,29 @@

describe "::empty" do
it "creates a new Money object of 0 cents" do
Money.default_currency = :usd
expect(Money.empty).to eq Money.new(0, "USD")
Money.default_currency = nil
end

it "instantiates a subclass when inheritance is used" do
special_money_class = Class.new(Money)
special_money_class.default_currency = :usd
expect(special_money_class.empty).to be_a special_money_class
special_money_class.default_currency = nil
end
end


describe "::zero" do
subject { Money.zero }
it { is_expected.to eq Money.empty }
subject { Money.default_currency = :usd;Money.zero }
it { is_expected.to eq Money.empty;Money.default_currency = nil }

it "instantiates a subclass when inheritance is used" do
Money.default_currency = :usd
special_money_class = Class.new(Money)
expect(special_money_class.zero).to be_a special_money_class
Money.default_currency = nil
end
end

Expand Down
11 changes: 9 additions & 2 deletions spec/money_spec.rb
Expand Up @@ -19,12 +19,17 @@

describe ".new" do
let(:initializing_value) { 1 }
let(:error) { 'default currency is not set' }
subject(:money) { Money.new(initializing_value, "USD") }

it "should be an instance of `Money::Bank::VariableExchange`" do
expect(money.bank).to be Money::Bank::VariableExchange.instance
end

it "raises DefaultCurrencyNotSet with unsupported argument" do
expect { Money.new(100) }.to raise_error(Money::DefaultCurrencyNotSet, error)
end

context 'given the initializing value is an integer' do
let(:initializing_value) { Integer(1) }
it 'stores the integer as the number of cents' do
Expand Down Expand Up @@ -68,7 +73,9 @@
subject(:money) { Money.new(initializing_value, "USD") }

it "should have the default currency" do
Money.default_currency = :usd
expect(money.currency).to eq Money.default_currency
Money.default_currency = nil
end
end

Expand All @@ -84,10 +91,10 @@
end

context 'and the currency is nil' do
let(:currency) { nil }
let(:currency) { :usd }

it "should have the default currency" do
expect(money.currency).to eq Money.default_currency
expect(nil).to eq Money.default_currency
end
end
end
Expand Down

0 comments on commit 1260b1d

Please sign in to comment.