money 3.1.0.pre3 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,111 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe "Money core extensions" do
4
- specify "Numberic#to_money works" do
5
- money = 1234.to_money
6
- money.cents.should == 1234_00
7
- money.currency.should == Money.default_currency
8
-
9
- money = 100.37.to_money
10
- money.cents.should == 100_37
11
- money.currency.should == Money.default_currency
12
-
13
- require 'bigdecimal'
14
- money = BigDecimal.new('1234').to_money
15
- money.cents.should == 1234_00
16
- money.currency.should == Money.default_currency
17
- end
18
-
19
- specify "#issue/15" do
20
- amount = 555.55.to_money
21
- amount.should == Money.new(55555)
22
- end
23
-
24
- specify "Numeric#to_money accepts optional currency" do
25
- 1234.to_money('USD').should == Money.new(123400, 'USD')
26
- 1234.to_money('EUR').should == Money.new(123400, 'EUR')
27
- end
28
-
29
- specify "Numeric#to_money should respect :subunit_to_unit" do
30
- 10.to_money('USD').should == Money.new(10_00, 'USD')
31
- 10.to_money('TND').should == Money.new(10_000, 'TND')
32
- 10.to_money('CLP').should == Money.new(10, 'CLP')
33
- end
34
-
35
- specify "String#to_money works" do
36
- "20.15".to_money.should == Money.new(20_15)
37
- "100".to_money.should == Money.new(100_00)
38
- "100.37".to_money.should == Money.new(100_37)
39
- "100,37".to_money.should == Money.new(100_37)
40
- "100 000".to_money.should == Money.new(100_000_00)
41
- "100,000.00".to_money.should == Money.new(100_000_00)
42
- "1,000".to_money.should == Money.new(1_000_00)
43
- "-1,000".to_money.should == Money.new(-1_000_00)
44
- "1,000.5".to_money.should == Money.new(1_000_50)
45
- "1,000.51".to_money.should == Money.new(1_000_51)
46
- "1,000.505".to_money.should == Money.new(1_000_51)
47
- "1,000.504".to_money.should == Money.new(1_000_50)
48
- "1,000.0000".to_money.should == Money.new(1_000_00)
49
- "1,000.5000".to_money.should == Money.new(1_000_50)
50
- "1,000.5099".to_money.should == Money.new(1_000_51)
51
- "1.550".to_money.should == Money.new(1_55)
52
- "25.".to_money.should == Money.new(25_00)
53
- ".75".to_money.should == Money.new(75)
54
-
55
- "100 USD".to_money.should == Money.new(100_00, "USD")
56
- "-100 USD".to_money.should == Money.new(-100_00, "USD")
57
- "100 EUR".to_money.should == Money.new(100_00, "EUR")
58
- "100.37 EUR".to_money.should == Money.new(100_37, "EUR")
59
- "100,37 EUR".to_money.should == Money.new(100_37, "EUR")
60
- "100,000.00 USD".to_money.should == Money.new(100_000_00, "USD")
61
- "100.000,00 EUR".to_money.should == Money.new(100_000_00, "EUR")
62
- "1,000 USD".to_money.should == Money.new(1_000_00, "USD")
63
- "-1,000 USD".to_money.should == Money.new(-1_000_00, "USD")
64
- "1,000.5500 USD".to_money.should == Money.new(1_000_55, "USD")
65
- "-1,000.6500 USD".to_money.should == Money.new(-1_000_65, "USD")
66
- "1.550 USD".to_money.should == Money.new(1_55, "USD")
67
-
68
- "USD 100".to_money.should == Money.new(100_00, "USD")
69
- "EUR 100".to_money.should == Money.new(100_00, "EUR")
70
- "EUR 100.37".to_money.should == Money.new(100_37, "EUR")
71
- "CAD -100.37".to_money.should == Money.new(-100_37, "CAD")
72
- "EUR 100,37".to_money.should == Money.new(100_37, "EUR")
73
- "EUR -100,37".to_money.should == Money.new(-100_37, "EUR")
74
- "USD 100,000.00".to_money.should == Money.new(100_000_00, "USD")
75
- "EUR 100.000,00".to_money.should == Money.new(100_000_00, "EUR")
76
- "USD 1,000".to_money.should == Money.new(1_000_00, "USD")
77
- "USD -1,000".to_money.should == Money.new(-1_000_00, "USD")
78
- "USD 1,000.9000".to_money.should == Money.new(1_000_90, "USD")
79
- "USD -1,000.090".to_money.should == Money.new(-1_000_09, "USD")
80
- "USD 1.5500".to_money.should == Money.new(1_55, "USD")
81
-
82
- "$100 USD".to_money.should == Money.new(100_00, "USD")
83
- "$1,194.59 USD".to_money.should == Money.new(1_194_59, "USD")
84
- "$-1,955 USD".to_money.should == Money.new(-1_955_00, "USD")
85
- "$1,194.5900 USD".to_money.should == Money.new(1_194_59, "USD")
86
- "$-1,955.000 USD".to_money.should == Money.new(-1_955_00, "USD")
87
- "$1.99000 USD".to_money.should == Money.new(1_99, "USD")
88
- end
89
-
90
- specify "String#to_money should accept optional currency" do
91
- "10.10".to_money('USD').should == Money.new(1010, 'USD')
92
- "10.10".to_money('EUR').should == Money.new(1010, 'EUR')
93
- "10.10 USD".to_money('USD').should == Money.new(1010, 'USD')
94
- lambda{"10.10 USD".to_money('EUR')}.should raise_error
95
- end
96
-
97
- specify "String#to_money ignores unrecognized data" do
98
- "hello 2000 world".to_money.should == Money.new(2000_00)
99
- end
100
-
101
- specify "String#to_currency convert string to Currency" do
102
- "USD".to_currency.should == Money::Currency.new(:usd)
103
- "EUR".to_currency.should == Money::Currency.new(:eur)
104
- end
105
-
106
- specify "String#to_currency should raise Currency::UnknownCurrency with unkwnown Currency" do
107
- lambda { "XXX".to_currency }.should raise_error(Money::Currency::UnknownCurrency)
108
- lambda { " ".to_currency }.should raise_error(Money::Currency::UnknownCurrency)
109
- end
110
-
111
- end
@@ -1,126 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require "spec_helper"
4
-
5
- describe Money::Currency do
6
-
7
- specify "#initialize should lookup data from TABLE" do
8
- with_custom_definitions do
9
- Money::Currency::TABLE[:usd] = { :priority => 1, :iso_code => "USD", :name => "United States Dollar", :symbol => "$", :subunit => "Cent", :subunit_to_unit => 100, :separator => ".", :delimiter => "," }
10
- Money::Currency::TABLE[:eur] = { :priority => 2, :iso_code => "EUR", :name => "Euro", :symbol => "€", :subunit => "Cent", :subunit_to_unit => 100, :separator => ".", :delimiter => "," }
11
-
12
- currency = Money::Currency.new("USD")
13
- currency.id.should == :usd
14
- currency.priority.should == 1
15
- currency.iso_code.should == "USD"
16
- currency.name.should == "United States Dollar"
17
- currency.separator.should == "."
18
- currency.delimiter.should == ","
19
- end
20
- end
21
-
22
- specify "#initialize should raise UnknownMoney::Currency with unknown currency" do
23
- lambda { Money::Currency.new("xxx") }.should raise_error(Money::Currency::UnknownCurrency, /xxx/)
24
- end
25
-
26
- specify "#== should return true if self === other" do
27
- currency = Money::Currency.new(:eur)
28
- currency.should == currency
29
- end
30
-
31
- specify "#== should return true if the id is equal" do
32
- Money::Currency.new(:eur).should == Money::Currency.new(:eur)
33
- Money::Currency.new(:eur).should_not == Money::Currency.new(:usd)
34
- end
35
-
36
- specify "#eql? should return true if #== returns true" do
37
- Money::Currency.new(:eur).eql?(Money::Currency.new(:eur)).should be true
38
- Money::Currency.new(:eur).eql?(Money::Currency.new(:usd)).should be false
39
- end
40
-
41
- specify "#hash should return the same value for equal objects" do
42
- Money::Currency.new(:eur).hash.should == Money::Currency.new(:eur).hash
43
- Money::Currency.new(:eur).hash.should_not == Money::Currency.new(:usd).hash
44
- end
45
-
46
- specify "#hash can be used to return the intersection of Currency object arrays" do
47
- intersection = [Money::Currency.new(:eur), Money::Currency.new(:usd)] & [Money::Currency.new(:eur)]
48
- intersection.should == [Money::Currency.new(:eur)]
49
- end
50
-
51
- specify "#<=> should compare objects by priority" do
52
- Money::Currency.new(:cad).should > Money::Currency.new(:usd)
53
- Money::Currency.new(:usd).should < Money::Currency.new(:eur)
54
- end
55
-
56
- specify "#to_s" do
57
- Money::Currency.new(:usd).to_s.should == "USD"
58
- Money::Currency.new(:eur).to_s.should == "EUR"
59
- end
60
-
61
- specify "#inspect" do
62
- Money::Currency.new(:usd).inspect.should ==
63
- %Q{#<Money::Currency id: usd priority: 1, iso_code: USD, name: United States Dollar, symbol: $, subunit: Cent, subunit_to_unit: 100, separator: ., delimiter: ,>}
64
- end
65
-
66
-
67
- specify "#self.find should return currency matching given id" do
68
- with_custom_definitions do
69
- Money::Currency::TABLE[:usd] = { :priority => 1, :iso_code => "USD", :name => "United States Dollar", :symbol => "$", :subunit => "Cent", :subunit_to_unit => 100, :separator => ".", :delimiter => "," }
70
- Money::Currency::TABLE[:eur] = { :priority => 2, :iso_code => "EUR", :name => "Euro", :symbol => "€", :subunit => "Cent", :subunit_to_unit => 100, :separator => ".", :delimiter => "," }
71
-
72
- expected = Money::Currency.new(:eur)
73
- Money::Currency.find(:eur).should == expected
74
- Money::Currency.find(:EUR).should == expected
75
- Money::Currency.find("eur").should == expected
76
- Money::Currency.find("EUR").should == expected
77
- end
78
- end
79
-
80
- specify "#self.find should return nil unless currency matching given id" do
81
- with_custom_definitions do
82
- Money::Currency::TABLE[:usd] = { :position => 1, :iso_code => "USD", :name => "United States Dollar", :symbol => "$", :subunit => "Cent", :subunit_to_unit => 100, :separator => ".", :delimiter => "," }
83
- Money::Currency::TABLE[:eur] = { :position => 2, :iso_code => "EUR", :name => "Euro", :symbol => "€", :subunit => "Cent", :subunit_to_unit => 100, :separator => ".", :delimiter => "," }
84
-
85
- expected = Money::Currency.new(:eur)
86
- Money::Currency.find(:eur).should == expected
87
- Money::Currency.find(:EUR).should == expected
88
- Money::Currency.find("eur").should == expected
89
- Money::Currency.find("EUR").should == expected
90
- end
91
- end
92
-
93
- specify "#self.wrap should return nil if object is nil" do
94
- Money::Currency.wrap(nil).should == nil
95
- Money::Currency.wrap(Money::Currency.new(:usd)).should == Money::Currency.new(:usd)
96
- Money::Currency.wrap(:usd).should == Money::Currency.new(:usd)
97
- end
98
-
99
-
100
- def with_custom_definitions(&block)
101
- begin
102
- old = Money::Currency::TABLE.dup
103
- Money::Currency::TABLE.clear
104
- yield
105
- ensure
106
- silence_warnings do
107
- Money::Currency.const_set("TABLE", old)
108
- end
109
- end
110
- end
111
-
112
- # Sets $VERBOSE to nil for the duration of the block and back to its original value afterwards.
113
- #
114
- # silence_warnings do
115
- # value = noisy_call # no warning voiced
116
- # end
117
- #
118
- # noisy_call # warning voiced
119
- def silence_warnings
120
- old_verbose, $VERBOSE = $VERBOSE, nil
121
- yield
122
- ensure
123
- $VERBOSE = old_verbose
124
- end
125
-
126
- end
@@ -1,16 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe "Money deprecations" do
4
-
5
- describe Money::VariableExchangeBank do
6
- it "should be deprecated" do
7
- Money.should_receive(:deprecate)
8
- Money::VariableExchangeBank.new.should_not be_nil
9
- end
10
-
11
- it "should extend Money::Bank::VariableExchange" do
12
- Money::VariableExchangeBank.new.should be_kind_of Money::Bank::VariableExchange
13
- end
14
- end
15
-
16
- end
data/spec/money_spec.rb DELETED
@@ -1,799 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require "spec_helper"
4
-
5
- describe Money do
6
- it "is associated to the singleton instance of Bank::VariableExchange by default" do
7
- Money.new(0).bank.should be_equal Money::Bank::VariableExchange.instance
8
- end
9
-
10
- specify "#cents returns the amount of cents passed to the constructor" do
11
- Money.new(200_00, "USD").cents.should == 200_00
12
- end
13
-
14
- it "rounds the given cents to an integer" do
15
- Money.new(1.00, "USD").cents.should == 1
16
- Money.new(1.01, "USD").cents.should == 1
17
- Money.new(1.50, "USD").cents.should == 2
18
- end
19
-
20
- specify "#currency returns the currency passed to the constructor" do
21
- Money.new(200_00, "USD").currency.should == Money::Currency.new("USD")
22
- end
23
-
24
- specify "#currency_string returns the iso_code of the currency object" do
25
- Money.new(200_00, "USD").currency_as_string.should == Money::Currency.new("USD").to_s
26
- Money.new(200_00, "USD").currency_as_string.should == "USD"
27
- Money.new(200_00, "EUR").currency_as_string.should == "EUR"
28
- Money.new(200_00, "YEN").currency_as_string.should == "YEN"
29
- end
30
-
31
- specify "#currency_string= set the currency object using the provided string" do
32
- obj = Money.new(200_00, "USD")
33
- obj.currency_as_string = "EUR"
34
- obj.currency.should == Money::Currency.new("EUR")
35
- obj.currency_as_string = "YEN"
36
- obj.currency.should == Money::Currency.new("YEN")
37
- obj.currency_as_string = "USD"
38
- obj.currency.should == Money::Currency.new("USD")
39
- end
40
-
41
- specify "#zero? returns whether the amount is 0" do
42
- Money.new(0, "USD").should be_zero
43
- Money.new(0, "EUR").should be_zero
44
- Money.new(1, "USD").should_not be_zero
45
- Money.new(10, "YEN").should_not be_zero
46
- Money.new(-1, "EUR").should_not be_zero
47
- end
48
-
49
- specify "#nonzero? returns whether the amount is not 0" do
50
- Money.new(0, "USD").should_not be_nonzero
51
- Money.new(0, "EUR").should_not be_nonzero
52
- Money.new(1, "USD").should be_nonzero
53
- Money.new(10, "YEN").should be_nonzero
54
- Money.new(-1, "EUR").should be_nonzero
55
- end
56
-
57
- specify "#nonzero? has the same return-value semantics as Numeric#nonzero?" do
58
- Money.new(0, "USD").nonzero?.should be_nil
59
-
60
- money = Money.new(1, "USD")
61
- money.nonzero?.should be_equal(money)
62
- end
63
-
64
- specify "#exchange_to exchanges the amount via its exchange bank" do
65
- money = Money.new(100_00, "USD")
66
- money.bank.should_receive(:exchange_with).with(Money.new(100_00, Money::Currency.new("USD")), Money::Currency.new("EUR")).and_return(Money.new(200_00, Money::Currency.new('EUR')))
67
- money.exchange_to("EUR")
68
- end
69
-
70
- specify "#exchange_to exchanges the amount properly" do
71
- money = Money.new(100_00, "USD")
72
- money.bank.should_receive(:exchange_with).with(Money.new(100_00, Money::Currency.new("USD")), Money::Currency.new("EUR")).and_return(Money.new(200_00, Money::Currency.new('EUR')))
73
- money.exchange_to("EUR").should == Money.new(200_00, "EUR")
74
- end
75
-
76
- specify "#== returns true if and only if their amount and currency are equal" do
77
- Money.new(1_00, "USD").should == Money.new(1_00, "USD")
78
- Money.new(1_00, "USD").should_not == Money.new(1_00, "EUR")
79
- Money.new(1_00, "USD").should_not == Money.new(2_00, "USD")
80
- Money.new(1_00, "USD").should_not == Money.new(99_00, "EUR")
81
- end
82
-
83
- specify "#== can be used to compare with a String money value" do
84
- Money.new(1_00, "USD").should == "1.00"
85
- Money.new(1_00, "USD").should_not == "2.00"
86
- Money.new(1_00, "GBP").should_not == "1.00"
87
- end
88
-
89
- specify "#== can be used to compare with a Numeric money value" do
90
- Money.new(1_00, "USD").should == 1
91
- Money.new(1_57, "USD").should == 1.57
92
- Money.new(1_00, "USD").should_not == 2
93
- Money.new(1_00, "GBP").should_not == 1
94
- end
95
-
96
- specify "#== can be used to compare with an object that responds to #to_money" do
97
- klass = Class.new do
98
- def initialize(money)
99
- @money = money
100
- end
101
-
102
- def to_money
103
- @money
104
- end
105
- end
106
-
107
- Money.new(1_00, "USD").should == klass.new(Money.new(1_00, "USD"))
108
- Money.new(2_50, "USD").should == klass.new(Money.new(2_50, "USD"))
109
- Money.new(2_50, "USD").should_not == klass.new(Money.new(3_00, "USD"))
110
- Money.new(1_00, "GBP").should_not == klass.new(Money.new(1_00, "USD"))
111
- end
112
-
113
- specify "#== returns false if used to compare with an object that doesn't respond to #to_money" do
114
- Money.new(1_00, "USD").should_not == Object.new
115
- Money.new(1_00, "USD").should_not == Class
116
- Money.new(1_00, "USD").should_not == Kernel
117
- Money.new(1_00, "USD").should_not == /foo/
118
- Money.new(1_00, "USD").should_not == nil
119
- end
120
-
121
- specify "#eql? returns true if and only if their amount and currency are equal" do
122
- Money.new(1_00, "USD").eql?(Money.new(1_00, "USD")).should be true
123
- Money.new(1_00, "USD").eql?(Money.new(1_00, "EUR")).should be false
124
- Money.new(1_00, "USD").eql?(Money.new(2_00, "USD")).should be false
125
- Money.new(1_00, "USD").eql?(Money.new(99_00, "EUR")).should be false
126
- end
127
-
128
- specify "#eql? can be used to compare with a String money value" do
129
- Money.new(1_00, "USD").eql?("1.00").should be true
130
- Money.new(1_00, "USD").eql?("2.00").should be false
131
- Money.new(1_00, "GBP").eql?("1.00").should be false
132
- end
133
-
134
- specify "#eql? can be used to compare with a Numeric money value" do
135
- Money.new(1_00, "USD").eql?(1).should be true
136
- Money.new(1_57, "USD").eql?(1.57).should be true
137
- Money.new(1_00, "USD").eql?(2).should be false
138
- Money.new(1_00, "GBP").eql?(1).should be false
139
- end
140
-
141
- specify "#eql? can be used to compare with an object that responds to #to_money" do
142
- klass = Class.new do
143
- def initialize(money)
144
- @money = money
145
- end
146
-
147
- def to_money
148
- @money
149
- end
150
- end
151
-
152
- Money.new(1_00, "USD").eql?(klass.new(Money.new(1_00, "USD"))).should be true
153
- Money.new(2_50, "USD").eql?(klass.new(Money.new(2_50, "USD"))).should be true
154
- Money.new(2_50, "USD").eql?(klass.new(Money.new(3_00, "USD"))).should be false
155
- Money.new(1_00, "GBP").eql?(klass.new(Money.new(1_00, "USD"))).should be false
156
- end
157
-
158
- specify "#eql? returns false if used to compare with an object that doesn't respond to #to_money" do
159
- Money.new(1_00, "USD").eql?(Object.new).should be false
160
- Money.new(1_00, "USD").eql?(Class).should be false
161
- Money.new(1_00, "USD").eql?(Kernel).should be false
162
- Money.new(1_00, "USD").eql?(/foo/).should be false
163
- Money.new(1_00, "USD").eql?(nil).should be false
164
- end
165
-
166
- specify "#hash should return the same value for equal objects" do
167
- Money.new(1_00, :eur).hash.should == Money.new(1_00, :eur).hash
168
- Money.new(2_00, :usd).hash.should == Money.new(2_00, :usd).hash
169
- Money.new(1_00, :eur).hash.should_not == Money.new(2_00, :eur).hash
170
- Money.new(1_00, :eur).hash.should_not == Money.new(1_00, :usd).hash
171
- Money.new(1_00, :eur).hash.should_not == Money.new(2_00, :usd).hash
172
- end
173
-
174
- specify "#hash can be used to return the intersection of Money object arrays" do
175
- intersection = [Money.new(1_00, :eur), Money.new(1_00, :usd)] & [Money.new(1_00, :eur)]
176
- intersection.should == [Money.new(1_00, :eur)]
177
- end
178
-
179
- specify "#<=> can be used to compare with a String money value" do
180
- (Money.new(1_00) <=> "1.00").should == 0
181
- (Money.new(1_00) <=> ".99").should > 0
182
- (Money.new(1_00) <=> "2.00").should < 0
183
- end
184
-
185
- specify "#<=> can be used to compare with a Numeric money value" do
186
- (Money.new(1_00) <=> 1).should == 0
187
- (Money.new(1_00) <=> 0.99).should > 0
188
- (Money.new(1_00) <=> 2.00).should < 0
189
- end
190
-
191
- specify "#<=> can be used to compare with an object that responds to #to_money" do
192
- klass = Class.new do
193
- def initialize(money)
194
- @money = money
195
- end
196
-
197
- def to_money
198
- @money
199
- end
200
- end
201
-
202
- (Money.new(1_00) <=> klass.new(Money.new(1_00))).should == 0
203
- (Money.new(1_00) <=> klass.new(Money.new(99))).should > 0
204
- (Money.new(1_00) <=> klass.new(Money.new(2_00))).should < 0
205
- end
206
-
207
- specify "#<=> raises ArgumentError when used to compare with an object that doesn't respond to #to_money" do
208
- expected_message = /comparison .+ failed/
209
- lambda{ Money.new(1_00) <=> Object.new }.should raise_error(ArgumentError, expected_message)
210
- lambda{ Money.new(1_00) <=> Class }.should raise_error(ArgumentError, expected_message)
211
- lambda{ Money.new(1_00) <=> Kernel }.should raise_error(ArgumentError, expected_message)
212
- lambda{ Money.new(1_00) <=> /foo/ }.should raise_error(ArgumentError, expected_message)
213
- end
214
-
215
- specify "#* multiplies the money's amount by the multiplier while retaining the currency" do
216
- (Money.new(1_00, "USD") * 10).should == Money.new(10_00, "USD")
217
- end
218
-
219
- specify "#/ divides the money's amount by the divisor while retaining the currency" do
220
- (Money.new(10_00, "USD") / 10).should == Money.new(1_00, "USD")
221
- end
222
-
223
- specify "#/ -> money / fixnum" do
224
- ts = [
225
- {:a => Money.new( 13, :USD), :b => 4, :c => Money.new( 3, :USD)},
226
- {:a => Money.new( 13, :USD), :b => -4, :c => Money.new(-4, :USD)},
227
- {:a => Money.new(-13, :USD), :b => 4, :c => Money.new(-4, :USD)},
228
- {:a => Money.new(-13, :USD), :b => -4, :c => Money.new( 3, :USD)},
229
- ]
230
- ts.each do |t|
231
- (t[:a] / t[:b]).should == t[:c]
232
- end
233
- end
234
-
235
- specify "#/ -> money / money (same currency)" do
236
- ts = [
237
- {:a => Money.new( 13, :USD), :b => Money.new( 4, :USD), :c => 3.25},
238
- {:a => Money.new( 13, :USD), :b => Money.new(-4, :USD), :c => -3.25},
239
- {:a => Money.new(-13, :USD), :b => Money.new( 4, :USD), :c => -3.25},
240
- {:a => Money.new(-13, :USD), :b => Money.new(-4, :USD), :c => 3.25},
241
- ]
242
- ts.each do |t|
243
- (t[:a] / t[:b]).should == t[:c]
244
- end
245
- end
246
-
247
- specify "#/ -> money / money (difference currency)" do
248
- ts = [
249
- {:a => Money.new( 13, :USD), :b => Money.new( 4, :EUR), :c => 1.625},
250
- {:a => Money.new( 13, :USD), :b => Money.new(-4, :EUR), :c => -1.625},
251
- {:a => Money.new(-13, :USD), :b => Money.new( 4, :EUR), :c => -1.625},
252
- {:a => Money.new(-13, :USD), :b => Money.new(-4, :EUR), :c => 1.625},
253
- ]
254
- ts.each do |t|
255
- t[:b].should_receive(:exchange_to).once.with(t[:a].currency).and_return(Money.new(t[:b].cents * 2, :USD))
256
- (t[:a] / t[:b]).should == t[:c]
257
- end
258
- end
259
-
260
- specify "#div -> money / fixnum" do
261
- ts = [
262
- {:a => Money.new( 13, :USD), :b => 4, :c => Money.new( 3, :USD)},
263
- {:a => Money.new( 13, :USD), :b => -4, :c => Money.new(-4, :USD)},
264
- {:a => Money.new(-13, :USD), :b => 4, :c => Money.new(-4, :USD)},
265
- {:a => Money.new(-13, :USD), :b => -4, :c => Money.new( 3, :USD)},
266
- ]
267
- ts.each do |t|
268
- t[:a].div(t[:b]).should == t[:c]
269
- end
270
- end
271
-
272
- specify "#div -> money / money (same currency)" do
273
- ts = [
274
- {:a => Money.new( 13, :USD), :b => Money.new( 4, :USD), :c => 3.25},
275
- {:a => Money.new( 13, :USD), :b => Money.new(-4, :USD), :c => -3.25},
276
- {:a => Money.new(-13, :USD), :b => Money.new( 4, :USD), :c => -3.25},
277
- {:a => Money.new(-13, :USD), :b => Money.new(-4, :USD), :c => 3.25},
278
- ]
279
- ts.each do |t|
280
- t[:a].div(t[:b]).should == t[:c]
281
- end
282
- end
283
-
284
- specify "#div -> money / money (different currency)" do
285
- ts = [
286
- {:a => Money.new( 13, :USD), :b => Money.new( 4, :EUR), :c => 1.625},
287
- {:a => Money.new( 13, :USD), :b => Money.new(-4, :EUR), :c => -1.625},
288
- {:a => Money.new(-13, :USD), :b => Money.new( 4, :EUR), :c => -1.625},
289
- {:a => Money.new(-13, :USD), :b => Money.new(-4, :EUR), :c => 1.625},
290
- ]
291
- ts.each do |t|
292
- t[:b].should_receive(:exchange_to).once.with(t[:a].currency).and_return(Money.new(t[:b].cents * 2, :USD))
293
- t[:a].div(t[:b]).should == t[:c]
294
- end
295
- end
296
-
297
- specify "#divmod -> money `divmod` fixnum" do
298
- ts = [
299
- {:a => Money.new( 13, :USD), :b => 4, :c => [Money.new( 3, :USD), Money.new( 1, :USD)]},
300
- {:a => Money.new( 13, :USD), :b => -4, :c => [Money.new(-4, :USD), Money.new(-3, :USD)]},
301
- {:a => Money.new(-13, :USD), :b => 4, :c => [Money.new(-4, :USD), Money.new( 3, :USD)]},
302
- {:a => Money.new(-13, :USD), :b => -4, :c => [Money.new( 3, :USD), Money.new(-1, :USD)]},
303
- ]
304
- ts.each do |t|
305
- t[:a].divmod(t[:b]).should == t[:c]
306
- end
307
- end
308
-
309
- specify "#divmod -> money `divmod` money (same currency)" do
310
- ts = [
311
- {:a => Money.new( 13, :USD), :b => Money.new( 4, :USD), :c => [ 3, Money.new( 1, :USD)]},
312
- {:a => Money.new( 13, :USD), :b => Money.new(-4, :USD), :c => [-4, Money.new(-3, :USD)]},
313
- {:a => Money.new(-13, :USD), :b => Money.new( 4, :USD), :c => [-4, Money.new( 3, :USD)]},
314
- {:a => Money.new(-13, :USD), :b => Money.new(-4, :USD), :c => [ 3, Money.new(-1, :USD)]},
315
- ]
316
- ts.each do |t|
317
- t[:a].divmod(t[:b]).should == t[:c]
318
- end
319
- end
320
-
321
- specify "#divmod -> money `divmod` money (different currency)" do
322
- ts = [
323
- {:a => Money.new( 13, :USD), :b => Money.new( 4, :EUR), :c => [ 1, Money.new( 5, :USD)]},
324
- {:a => Money.new( 13, :USD), :b => Money.new(-4, :EUR), :c => [-2, Money.new(-3, :USD)]},
325
- {:a => Money.new(-13, :USD), :b => Money.new( 4, :EUR), :c => [-2, Money.new( 3, :USD)]},
326
- {:a => Money.new(-13, :USD), :b => Money.new(-4, :EUR), :c => [ 1, Money.new(-5, :USD)]},
327
- ]
328
- ts.each do |t|
329
- t[:b].should_receive(:exchange_to).once.with(t[:a].currency).and_return(Money.new(t[:b].cents * 2, :USD))
330
- t[:a].divmod(t[:b]).should == t[:c]
331
- end
332
- end
333
-
334
- specify "#modulo -> money `modulo` fixnum" do
335
- ts = [
336
- {:a => Money.new( 13, :USD), :b => 4, :c => Money.new( 1, :USD)},
337
- {:a => Money.new( 13, :USD), :b => -4, :c => Money.new(-3, :USD)},
338
- {:a => Money.new(-13, :USD), :b => 4, :c => Money.new( 3, :USD)},
339
- {:a => Money.new(-13, :USD), :b => -4, :c => Money.new(-1, :USD)},
340
- ]
341
- ts.each do |t|
342
- t[:a].modulo(t[:b]).should == t[:c]
343
- end
344
- end
345
-
346
- specify "#modulo -> money `modulo` money (same currency)" do
347
- ts = [
348
- {:a => Money.new( 13, :USD), :b => Money.new( 4, :USD), :c => Money.new( 1, :USD)},
349
- {:a => Money.new( 13, :USD), :b => Money.new(-4, :USD), :c => Money.new(-3, :USD)},
350
- {:a => Money.new(-13, :USD), :b => Money.new( 4, :USD), :c => Money.new( 3, :USD)},
351
- {:a => Money.new(-13, :USD), :b => Money.new(-4, :USD), :c => Money.new(-1, :USD)},
352
- ]
353
- ts.each do |t|
354
- t[:a].modulo(t[:b]).should == t[:c]
355
- end
356
- end
357
-
358
- specify "#modulo -> money `modulo` money (different currency)" do
359
- ts = [
360
- {:a => Money.new( 13, :USD), :b => Money.new( 4, :EUR), :c => Money.new( 5, :USD)},
361
- {:a => Money.new( 13, :USD), :b => Money.new(-4, :EUR), :c => Money.new(-3, :USD)},
362
- {:a => Money.new(-13, :USD), :b => Money.new( 4, :EUR), :c => Money.new( 3, :USD)},
363
- {:a => Money.new(-13, :USD), :b => Money.new(-4, :EUR), :c => Money.new(-5, :USD)},
364
- ]
365
- ts.each do |t|
366
- t[:b].should_receive(:exchange_to).once.with(t[:a].currency).and_return(Money.new(t[:b].cents * 2, :USD))
367
- t[:a].modulo(t[:b]).should == t[:c]
368
- end
369
- end
370
-
371
- specify "#% -> money % fixnum" do
372
- ts = [
373
- {:a => Money.new( 13, :USD), :b => 4, :c => Money.new( 1, :USD)},
374
- {:a => Money.new( 13, :USD), :b => -4, :c => Money.new(-3, :USD)},
375
- {:a => Money.new(-13, :USD), :b => 4, :c => Money.new( 3, :USD)},
376
- {:a => Money.new(-13, :USD), :b => -4, :c => Money.new(-1, :USD)},
377
- ]
378
- ts.each do |t|
379
- (t[:a] % t[:b]).should == t[:c]
380
- end
381
- end
382
-
383
- specify "#% -> money % money (same currency)" do
384
- ts = [
385
- {:a => Money.new( 13, :USD), :b => Money.new( 4, :USD), :c => Money.new( 1, :USD)},
386
- {:a => Money.new( 13, :USD), :b => Money.new(-4, :USD), :c => Money.new(-3, :USD)},
387
- {:a => Money.new(-13, :USD), :b => Money.new( 4, :USD), :c => Money.new( 3, :USD)},
388
- {:a => Money.new(-13, :USD), :b => Money.new(-4, :USD), :c => Money.new(-1, :USD)},
389
- ]
390
- ts.each do |t|
391
- (t[:a] % t[:b]).should == t[:c]
392
- end
393
- end
394
-
395
- specify "#% -> money % money (different currency)" do
396
- ts = [
397
- {:a => Money.new( 13, :USD), :b => Money.new( 4, :EUR), :c => Money.new( 5, :USD)},
398
- {:a => Money.new( 13, :USD), :b => Money.new(-4, :EUR), :c => Money.new(-3, :USD)},
399
- {:a => Money.new(-13, :USD), :b => Money.new( 4, :EUR), :c => Money.new( 3, :USD)},
400
- {:a => Money.new(-13, :USD), :b => Money.new(-4, :EUR), :c => Money.new(-5, :USD)},
401
- ]
402
- ts.each do |t|
403
- t[:b].should_receive(:exchange_to).once.with(t[:a].currency).and_return(Money.new(t[:b].cents * 2, :USD))
404
- (t[:a] % t[:b]).should == t[:c]
405
- end
406
- end
407
-
408
- specify "#remainder -> money `remainder` fixnum" do
409
- ts = [
410
- {:a => Money.new( 13, :USD), :b => 4, :c => Money.new( 1, :USD)},
411
- {:a => Money.new( 13, :USD), :b => -4, :c => Money.new( 1, :USD)},
412
- {:a => Money.new(-13, :USD), :b => 4, :c => Money.new(-1, :USD)},
413
- {:a => Money.new(-13, :USD), :b => -4, :c => Money.new(-1, :USD)},
414
- ]
415
- ts.each do |t|
416
- t[:a].remainder(t[:b]).should == t[:c]
417
- end
418
- end
419
-
420
- specify "#remainder -> money `remainder` money (same currency)" do
421
- ts = [
422
- {:a => Money.new( 13, :USD), :b => Money.new( 4, :USD), :c => Money.new( 1, :USD)},
423
- {:a => Money.new( 13, :USD), :b => Money.new(-4, :USD), :c => Money.new( 1, :USD)},
424
- {:a => Money.new(-13, :USD), :b => Money.new( 4, :USD), :c => Money.new(-1, :USD)},
425
- {:a => Money.new(-13, :USD), :b => Money.new(-4, :USD), :c => Money.new(-1, :USD)},
426
- ]
427
- ts.each do |t|
428
- t[:a].remainder(t[:b]).should == t[:c]
429
- end
430
- end
431
-
432
- specify "#remainder -> money `remainder` money (different currency)" do
433
- ts = [
434
- {:a => Money.new( 13, :USD), :b => Money.new( 4, :EUR), :c => Money.new( 5, :USD)},
435
- {:a => Money.new( 13, :USD), :b => Money.new(-4, :EUR), :c => Money.new( 5, :USD)},
436
- {:a => Money.new(-13, :USD), :b => Money.new( 4, :EUR), :c => Money.new(-5, :USD)},
437
- {:a => Money.new(-13, :USD), :b => Money.new(-4, :EUR), :c => Money.new(-5, :USD)},
438
- ]
439
- ts.each do |t|
440
- t[:b].should_receive(:exchange_to).once.with(t[:a].currency).and_return(Money.new(t[:b].cents * 2, :USD))
441
- t[:a].remainder(t[:b]).should == t[:c]
442
- end
443
- end
444
-
445
- specify "#abs correctly returns the absolute value as a new Money object" do
446
- n = Money.new(-1, :USD)
447
- n.abs.should == Money.new( 1, :USD)
448
- n.should == Money.new(-1, :USD)
449
- end
450
-
451
- specify "Money.empty creates a new Money object of 0 cents" do
452
- Money.empty.should == Money.new(0)
453
- end
454
-
455
- specify "Money.ca_dollar creates a new Money object of the given value in CAD" do
456
- Money.ca_dollar(50).should == Money.new(50, "CAD")
457
- end
458
-
459
- specify "Money.ca_dollar creates a new Money object of the given value in USD" do
460
- Money.us_dollar(50).should == Money.new(50, "USD")
461
- end
462
-
463
- specify "Money.ca_dollar creates a new Money object of the given value in EUR" do
464
- Money.euro(50).should == Money.new(50, "EUR")
465
- end
466
-
467
- specify "Money.new accepts { :currency => 'foo' } as the value for the 'currency' argument" do
468
- money = Money.new(20, :currency => "EUR")
469
- money.currency.should == Money::Currency.new("EUR")
470
-
471
- money = Money.new(20, :currency => nil)
472
- money.currency.should == Money.default_currency
473
- end
474
-
475
- specify "Money.add_rate works" do
476
- Money.add_rate("EUR", "USD", 10)
477
- Money.new(10_00, "EUR").exchange_to("USD").should == Money.new(100_00, "USD")
478
- end
479
-
480
- specify "Money.to_s works" do
481
- Money.new(10_00).to_s.should == "10.00"
482
- end
483
-
484
- specify "Money.to_s works with :subunit_to_unit other than 100" do
485
- Money.new(10_00, "BHD").to_s.should == "1.00"
486
- end
487
-
488
- specify "Money.to_s shouldn't have decimal when :subunit_to_unit is 1" do
489
- Money.new(10_00, "CLP").to_s.should == "1000"
490
- end
491
-
492
- specify "Money.to_f works" do
493
- Money.new(10_00).to_f.should == 10.0
494
- end
495
-
496
- specify "Money.to_f works with :subunit_to_unit other than 100" do
497
- Money.new(10_00, "BHD").to_f.should == 1.0
498
- end
499
-
500
- describe "#format" do
501
- it "returns the monetary value as a string" do
502
- Money.ca_dollar(100).format.should == "$1.00"
503
- end
504
-
505
- it "uses the correct :subunit_to_unit" do
506
- Money.new(10_00, "BHD").format.should == "ب.د1.00"
507
- end
508
-
509
- it "doesn't display a decimal when :subunit_to_unit is 1" do
510
- Money.new(10_00, "CLP").format.should == "$1.000"
511
- end
512
-
513
- specify "respects the delimiter and separator defaults" do
514
- one_thousand = Proc.new do |currency|
515
- Money.new(1000_00, currency).format
516
- end
517
-
518
- # Pounds
519
- one_thousand["GBP"].should == "£1,000.00"
520
-
521
- # Dollars
522
- one_thousand["USD"].should == "$1,000.00"
523
- one_thousand["CAD"].should == "$1,000.00"
524
- one_thousand["AUD"].should == "$1,000.00"
525
- one_thousand["NZD"].should == "$1,000.00"
526
- one_thousand["ZWD"].should == "$1,000.00"
527
-
528
- # Yen
529
- one_thousand["JPY"].should == "¥1,000.00"
530
- one_thousand["CNY"].should == "¥10,000.00"
531
-
532
- # Euro
533
- one_thousand["EUR"].should == "€1,000.00"
534
-
535
- # Rupees
536
- one_thousand["INR"].should == "₨1,000.00"
537
- one_thousand["NPR"].should == "₨1,000.00"
538
- one_thousand["SCR"].should == "₨1,000.00"
539
- one_thousand["LKR"].should == "₨1,000.00"
540
-
541
- # Brazilian Real
542
- one_thousand["BRL"].should == "R$ 1.000,00"
543
-
544
- # Other
545
- one_thousand["SEK"].should == "kr1,000.00"
546
- one_thousand["GHC"].should == "₵1,000.00"
547
- end
548
-
549
- describe "if the monetary value is 0" do
550
- before :each do
551
- @money = Money.us_dollar(0)
552
- end
553
-
554
- it "returns 'free' when :display_free is true" do
555
- @money.format(:display_free => true).should == 'free'
556
- end
557
-
558
- it "returns '$0.00' when :display_free is false or not given" do
559
- @money.format.should == '$0.00'
560
- @money.format(:display_free => false).should == '$0.00'
561
- @money.format(:display_free => nil).should == '$0.00'
562
- end
563
-
564
- it "returns the value specified by :display_free if it's a string-like object" do
565
- @money.format(:display_free => 'gratis').should == 'gratis'
566
- end
567
- end
568
-
569
-
570
- specify "#symbol works as documented" do
571
- currency = Money::Currency.new("EUR")
572
- currency.should_receive(:symbol).and_return("€")
573
- Money.empty(currency).symbol.should == "€"
574
-
575
- currency = Money::Currency.new("EUR")
576
- currency.should_receive(:symbol).and_return(nil)
577
- Money.empty(currency).symbol.should == "¤"
578
- end
579
-
580
- specify "#delimiter works as documented" do
581
- Money.empty("USD").delimiter.should == ","
582
- Money.empty("EUR").delimiter.should == ","
583
- Money.empty("BRL").delimiter.should == "."
584
- end
585
-
586
- specify "#separator works as documented" do
587
- Money.empty("USD").separator.should == "."
588
- Money.empty("EUR").separator.should == "."
589
- Money.empty("BRL").separator.should == ","
590
- end
591
-
592
- specify "#format(:with_currency => true) works as documented" do
593
- Money.ca_dollar(100).format(:with_currency => true).should == "$1.00 CAD"
594
- Money.us_dollar(85).format(:with_currency => true).should == "$0.85 USD"
595
- Money.us_dollar(85).format(:with_currency).should == "$0.85 USD"
596
- end
597
-
598
- specify "#format(:with_currency) works as documented" do
599
- Money.ca_dollar(100).format(:with_currency).should == "$1.00 CAD"
600
- Money.us_dollar(85).format(:with_currency).should == "$0.85 USD"
601
- end
602
-
603
- specify "#format(:no_cents => true) works as documented" do
604
- Money.ca_dollar(100).format(:no_cents => true).should == "$1"
605
- Money.ca_dollar(599).format(:no_cents => true).should == "$5"
606
- Money.ca_dollar(570).format(:no_cents => true, :with_currency => true).should == "$5 CAD"
607
- Money.ca_dollar(39000).format(:no_cents => true).should == "$390"
608
- end
609
-
610
- specify "#format(:no_cents => true) uses correct :subunit_to_unit" do
611
- Money.new(10_00, "BHD").format(:no_cents => true).should == "ب.د1"
612
- end
613
-
614
- specify "#format(:no_cents) works as documented" do
615
- Money.ca_dollar(100).format(:no_cents).should == "$1"
616
- Money.ca_dollar(599).format(:no_cents).should == "$5"
617
- Money.ca_dollar(570).format(:no_cents, :with_currency).should == "$5 CAD"
618
- Money.ca_dollar(39000).format(:no_cents).should == "$390"
619
- end
620
-
621
- specify "#format(:no_cents) uses correct :subunit_to_unit" do
622
- Money.new(10_00, "BHD").format(:no_cents).should == "ب.د1"
623
- end
624
-
625
- specify "#format(:symbol => a symbol string) uses the given value as the money symbol" do
626
- Money.new(100, "GBP").format(:symbol => "£").should == "£1.00"
627
- end
628
-
629
- specify "#format(:symbol => true) returns symbol based on the given currency code" do
630
- one = Proc.new do |currency|
631
- Money.new(100, currency).format(:symbol => true)
632
- end
633
-
634
- # Pounds
635
- one["GBP"].should == "£1.00"
636
-
637
- # Dollars
638
- one["USD"].should == "$1.00"
639
- one["CAD"].should == "$1.00"
640
- one["AUD"].should == "$1.00"
641
- one["NZD"].should == "$1.00"
642
- one["ZWD"].should == "$1.00"
643
-
644
- # Yen
645
- one["JPY"].should == "¥1.00"
646
- one["CNY"].should == "¥10.00"
647
-
648
- # Euro
649
- one["EUR"].should == "€1.00"
650
-
651
- # Rupees
652
- one["INR"].should == "₨1.00"
653
- one["NPR"].should == "₨1.00"
654
- one["SCR"].should == "₨1.00"
655
- one["LKR"].should == "₨1.00"
656
-
657
- # Brazilian Real
658
- one["BRL"].should == "R$ 1,00"
659
-
660
- # Other
661
- one["SEK"].should == "kr1.00"
662
- one["GHC"].should == "₵1.00"
663
- end
664
-
665
- specify "#format(:symbol => true) returns $ when currency code is not recognized" do
666
- currency = Money::Currency.new("EUR")
667
- currency.should_receive(:symbol).and_return(nil)
668
- Money.new(100, currency).format(:symbol => true).should == "¤1.00"
669
- end
670
-
671
- specify "#format(:symbol => some non-Boolean value that evaluates to true) returs symbol based on the given currency code" do
672
- Money.new(100, "GBP").format(:symbol => true).should == "£1.00"
673
- Money.new(100, "EUR").format(:symbol => true).should == "€1.00"
674
- Money.new(100, "SEK").format(:symbol => true).should == "kr1.00"
675
- end
676
-
677
- specify "#format with :symbol == "", nil or false returns the amount without a symbol" do
678
- money = Money.new(100, "GBP")
679
- money.format(:symbol => "").should == "1.00"
680
- money.format(:symbol => nil).should == "1.00"
681
- money.format(:symbol => false).should == "1.00"
682
- end
683
-
684
- specify "#format without :symbol assumes that :symbol is set to true" do
685
- money = Money.new(100)
686
- money.format.should == "$1.00"
687
-
688
- money = Money.new(100, "GBP")
689
- money.format.should == "£1.00"
690
-
691
- money = Money.new(100, "EUR")
692
- money.format.should == "€1.00"
693
- end
694
-
695
- specify "#format(:separator => a separator string) works as documented" do
696
- Money.us_dollar(100).format(:separator => ",").should == "$1,00"
697
- end
698
-
699
- specify "#format will default separator to '.' if currency isn't recognized" do
700
- Money.new(100, "ZWD").format.should == "$1.00"
701
- end
702
-
703
- specify "#format(:delimiter => a delimiter string) works as documented" do
704
- Money.us_dollar(100000).format(:delimiter => ".").should == "$1.000.00"
705
- Money.us_dollar(200000).format(:delimiter => "").should == "$2000.00"
706
- end
707
-
708
- specify "#format(:delimiter => false or nil) works as documented" do
709
- Money.us_dollar(100000).format(:delimiter => false).should == "$1000.00"
710
- Money.us_dollar(200000).format(:delimiter => nil).should == "$2000.00"
711
- end
712
-
713
- specify "#format will default delimiter to ',' if currency isn't recognized" do
714
- Money.new(100000, "ZWD").format.should == "$1,000.00"
715
- end
716
-
717
- specify "#format(:html => true) works as documented" do
718
- string = Money.ca_dollar(570).format(:html => true, :with_currency => true)
719
- string.should == "$5.70 <span class=\"currency\">CAD</span>"
720
- end
721
-
722
- it "should insert commas into the result if the amount is sufficiently large" do
723
- Money.us_dollar(1_000_000_000_12).format.should == "$1,000,000,000.12"
724
- Money.us_dollar(1_000_000_000_12).format(:no_cents => true).should == "$1,000,000,000"
725
- end
726
- end
727
-
728
-
729
- # Sets $VERBOSE to nil for the duration of the block and back to its original value afterwards.
730
- #
731
- # silence_warnings do
732
- # value = noisy_call # no warning voiced
733
- # end
734
- #
735
- # noisy_call # warning voiced
736
- def silence_warnings
737
- old_verbose, $VERBOSE = $VERBOSE, nil
738
- yield
739
- ensure
740
- $VERBOSE = old_verbose
741
- end
742
-
743
- end
744
-
745
- describe "Actions involving two Money objects" do
746
- describe "if the other Money object has the same currency" do
747
- specify "#<=> compares the two objects' amounts" do
748
- (Money.new(1_00, "USD") <=> Money.new(1_00, "USD")).should == 0
749
- (Money.new(1_00, "USD") <=> Money.new(99, "USD")).should > 0
750
- (Money.new(1_00, "USD") <=> Money.new(2_00, "USD")).should < 0
751
- end
752
-
753
- specify "#+ adds the other object's amount to the current object's amount while retaining the currency" do
754
- (Money.new(10_00, "USD") + Money.new(90, "USD")).should == Money.new(10_90, "USD")
755
- end
756
-
757
- specify "#- substracts the other object's amount from the current object's amount while retaining the currency" do
758
- (Money.new(10_00, "USD") - Money.new(90, "USD")).should == Money.new(9_10, "USD")
759
- end
760
-
761
- specify "#/ divides the current object's amount by the other object's amount resulting in a float" do
762
- (Money.new(10_00, "USD") / Money.new(100_00, "USD")).should == 0.1
763
- end
764
- end
765
-
766
- describe "if the other Money object has a different currency" do
767
- specify "#<=> compares the two objects' amount after converting the other object's amount to its own currency" do
768
- target = Money.new(200_00, "EUR")
769
- target.should_receive(:exchange_to).with(Money::Currency.new("USD")).and_return(Money.new(300_00, "USD"))
770
- (Money.new(100_00, "USD") <=> target).should < 0
771
-
772
- target = Money.new(200_00, "EUR")
773
- target.should_receive(:exchange_to).with(Money::Currency.new("USD")).and_return(Money.new(100_00, "USD"))
774
- (Money.new(100_00, "USD") <=> target).should == 0
775
-
776
- target = Money.new(200_00, "EUR")
777
- target.should_receive(:exchange_to).with(Money::Currency.new("USD")).and_return(Money.new(99_00, "USD"))
778
- (Money.new(100_00, "USD") <=> target).should > 0
779
- end
780
-
781
- specify "#+ adds the other object's amount, converted to this object's currency, to this object's amount while retaining its currency" do
782
- other = Money.new(90, "EUR")
783
- other.should_receive(:exchange_to).with(Money::Currency.new("USD")).and_return(Money.new(9_00, "USD"))
784
- (Money.new(10_00, "USD") + other).should == Money.new(19_00, "USD")
785
- end
786
-
787
- specify "#- substracts the other object's amount, converted to this object's currency, from this object's amount while retaining its currency" do
788
- other = Money.new(90, "EUR")
789
- other.should_receive(:exchange_to).with(Money::Currency.new("USD")).and_return(Money.new(9_00, "USD"))
790
- (Money.new(10_00, "USD") - other).should == Money.new(1_00, "USD")
791
- end
792
-
793
- specify "#/ divides the this object's amount by the other objects's amount, converted to this object's currency, resulting in a float" do
794
- other = Money.new(1000, "EUR")
795
- other.should_receive(:exchange_to).with(Money::Currency.new("USD")).and_return(Money.new(100_00, "USD"))
796
- (Money.new(10_00, "USD") / other).should == 0.1
797
- end
798
- end
799
- end