money 4.0.1 → 4.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,158 +1,160 @@
1
- require "spec_helper"
2
-
3
- describe "Money core extensions" do
4
-
5
- describe Numeric do
6
- describe "#to_money" do
7
- it "should work" do
8
- money = 1234.to_money
9
- money.cents.should == 1234_00
10
- money.currency.should == Money.default_currency
11
-
12
- money = 100.37.to_money
13
- money.cents.should == 100_37
14
- money.currency.should == Money.default_currency
15
-
16
- money = BigDecimal.new('1234').to_money
17
- money.cents.should == 1234_00
18
- money.currency.should == Money.default_currency
19
- end
20
-
21
- it "should accept optional currency" do
22
- 1234.to_money('USD').should == Money.new(123400, 'USD')
23
- 1234.to_money('EUR').should == Money.new(123400, 'EUR')
24
- end
25
-
26
- it "should respect :subunit_to_unit currency property" do
27
- 10.to_money('USD').should == Money.new(10_00, 'USD')
28
- 10.to_money('TND').should == Money.new(10_000, 'TND')
29
- 10.to_money('CLP').should == Money.new(10, 'CLP')
30
- end
31
-
32
- specify "#issue/15" do
33
- amount = 555.55.to_money
34
- amount.should == Money.new(55555)
35
- end
36
- end
37
- end
38
-
39
- describe String do
40
- describe "#to_money" do
41
-
42
- StringToMoney = {
43
- "20.15" => Money.new(20_15) ,
44
- "100" => Money.new(100_00) ,
45
- "100.37" => Money.new(100_37) ,
46
- "100,37" => Money.new(100_37) ,
47
- "100 000" => Money.new(100_000_00) ,
48
- "100,000.00" => Money.new(100_000_00) ,
49
- "1,000" => Money.new(1_000_00) ,
50
- "-1,000" => Money.new(-1_000_00) ,
51
- "1,000.5" => Money.new(1_000_50) ,
52
- "1,000.51" => Money.new(1_000_51) ,
53
- "1,000.505" => Money.new(1_000_51) ,
54
- "1,000.504" => Money.new(1_000_50) ,
55
- "1,000.0000" => Money.new(1_000_00) ,
56
- "1,000.5000" => Money.new(1_000_50) ,
57
- "1,000.5099" => Money.new(1_000_51) ,
58
- "1.550" => Money.new(1_55) ,
59
- "25." => Money.new(25_00) ,
60
- ".75" => Money.new(75) ,
61
-
62
- "100 USD" => Money.new(100_00, "USD") ,
63
- "-100 USD" => Money.new(-100_00, "USD") ,
64
- "100 EUR" => Money.new(100_00, "EUR") ,
65
- "100.37 EUR" => Money.new(100_37, "EUR") ,
66
- "100,37 EUR" => Money.new(100_37, "EUR") ,
67
- "100,000.00 USD" => Money.new(100_000_00, "USD") ,
68
- "100.000,00 EUR" => Money.new(100_000_00, "EUR") ,
69
- "1,000 USD" => Money.new(1_000_00, "USD") ,
70
- "-1,000 USD" => Money.new(-1_000_00, "USD") ,
71
- "1,000.5500 USD" => Money.new(1_000_55, "USD") ,
72
- "-1,000.6500 USD" => Money.new(-1_000_65, "USD") ,
73
- "1.550 USD" => Money.new(1_55, "USD") ,
74
-
75
- "USD 100" => Money.new(100_00, "USD") ,
76
- "EUR 100" => Money.new(100_00, "EUR") ,
77
- "EUR 100.37" => Money.new(100_37, "EUR") ,
78
- "CAD -100.37" => Money.new(-100_37, "CAD") ,
79
- "EUR 100,37" => Money.new(100_37, "EUR") ,
80
- "EUR -100,37" => Money.new(-100_37, "EUR") ,
81
- "USD 100,000.00" => Money.new(100_000_00, "USD") ,
82
- "EUR 100.000,00" => Money.new(100_000_00, "EUR") ,
83
- "USD 1,000" => Money.new(1_000_00, "USD") ,
84
- "USD -1,000" => Money.new(-1_000_00, "USD") ,
85
- "USD 1,000.9000" => Money.new(1_000_90, "USD") ,
86
- "USD -1,000.090" => Money.new(-1_000_09, "USD") ,
87
- "USD 1.5500" => Money.new(1_55, "USD") ,
88
-
89
- "$100 USD" => Money.new(100_00, "USD") ,
90
- "$1,194.59 USD" => Money.new(1_194_59, "USD") ,
91
- "$-1,955 USD" => Money.new(-1_955_00, "USD") ,
92
- "$1,194.5900 USD" => Money.new(1_194_59, "USD") ,
93
- "$-1,955.000 USD" => Money.new(-1_955_00, "USD") ,
94
- "$1.99000 USD" => Money.new(1_99, "USD") ,
95
- }
96
-
97
- specify "it should work" do
98
- StringToMoney.each do |string, money|
99
- string.to_money.should == money
100
- end
101
- end
102
-
103
- it "should coerce input to string" do
104
- Money.parse(20, "USD").should == Money.new(20_00, "USD")
105
- end
106
-
107
- it "should accept optional currency" do
108
- "10.10".to_money('USD').should == Money.new(1010, 'USD')
109
- "10.10".to_money('EUR').should == Money.new(1010, 'EUR')
110
- "10.10 USD".to_money('USD').should == Money.new(1010, 'USD')
111
- end
112
-
113
- it "should raise error if optional currency doesn't match string currency" do
114
- lambda{ "10.10 USD".to_money('EUR') }.should raise_error(/Mismatching Currencies/)
115
- end
116
-
117
- it "should ignore unrecognized data" do
118
- "hello 2000 world".to_money.should == Money.new(2000_00)
119
- end
120
-
121
- it "should respect :subunit_to_unit currency property" do
122
- "1".to_money("USD").should == Money.new(1_00, "USD")
123
- "1".to_money("TND").should == Money.new(1_000, "TND")
124
- "1".to_money("CLP").should == Money.new(1, "CLP")
125
- "1.5".to_money("KWD").cents.should == 1500
126
- end
127
- end
128
-
129
- describe "#to_currency" do
130
- it "should convert string to Currency" do
131
- "USD".to_currency.should == Money::Currency.new(:usd)
132
- "EUR".to_currency.should == Money::Currency.new(:eur)
133
- end
134
-
135
- it "should raise Money::Currency::UnknownCurrency with unknown Currency" do
136
- lambda { "XXX".to_currency }.should raise_error(Money::Currency::UnknownCurrency)
137
- lambda { " ".to_currency }.should raise_error(Money::Currency::UnknownCurrency)
138
- end
139
- end
140
- end
141
-
142
- describe Symbol do
143
- describe "#to_currency" do
144
- it "should convert symbol to Currency" do
145
- :usd.to_currency.should == Money::Currency.new(:usd)
146
- :ars.to_currency.should == Money::Currency.new(:ars)
147
- end
148
- it "should work case-insensitive" do
149
- :EUR.to_currency.should == Money::Currency.new(:eur)
150
- end
151
- it "should raise Money::Currency::UnknownCurrency with unknown Currency" do
152
- lambda { :XXX.to_currency }.should raise_error(Money::Currency::UnknownCurrency)
153
- lambda { :" ".to_currency }.should raise_error(Money::Currency::UnknownCurrency)
154
- end
155
- end
156
- end
157
-
158
- end
1
+ require "spec_helper"
2
+
3
+ describe Money, "core extensions" do
4
+
5
+ describe Numeric do
6
+ describe "#to_money" do
7
+ it "work as documented" do
8
+ money = 1234.to_money
9
+ money.cents.should == 1234_00
10
+ money.currency.should == Money.default_currency
11
+
12
+ money = 100.37.to_money
13
+ money.cents.should == 100_37
14
+ money.currency.should == Money.default_currency
15
+
16
+ money = BigDecimal.new('1234').to_money
17
+ money.cents.should == 1234_00
18
+ money.currency.should == Money.default_currency
19
+ end
20
+
21
+ it "accepts optional currency" do
22
+ 1234.to_money('USD').should == Money.new(123400, 'USD')
23
+ 1234.to_money('EUR').should == Money.new(123400, 'EUR')
24
+ end
25
+
26
+ it "respects :subunit_to_unit currency property" do
27
+ 10.to_money('USD').should == Money.new(10_00, 'USD')
28
+ 10.to_money('TND').should == Money.new(10_000, 'TND')
29
+ 10.to_money('CLP').should == Money.new(10, 'CLP')
30
+ end
31
+
32
+ specify "GH-15" do
33
+ amount = 555.55.to_money
34
+ amount.should == Money.new(55555)
35
+ end
36
+ end
37
+ end
38
+
39
+ describe String do
40
+ describe "#to_money" do
41
+
42
+ STRING_TO_MONEY = {
43
+ "20.15" => Money.new(20_15) ,
44
+ "100" => Money.new(100_00) ,
45
+ "100.37" => Money.new(100_37) ,
46
+ "100,37" => Money.new(100_37) ,
47
+ "100 000" => Money.new(100_000_00) ,
48
+ "100,000.00" => Money.new(100_000_00) ,
49
+ "1,000" => Money.new(1_000_00) ,
50
+ "-1,000" => Money.new(-1_000_00) ,
51
+ "1,000.5" => Money.new(1_000_50) ,
52
+ "1,000.51" => Money.new(1_000_51) ,
53
+ "1,000.505" => Money.new(1_000_51) ,
54
+ "1,000.504" => Money.new(1_000_50) ,
55
+ "1,000.0000" => Money.new(1_000_00) ,
56
+ "1,000.5000" => Money.new(1_000_50) ,
57
+ "1,000.5099" => Money.new(1_000_51) ,
58
+ "1.550" => Money.new(1_55) ,
59
+ "25." => Money.new(25_00) ,
60
+ ".75" => Money.new(75) ,
61
+
62
+ "100 USD" => Money.new(100_00, "USD") ,
63
+ "-100 USD" => Money.new(-100_00, "USD") ,
64
+ "100 EUR" => Money.new(100_00, "EUR") ,
65
+ "100.37 EUR" => Money.new(100_37, "EUR") ,
66
+ "100,37 EUR" => Money.new(100_37, "EUR") ,
67
+ "100,000.00 USD" => Money.new(100_000_00, "USD") ,
68
+ "100.000,00 EUR" => Money.new(100_000_00, "EUR") ,
69
+ "1,000 USD" => Money.new(1_000_00, "USD") ,
70
+ "-1,000 USD" => Money.new(-1_000_00, "USD") ,
71
+ "1,000.5500 USD" => Money.new(1_000_55, "USD") ,
72
+ "-1,000.6500 USD" => Money.new(-1_000_65, "USD") ,
73
+ "1.550 USD" => Money.new(1_55, "USD") ,
74
+
75
+ "USD 100" => Money.new(100_00, "USD") ,
76
+ "EUR 100" => Money.new(100_00, "EUR") ,
77
+ "EUR 100.37" => Money.new(100_37, "EUR") ,
78
+ "CAD -100.37" => Money.new(-100_37, "CAD") ,
79
+ "EUR 100,37" => Money.new(100_37, "EUR") ,
80
+ "EUR -100,37" => Money.new(-100_37, "EUR") ,
81
+ "USD 100,000.00" => Money.new(100_000_00, "USD") ,
82
+ "EUR 100.000,00" => Money.new(100_000_00, "EUR") ,
83
+ "USD 1,000" => Money.new(1_000_00, "USD") ,
84
+ "USD -1,000" => Money.new(-1_000_00, "USD") ,
85
+ "USD 1,000.9000" => Money.new(1_000_90, "USD") ,
86
+ "USD -1,000.090" => Money.new(-1_000_09, "USD") ,
87
+ "USD 1.5500" => Money.new(1_55, "USD") ,
88
+
89
+ "$100 USD" => Money.new(100_00, "USD") ,
90
+ "$1,194.59 USD" => Money.new(1_194_59, "USD") ,
91
+ "$-1,955 USD" => Money.new(-1_955_00, "USD") ,
92
+ "$1,194.5900 USD" => Money.new(1_194_59, "USD") ,
93
+ "$-1,955.000 USD" => Money.new(-1_955_00, "USD") ,
94
+ "$1.99000 USD" => Money.new(1_99, "USD") ,
95
+ }
96
+
97
+ it "works as documented" do
98
+ STRING_TO_MONEY.each do |string, money|
99
+ string.to_money.should == money
100
+ end
101
+ end
102
+
103
+ it "coerces input to string" do
104
+ Money.parse(20, "USD").should == Money.new(20_00, "USD")
105
+ end
106
+
107
+ it "accepts optional currency" do
108
+ "10.10".to_money('USD').should == Money.new(1010, 'USD')
109
+ "10.10".to_money('EUR').should == Money.new(1010, 'EUR')
110
+ "10.10 USD".to_money('USD').should == Money.new(1010, 'USD')
111
+ end
112
+
113
+ it "raises error if optional currency doesn't match string currency" do
114
+ expect { "10.10 USD".to_money('EUR') }.to raise_error(/Mismatching Currencies/)
115
+ end
116
+
117
+ it "ignores unrecognized data" do
118
+ "hello 2000 world".to_money.should == Money.new(2000_00)
119
+ end
120
+
121
+ it "respects :subunit_to_unit currency property" do
122
+ "1".to_money("USD").should == Money.new(1_00, "USD")
123
+ "1".to_money("TND").should == Money.new(1_000, "TND")
124
+ "1".to_money("CLP").should == Money.new(1, "CLP")
125
+ "1.5".to_money("KWD").cents.should == 1500
126
+ end
127
+ end
128
+
129
+ describe "#to_currency" do
130
+ it "converts String to Currency" do
131
+ "USD".to_currency.should == Money::Currency.new("USD")
132
+ "EUR".to_currency.should == Money::Currency.new("EUR")
133
+ end
134
+
135
+ it "raises Money::Currency::UnknownCurrency with unknown Currency" do
136
+ expect { "XXX".to_currency }.to raise_error(Money::Currency::UnknownCurrency)
137
+ expect { " ".to_currency }.to raise_error(Money::Currency::UnknownCurrency)
138
+ end
139
+ end
140
+ end
141
+
142
+ describe Symbol do
143
+ describe "#to_currency" do
144
+ it "converts Symbol to Currency" do
145
+ :usd.to_currency.should == Money::Currency.new("USD")
146
+ :ars.to_currency.should == Money::Currency.new("ARS")
147
+ end
148
+
149
+ it "is case-insensitive" do
150
+ :EUR.to_currency.should == Money::Currency.new("EUR")
151
+ end
152
+
153
+ it "raises Money::Currency::UnknownCurrency with unknown Currency" do
154
+ expect { :XXX.to_currency }.to raise_error(Money::Currency::UnknownCurrency)
155
+ expect { :" ".to_currency }.to raise_error(Money::Currency::UnknownCurrency)
156
+ end
157
+ end
158
+ end
159
+
160
+ end
@@ -1,120 +1,139 @@
1
- # encoding: utf-8
2
-
3
- require "spec_helper"
4
-
5
- describe Money::Currency do
6
-
7
- specify "#initialize should lookup data from loaded config" do
8
- currency = Money::Currency.new("USD")
9
- currency.id.should == :usd
10
- currency.priority.should == 1
11
- currency.iso_code.should == "USD"
12
- currency.iso_numeric.should == "840"
13
- currency.name.should == "United States Dollar"
14
- currency.decimal_mark.should == "."
15
- currency.separator.should == "."
16
- currency.thousands_separator.should == ","
17
- currency.delimiter.should == ","
18
- end
19
-
20
- specify "#initialize should raise UnknownMoney::Currency with unknown currency" do
21
- lambda { Money::Currency.new("xxx") }.should raise_error(Money::Currency::UnknownCurrency, /xxx/)
22
- end
23
-
24
- specify "#== should return true if self === other" do
25
- currency = Money::Currency.new(:eur)
26
- currency.should == currency
27
- end
28
-
29
- specify "#== should return true if the id is equal" do
30
- Money::Currency.new(:eur).should == Money::Currency.new(:eur)
31
- Money::Currency.new(:eur).should_not == Money::Currency.new(:usd)
32
- end
33
-
34
- specify "#eql? should return true if #== returns true" do
35
- Money::Currency.new(:eur).eql?(Money::Currency.new(:eur)).should be true
36
- Money::Currency.new(:eur).eql?(Money::Currency.new(:usd)).should be false
37
- end
38
-
39
- specify "#hash should return the same value for equal objects" do
40
- Money::Currency.new(:eur).hash.should == Money::Currency.new(:eur).hash
41
- Money::Currency.new(:eur).hash.should_not == Money::Currency.new(:usd).hash
42
- end
43
-
44
- specify "#hash can be used to return the intersection of Currency object arrays" do
45
- intersection = [Money::Currency.new(:eur), Money::Currency.new(:usd)] & [Money::Currency.new(:eur)]
46
- intersection.should == [Money::Currency.new(:eur)]
47
- end
48
-
49
- specify "#<=> should compare objects by priority" do
50
- Money::Currency.new(:cad).should > Money::Currency.new(:usd)
51
- Money::Currency.new(:usd).should < Money::Currency.new(:eur)
52
- end
53
-
54
- specify "#to_s" do
55
- Money::Currency.new(:usd).to_s.should == "USD"
56
- Money::Currency.new(:eur).to_s.should == "EUR"
57
- end
58
-
59
- specify "#to_currency" do
60
- usd = Money::Currency.new(:usd)
61
- usd.to_currency.should == usd
62
- end
63
-
64
- specify "#inspect" do
65
- Money::Currency.new(:usd).inspect.should ==
66
- %Q{#<Money::Currency id: usd, priority: 1, symbol_first: true, thousands_separator: ,, html_entity: $, decimal_mark: ., name: United States Dollar, symbol: $, subunit_to_unit: 100, iso_code: USD, iso_numeric: 840, subunit: Cent>}
67
- end
68
-
69
-
70
- specify "#self.find should return currency matching given id" do
71
- with_custom_definitions do
72
- Money::Currency::TABLE[:usd] = JSON.parse(%Q({ "priority": 1, "iso_code": "USD", "iso_numeric": "840", "name": "United States Dollar", "symbol": "$", "subunit": "Cent", "subunit_to_unit": 100, "symbol_first": true, "html_entity": "$", "decimal_mark": ".", "thousands_separator": "," }))
73
- Money::Currency::TABLE[:eur] = JSON.parse(%Q({ "priority": 2, "iso_code": "EUR", "iso_numeric": "978", "name": "Euro", "symbol": "€", "subunit": "Cent", "subunit_to_unit": 100, "symbol_first": false, "html_entity": "&#x20AC;", "decimal_mark": ",", "thousands_separator": "." }))
74
-
75
- expected = Money::Currency.new(:eur)
76
- Money::Currency.find(:eur).should == expected
77
- Money::Currency.find(:EUR).should == expected
78
- Money::Currency.find("eur").should == expected
79
- Money::Currency.find("EUR").should == expected
80
- end
81
- end
82
-
83
- specify "#self.find should return nil unless currency matching given id" do
84
- Money::Currency.find("ZZZ").should be_nil
85
- end
86
-
87
- specify "#self.wrap should return nil if object is nil" do
88
- Money::Currency.wrap(nil).should == nil
89
- Money::Currency.wrap(Money::Currency.new(:usd)).should == Money::Currency.new(:usd)
90
- Money::Currency.wrap(:usd).should == Money::Currency.new(:usd)
91
- end
92
-
93
-
94
- def with_custom_definitions(&block)
95
- begin
96
- old = Money::Currency::TABLE.dup
97
- Money::Currency::TABLE.clear
98
- yield
99
- ensure
100
- silence_warnings do
101
- Money::Currency.const_set("TABLE", old)
102
- end
103
- end
104
- end
105
-
106
- # Sets $VERBOSE to nil for the duration of the block and back to its original value afterwards.
107
- #
108
- # silence_warnings do
109
- # value = noisy_call # no warning voiced
110
- # end
111
- #
112
- # noisy_call # warning voiced
113
- def silence_warnings
114
- old_verbose, $VERBOSE = $VERBOSE, nil
115
- yield
116
- ensure
117
- $VERBOSE = old_verbose
118
- end
119
-
120
- end
1
+ # encoding: utf-8
2
+
3
+ require "spec_helper"
4
+
5
+ describe Money::Currency do
6
+
7
+ describe ".find" do
8
+ it "returns currency matching given id" do
9
+ with_custom_definitions do
10
+ Money::Currency::TABLE[:usd] = JSON.parse(%Q({ "priority": 1, "iso_code": "USD", "iso_numeric": "840", "name": "United States Dollar", "symbol": "$", "subunit": "Cent", "subunit_to_unit": 100, "symbol_first": true, "html_entity": "$", "decimal_mark": ".", "thousands_separator": "," }))
11
+ Money::Currency::TABLE[:eur] = JSON.parse(%Q({ "priority": 2, "iso_code": "EUR", "iso_numeric": "978", "name": "Euro", "symbol": "€", "subunit": "Cent", "subunit_to_unit": 100, "symbol_first": false, "html_entity": "&#x20AC;", "decimal_mark": ",", "thousands_separator": "." }))
12
+
13
+ expected = Money::Currency.new(:eur)
14
+ Money::Currency.find(:eur).should == expected
15
+ Money::Currency.find(:EUR).should == expected
16
+ Money::Currency.find("eur").should == expected
17
+ Money::Currency.find("EUR").should == expected
18
+ end
19
+ end
20
+
21
+ it "returns nil unless currency matching given id" do
22
+ Money::Currency.find("ZZZ").should be_nil
23
+ end
24
+ end
25
+
26
+ describe ".wrap" do
27
+ it "returns nil if object is nil" do
28
+ Money::Currency.wrap(nil).should == nil
29
+ Money::Currency.wrap(Money::Currency.new(:usd)).should == Money::Currency.new(:usd)
30
+ Money::Currency.wrap(:usd).should == Money::Currency.new(:usd)
31
+ end
32
+ end
33
+
34
+
35
+ describe "#initialize" do
36
+ it "lookups data from loaded config" do
37
+ currency = Money::Currency.new("USD")
38
+ currency.id.should == :usd
39
+ currency.priority.should == 1
40
+ currency.iso_code.should == "USD"
41
+ currency.iso_numeric.should == "840"
42
+ currency.name.should == "United States Dollar"
43
+ currency.decimal_mark.should == "."
44
+ currency.separator.should == "."
45
+ currency.thousands_separator.should == ","
46
+ currency.delimiter.should == ","
47
+ end
48
+
49
+ it "raises UnknownMoney::Currency with unknown currency" do
50
+ lambda { Money::Currency.new("xxx") }.should raise_error(Money::Currency::UnknownCurrency, /xxx/)
51
+ end
52
+ end
53
+
54
+ describe "#<=>" do
55
+ it "compares objects by priority" do
56
+ Money::Currency.new(:cad).should > Money::Currency.new(:usd)
57
+ Money::Currency.new(:usd).should < Money::Currency.new(:eur)
58
+ end
59
+ end
60
+
61
+ describe "#==" do
62
+ it "returns true if self === other" do
63
+ currency = Money::Currency.new(:eur)
64
+ currency.should == currency
65
+ end
66
+
67
+ it "returns true if the id is equal" do
68
+ Money::Currency.new(:eur).should == Money::Currency.new(:eur)
69
+ Money::Currency.new(:eur).should_not == Money::Currency.new(:usd)
70
+ end
71
+ end
72
+
73
+ describe "#eql?" do
74
+ it "returns true if #== returns true" do
75
+ Money::Currency.new(:eur).eql?(Money::Currency.new(:eur)).should be true
76
+ Money::Currency.new(:eur).eql?(Money::Currency.new(:usd)).should be false
77
+ end
78
+ end
79
+
80
+ describe "#hash" do
81
+ it "returns the same value for equal objects" do
82
+ Money::Currency.new(:eur).hash.should == Money::Currency.new(:eur).hash
83
+ Money::Currency.new(:eur).hash.should_not == Money::Currency.new(:usd).hash
84
+ end
85
+
86
+ it "can be used to return the intersection of Currency object arrays" do
87
+ intersection = [Money::Currency.new(:eur), Money::Currency.new(:usd)] & [Money::Currency.new(:eur)]
88
+ intersection.should == [Money::Currency.new(:eur)]
89
+ end
90
+ end
91
+
92
+ describe "#inspect" do
93
+ it "works as documented" do
94
+ Money::Currency.new(:usd).inspect.should ==
95
+ %Q{#<Money::Currency id: usd, priority: 1, symbol_first: true, thousands_separator: ,, html_entity: $, decimal_mark: ., name: United States Dollar, symbol: $, subunit_to_unit: 100, iso_code: USD, iso_numeric: 840, subunit: Cent>}
96
+ end
97
+ end
98
+
99
+ describe "#to_s" do
100
+ it "works as documented" do
101
+ Money::Currency.new(:usd).to_s.should == "USD"
102
+ Money::Currency.new(:eur).to_s.should == "EUR"
103
+ end
104
+ end
105
+
106
+ describe "#to_currency" do
107
+ it "works as documented" do
108
+ usd = Money::Currency.new(:usd)
109
+ usd.to_currency.should == usd
110
+ end
111
+
112
+ it "doesn't create new symbols indefinitely" do
113
+ expect {
114
+ expect { Money::Currency.new("bogus") }.to raise_exception(Money::Currency::UnknownCurrency)
115
+ }.to_not change{ Symbol.all_symbols.size }
116
+ end
117
+ end
118
+
119
+ describe "#code" do
120
+ it "works as documented" do
121
+ Money::Currency.new(:usd).code.should == "$"
122
+ Money::Currency.new(:azn).code.should == "AZN"
123
+ end
124
+ end
125
+
126
+
127
+ def with_custom_definitions(&block)
128
+ begin
129
+ old = Money::Currency::TABLE.dup
130
+ Money::Currency::TABLE.clear
131
+ yield
132
+ ensure
133
+ silence_warnings do
134
+ Money::Currency.const_set("TABLE", old)
135
+ end
136
+ end
137
+ end
138
+
139
+ end