spec/money/money_spec.rb in nofxx-money-2.3.1 vs spec/money/money_spec.rb in nofxx-money-2.3.2
- old
+ new
@@ -1,23 +1,31 @@
# -*- coding: utf-8 -*-
require File.dirname(__FILE__) + '/../spec_helper.rb'
describe Money do
+
+ it { Money.new(10_00).to_f.should eql(10.0) }
+ it { Money.new(10_00).to_s.should eql("10.00") }
+
it "is associated to the singleton instance of VariableExchangeBank by default" do
Money.new(0).bank.object_id.should == Money::VariableExchangeBank.instance.object_id
end
it "should return the amount of cents passed to the constructor" do
Money.new(200_00, "USD").cents.should == 200_00
end
it "should rounds the given cents to an integer" do
- Money.new(1.00, "USD").cents.should == 1
+ Money.new(1.0, "USD").cents.should == 1
Money.new(1.01, "USD").cents.should == 1
- Money.new(1.50, "USD").cents.should == 2
end
+ it "should use the floor method" do
+ Money.new(1.50, "USD").cents.should == 1
+ Money.new(1.99, "USD").cents.should == 1
+ end
+
it "#currency returns the currency passed to the constructor" do
Money.new(200_00, "USD").currency.should == "USD"
end
it "#zero? returns whether the amount is 0" do
@@ -50,102 +58,109 @@
it "#* divides the money's amount by the divisor while retaining the currency" do
(Money.new(10_00, "USD") / 10).should == Money.new(1_00, "USD")
end
- it "# divides the money ammout in installments add last" do
- @money = Money.new(10_00).split_in_installments(3)
- @money[0].cents.should eql(334)
- @money[1].cents.should eql(333)
- @money[2].cents.should eql(333)
+ it "should create a new Money object of 0 cents if empty" do
+ Money.empty.should == Money.new(0)
end
- it "# divides the money ammout in installments add first" do
- @money = Money.new(10_00).split_in_installments(3,true)
- @money.to_s.should eql(["3.34", "3.33", "3.33"])
+ it "Money.ca_dollar creates a new Money object of the given value in CAD" do
+ Money.ca_dollar(50).should == Money.new(50, "CAD")
end
- it "# divides the money ammout in installments base on payment" do
- money = Money.new(3_00)
- Money.new(10_00).in_installments_of(money)[0].cents.should eql(334)
- Money.new(10_00).in_installments_of(money)[1].cents.should eql(333)
- Money.new(10_00).in_installments_of(money)[2].cents.should eql(333)
+ it "Money.us_dollar creates a new Money object of the given value in USD" do
+ Money.us_dollar(50).should == Money.new(50, "USD")
end
- it "shuld sum array" do
- Money.new(10_00).split_in_installments(3).sum.cents.should eql(1000)
+ it "Money.euro creates a new Money object of the given value in EUR" do
+ Money.euro(50).should == Money.new(50, "EUR")
end
- it "should calculate tax" do
- Money.new(100).add_tax(20).cents.should eql(120)
- Money.new(100).add_tax(-20).cents.should eql(80)
+ it "Money.real creates a new Money object of the given value in BRL" do
+ Money.real(50).should == Money.new(50, "BRL")
end
- it "should calculate compound tax" do
- @ma = Money.new(1000_00)
- @ma.compound_interest(12.99,12).to_s.should eql("137.92")
- end
- it "should calculate compound tax" do
- @ma = Money.new(1000_00)
- @ma.simple_interest(12.99,12).to_s.should eql("129.90")
- end
+ describe "Installments" do
- it "should calculate compound tax" do
- @ma = Money.new(2500_00)
- @ma.compound_interest(12.99,3).to_s.should eql("82.07")
- end
+ it "# divides the money ammout in installments add last" do
+ @money = Money.new(10_00).split_in_installments(3)
+ @money[0].cents.should eql(334)
+ @money[1].cents.should eql(333)
+ @money[2].cents.should eql(333)
+ end
- it "shuld sum array" do
- @money = Money.new(10_00).add_tax(10)
- @money.split_in_installments(3).sum.cents.should eql(1100)
- end
+ it "# divides the money ammout in installments add first" do
+ @money = Money.new(10_00).split_in_installments(3,true)
+ @money.to_s.should eql(["3.34", "3.33", "3.33"])
+ end
- it { Money.new(10_00).to_f.should eql(10.0) }
- it { Money.new(10_00).to_s.should eql("10.00") }
+ it "# divides the money ammout in installments base on payment" do
+ money = Money.new(3_00)
+ Money.new(10_00).in_installments_of(money)[0].cents.should eql(334)
+ Money.new(10_00).in_installments_of(money)[1].cents.should eql(333)
+ Money.new(10_00).in_installments_of(money)[2].cents.should eql(333)
+ end
+ it "shuld sum array" do
+ Money.new(10_00).split_in_installments(3).sum.cents.should eql(1000)
+ end
- it "should create a new Money object of 0 cents if empty" do
- Money.empty.should == Money.new(0)
- end
+ it "should calculate tax" do
+ Money.new(100).add_tax(20).cents.should eql(120)
+ Money.new(100).add_tax(-20).cents.should eql(80)
+ end
- it "Money.ca_dollar creates a new Money object of the given value in CAD" do
- Money.ca_dollar(50).should == Money.new(50, "CAD")
- end
+ it "shuld sum array" do
+ @money = Money.new(10_00).add_tax(10)
+ @money.split_in_installments(3).sum.cents.should eql(1100)
+ end
- it "Money.us_dollar creates a new Money object of the given value in USD" do
- Money.us_dollar(50).should == Money.new(50, "USD")
end
- it "Money.euro creates a new Money object of the given value in EUR" do
- Money.euro(50).should == Money.new(50, "EUR")
- end
+ describe "Taxes and Interest" do
- it "Money.real creates a new Money object of the given value in BRL" do
- Money.real(50).should == Money.new(50, "BRL")
- end
+ it "Money.add_rate works" do
+ Money.add_rate("EUR", "USD", 10)
+ Money.new(10_00, "EUR").exchange_to("USD").should == Money.new(100_00, "USD")
+ end
- it "Money.add_rate works" do
- Money.add_rate("EUR", "USD", 10)
- Money.new(10_00, "EUR").exchange_to("USD").should == Money.new(100_00, "USD")
- end
+ it "Money method missing exchange" do
+ Money.add_rate("EUR", "BRL", 10)
+ Money.new(10_00, "EUR").as_brl.should == Money.new(100_00, "BRL")
+ end
- it "Money method missing exchange" do
- Money.add_rate("EUR", "BRL", 10)
- Money.new(10_00, "EUR").as_brl.should == Money.new(100_00, "BRL")
+ it "should calculate compound tax" do
+ m = Money.new(1000_00)
+ m.compound_interest(12.99,12).to_s.should eql("137.91")
+ end
+
+ it "should simple interest" do
+ m = Money.new(1000_00)
+ m.simple_interest(12.99,12).to_s.should eql("129.90")
+ end
+
+ it "should calculate compound interest" do
+ m = Money.new(2500_00)
+ m.compound_interest(12.99,3).to_s.should eql("82.06")
+ end
+
end
describe "Format out " do
describe "Options" do
before(:each) do
- @cash = Money.new(200)
+ @cash = Money.new(2_00, "JPY")
end
- it { @cash.format.should eql("$2.00") }
+ it { @cash.format.should eql("¥2.00") }
it { @cash.format(:symbol => "R$ ").should eql("R$ 2.00") }
- it { @cash.format(:no_cents => true).should eql("$2") }
+ it { @cash.format(:no_cents => true).should eql("¥2") }
it { @cash.format(:no_cents => true, :symbol => "R$ ").should eql("R$ 2") }
+ it { @cash.format(:html => true).should eql("¥2.00") }
+
end
it { Money.new(0).format.should eql("$0.00") }
it { Money.new(0).format(:display_free => true).should eql("free") }
it { Money.new(0).format(:display_free => "GRATIS").should eql("GRATIS") }