money 6.5.1 → 6.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,320 +2,352 @@
2
2
 
3
3
  require "spec_helper"
4
4
 
5
- describe Money::Currency do
5
+ class Money
6
+ describe Currency do
6
7
 
7
- FOO = '{ "priority": 1, "iso_code": "FOO", "iso_numeric": "840", "name": "United States Dollar", "symbol": "$", "subunit": "Cent", "subunit_to_unit": 450, "symbol_first": true, "html_entity": "$", "decimal_mark": ".", "thousands_separator": ",", "smallest_denomination": 1 }'
8
+ FOO = '{ "priority": 1, "iso_code": "FOO", "iso_numeric": "840", "name": "United States Dollar", "symbol": "$", "subunit": "Cent", "subunit_to_unit": 450, "symbol_first": true, "html_entity": "$", "decimal_mark": ".", "thousands_separator": ",", "smallest_denomination": 1 }'
8
9
 
9
- def register_foo
10
- Money::Currency.register(JSON.parse(FOO, :symbolize_names => true))
11
- end
10
+ def register_foo(opts={})
11
+ foo_attrs = JSON.parse(FOO, :symbolize_names => true)
12
+ # Pass an array of attribute names to 'skip' to remove them from the 'FOO'
13
+ # json before registering foo as a currency.
14
+ Array(opts[:skip]).each { |attr| foo_attrs.delete(attr) }
15
+ Money::Currency.register(foo_attrs)
16
+ end
12
17
 
13
- def unregister_foo
14
- Money::Currency.unregister(JSON.parse(FOO, :symbolize_names => true))
15
- end
18
+ def unregister_foo
19
+ Currency.unregister(JSON.parse(FOO, :symbolize_names => true))
20
+ end
16
21
 
17
- describe "UnknownMoney::Currency" do
18
- it "is a subclass of ArgumentError" do
19
- expect(Money::Currency::UnknownCurrency < ArgumentError).to be true
22
+ describe "UnknownCurrency" do
23
+ it "is a subclass of ArgumentError" do
24
+ expect(Currency::UnknownCurrency < ArgumentError).to be true
25
+ end
20
26
  end
21
- end
22
27
 
23
- describe ".find" do
24
- before { register_foo }
25
- after { unregister_foo }
28
+ describe ".find" do
29
+ before { register_foo }
30
+ after { unregister_foo }
26
31
 
27
- it "returns currency matching given id" do
28
- expected = Money::Currency.new(:foo)
29
- expect(Money::Currency.find(:foo)).to eq expected
30
- expect(Money::Currency.find(:FOO)).to eq expected
31
- expect(Money::Currency.find("foo")).to eq expected
32
- expect(Money::Currency.find("FOO")).to eq expected
33
- end
32
+ it "returns currency matching given id" do
33
+ expected = Currency.new(:foo)
34
+ expect(Currency.find(:foo)).to be expected
35
+ expect(Currency.find(:FOO)).to be expected
36
+ expect(Currency.find("foo")).to be expected
37
+ expect(Currency.find("FOO")).to be expected
38
+ end
34
39
 
35
- it "returns nil unless currency matching given id" do
36
- expect(Money::Currency.find("ZZZ")).to be_nil
40
+ it "returns nil unless currency matching given id" do
41
+ expect(Currency.find("ZZZ")).to be_nil
42
+ end
37
43
  end
38
- end
39
44
 
40
- describe ".find_by_iso_numeric" do
41
- it "returns currency matching given numeric code" do
42
- expect(Money::Currency.find_by_iso_numeric(978)).to eq Money::Currency.new(:eur)
43
- expect(Money::Currency.find_by_iso_numeric(208)).not_to eq Money::Currency.new(:eur)
44
- expect(Money::Currency.find_by_iso_numeric('840')).to eq Money::Currency.new(:usd)
45
+ describe ".find_by_iso_numeric" do
46
+ it "returns currency matching given numeric code" do
47
+ expect(Currency.find_by_iso_numeric(978)).to eq Currency.new(:eur)
48
+ expect(Currency.find_by_iso_numeric(208)).not_to eq Currency.new(:eur)
49
+ expect(Currency.find_by_iso_numeric('840')).to eq Currency.new(:usd)
45
50
 
46
- class Mock
47
- def to_s
48
- '208'
51
+ class Mock
52
+ def to_s
53
+ '208'
54
+ end
49
55
  end
56
+ expect(Currency.find_by_iso_numeric(Mock.new)).to eq Currency.new(:dkk)
57
+ expect(Currency.find_by_iso_numeric(Mock.new)).not_to eq Currency.new(:usd)
50
58
  end
51
- expect(Money::Currency.find_by_iso_numeric(Mock.new)).to eq Money::Currency.new(:dkk)
52
- expect(Money::Currency.find_by_iso_numeric(Mock.new)).not_to eq Money::Currency.new(:usd)
53
- end
54
59
 
55
- it "returns nil if no currency has the given numeric code" do
56
- expect(Money::Currency.find_by_iso_numeric('non iso 4217 numeric code')).to be_nil
57
- expect(Money::Currency.find_by_iso_numeric(0)).to be_nil
60
+ it "returns nil if no currency has the given numeric code" do
61
+ expect(Currency.find_by_iso_numeric('non iso 4217 numeric code')).to be_nil
62
+ expect(Currency.find_by_iso_numeric(0)).to be_nil
63
+ end
58
64
  end
59
- end
60
65
 
61
- describe ".wrap" do
62
- it "returns nil if object is nil" do
63
- expect(Money::Currency.wrap(nil)).to be_nil
64
- expect(Money::Currency.wrap(Money::Currency.new(:usd))).to eq Money::Currency.new(:usd)
65
- expect(Money::Currency.wrap(:usd)).to eq Money::Currency.new(:usd)
66
+ describe ".wrap" do
67
+ it "returns nil if object is nil" do
68
+ expect(Currency.wrap(nil)).to be_nil
69
+ expect(Currency.wrap(Currency.new(:usd))).to eq Currency.new(:usd)
70
+ expect(Currency.wrap(:usd)).to eq Currency.new(:usd)
71
+ end
66
72
  end
67
- end
68
73
 
69
- describe ".all" do
70
- it "returns an array of currencies" do
71
- expect(Money::Currency.all).to include Money::Currency.new(:usd)
72
- end
73
- it "includes registered currencies" do
74
- register_foo
75
- expect(Money::Currency.all).to include Money::Currency.new(:foo)
76
- unregister_foo
77
- end
78
- it 'is sorted by priority' do
79
- expect(Money::Currency.all.first.priority).to eq 1
74
+ describe ".all" do
75
+ it "returns an array of currencies" do
76
+ expect(Currency.all).to include Currency.new(:usd)
77
+ end
78
+ it "includes registered currencies" do
79
+ register_foo
80
+ expect(Currency.all).to include Currency.new(:foo)
81
+ unregister_foo
82
+ end
83
+ it 'is sorted by priority' do
84
+ expect(Currency.all.first.priority).to eq 1
85
+ end
86
+ it "raises a MissingAttributeError if any currency has no priority" do
87
+ register_foo(:skip => :priority)
88
+
89
+ expect{Money::Currency.all}.to \
90
+ raise_error(Money::Currency::MissingAttributeError, /foo.*priority/)
91
+ unregister_foo
92
+ end
80
93
  end
81
- end
82
94
 
83
95
 
84
- describe ".register" do
85
- after { Money::Currency.unregister(iso_code: "XXX") if Money::Currency.find("XXX") }
86
-
87
- it "registers a new currency" do
88
- Money::Currency.register(
89
- iso_code: "XXX",
90
- name: "Golden Doubloon",
91
- symbol: "%",
92
- subunit_to_unit: 100
93
- )
94
- new_currency = Money::Currency.find("XXX")
95
- expect(new_currency).not_to be_nil
96
- expect(new_currency.name).to eq "Golden Doubloon"
97
- expect(new_currency.symbol).to eq "%"
98
- end
96
+ describe ".register" do
97
+ after { Currency.unregister(iso_code: "XXX") if Currency.find("XXX") }
98
+
99
+ it "registers a new currency" do
100
+ Currency.register(
101
+ iso_code: "XXX",
102
+ name: "Golden Doubloon",
103
+ symbol: "%",
104
+ subunit_to_unit: 100
105
+ )
106
+ new_currency = Currency.find("XXX")
107
+ expect(new_currency).not_to be_nil
108
+ expect(new_currency.name).to eq "Golden Doubloon"
109
+ expect(new_currency.symbol).to eq "%"
110
+ end
99
111
 
100
- specify ":iso_code must be present" do
101
- expect {
102
- Money::Currency.register(name: "New Currency")
103
- }.to raise_error(KeyError)
112
+ specify ":iso_code must be present" do
113
+ expect {
114
+ Currency.register(name: "New Currency")
115
+ }.to raise_error(KeyError)
116
+ end
104
117
  end
105
- end
106
118
 
107
119
 
108
- describe ".unregister" do
109
- it "unregisters a currency" do
110
- Money::Currency.register(iso_code: "XXX")
111
- expect(Money::Currency.find("XXX")).not_to be_nil # Sanity check
112
- Money::Currency.unregister(iso_code: "XXX")
113
- expect(Money::Currency.find("XXX")).to be_nil
114
- end
120
+ describe ".unregister" do
121
+ it "unregisters a currency" do
122
+ Currency.register(iso_code: "XXX")
123
+ expect(Currency.find("XXX")).not_to be_nil # Sanity check
124
+ Currency.unregister(iso_code: "XXX")
125
+ expect(Currency.find("XXX")).to be_nil
126
+ end
115
127
 
116
- it "returns true iff the currency existed" do
117
- Money::Currency.register(iso_code: "XXX")
118
- expect(Money::Currency.unregister(iso_code: "XXX")).to be_truthy
119
- expect(Money::Currency.unregister(iso_code: "XXX")).to be_falsey
120
- end
128
+ it "returns true iff the currency existed" do
129
+ Currency.register(iso_code: "XXX")
130
+ expect(Currency.unregister(iso_code: "XXX")).to be_truthy
131
+ expect(Currency.unregister(iso_code: "XXX")).to be_falsey
132
+ end
121
133
 
122
- it "can be passed an ISO code" do
123
- Money::Currency.register(iso_code: "XXX")
124
- Money::Currency.register(iso_code: "YYZ")
125
- # Test with string:
126
- Money::Currency.unregister("XXX")
127
- expect(Money::Currency.find("XXX")).to be_nil
128
- # Test with symbol:
129
- Money::Currency.unregister(:yyz)
130
- expect(Money::Currency.find(:yyz)).to be_nil
134
+ it "can be passed an ISO code" do
135
+ Currency.register(iso_code: "XXX")
136
+ Currency.register(iso_code: "YYZ")
137
+ # Test with string:
138
+ Currency.unregister("XXX")
139
+ expect(Currency.find("XXX")).to be_nil
140
+ # Test with symbol:
141
+ Currency.unregister(:yyz)
142
+ expect(Currency.find(:yyz)).to be_nil
143
+ end
131
144
  end
132
- end
133
145
 
134
146
 
135
- describe ".each" do
136
- it "yields each currency to the block" do
137
- expect(Money::Currency).to respond_to(:each)
138
- currencies = []
139
- Money::Currency.each do |currency|
140
- currencies.push(currency)
147
+ describe ".each" do
148
+ it "yields each currency to the block" do
149
+ expect(Currency).to respond_to(:each)
150
+ currencies = []
151
+ Currency.each do |currency|
152
+ currencies.push(currency)
153
+ end
154
+
155
+ # Don't bother testing every single currency
156
+ expect(currencies[0]).to eq Currency.all[0]
157
+ expect(currencies[1]).to eq Currency.all[1]
158
+ expect(currencies[-1]).to eq Currency.all[-1]
141
159
  end
160
+ end
161
+
142
162
 
143
- # Don't bother testing every single currency
144
- expect(currencies[0]).to eq Money::Currency.all[0]
145
- expect(currencies[1]).to eq Money::Currency.all[1]
146
- expect(currencies[-1]).to eq Money::Currency.all[-1]
163
+ it "implements Enumerable" do
164
+ expect(Currency).to respond_to(:all?)
165
+ expect(Currency).to respond_to(:each_with_index)
166
+ expect(Currency).to respond_to(:map)
167
+ expect(Currency).to respond_to(:select)
168
+ expect(Currency).to respond_to(:reject)
147
169
  end
148
- end
149
170
 
150
171
 
151
- it "implements Enumerable" do
152
- expect(Money::Currency).to respond_to(:all?)
153
- expect(Money::Currency).to respond_to(:each_with_index)
154
- expect(Money::Currency).to respond_to(:map)
155
- expect(Money::Currency).to respond_to(:select)
156
- expect(Money::Currency).to respond_to(:reject)
157
- end
172
+ describe "#initialize" do
173
+ before { Currency.instances.clear }
174
+ it "lookups data from loaded config" do
175
+ currency = Currency.new("USD")
176
+ expect(currency.id).to eq :usd
177
+ expect(currency.priority).to eq 1
178
+ expect(currency.iso_code).to eq "USD"
179
+ expect(currency.iso_numeric).to eq "840"
180
+ expect(currency.name).to eq "United States Dollar"
181
+ expect(currency.decimal_mark).to eq "."
182
+ expect(currency.separator).to eq "."
183
+ expect(currency.thousands_separator).to eq ","
184
+ expect(currency.delimiter).to eq ","
185
+ expect(currency.smallest_denomination).to eq 1
186
+ end
158
187
 
188
+ it "raises UnknownCurrency with unknown currency" do
189
+ expect { Currency.new("xxx") }.to raise_error(Currency::UnknownCurrency, /xxx/)
190
+ end
159
191
 
160
- describe "#initialize" do
161
- it "lookups data from loaded config" do
162
- currency = Money::Currency.new("USD")
163
- expect(currency.id).to eq :usd
164
- expect(currency.priority).to eq 1
165
- expect(currency.iso_code).to eq "USD"
166
- expect(currency.iso_numeric).to eq "840"
167
- expect(currency.name).to eq "United States Dollar"
168
- expect(currency.decimal_mark).to eq "."
169
- expect(currency.separator).to eq "."
170
- expect(currency.thousands_separator).to eq ","
171
- expect(currency.delimiter).to eq ","
172
- expect(currency.smallest_denomination).to eq 1
173
- end
192
+ it 'returns old object for the same :key' do
193
+ expect(Currency.new("USD")).to be(Currency.new("USD"))
194
+ expect(Currency.new("USD")).to be(Currency.new(:usd))
195
+ expect(Currency.new("USD")).to be(Currency.new(:USD))
196
+ expect(Currency.new("USD")).to be(Currency.new('usd'))
197
+ expect(Currency.new("USD")).to be(Currency.new('Usd'))
198
+ end
174
199
 
175
- it "raises UnknownMoney::Currency with unknown currency" do
176
- expect { Money::Currency.new("xxx") }.to raise_error(Money::Currency::UnknownCurrency, /xxx/)
177
- end
178
- end
200
+ it 'returns new object for the different :key' do
201
+ expect(Currency.new("USD")).to_not be(Currency.new("EUR"))
202
+ end
179
203
 
180
- describe "#<=>" do
181
- it "compares objects by priority" do
182
- expect(Money::Currency.new(:cad)).to be > Money::Currency.new(:usd)
183
- expect(Money::Currency.new(:usd)).to be < Money::Currency.new(:eur)
204
+ it 'is thread safe' do
205
+ ids = []
206
+ 2.times.map{ Thread.new{ ids << Currency.new("USD").object_id }}.each(&:join)
207
+ expect(ids.uniq.length).to eq(1)
208
+ end
184
209
  end
185
210
 
186
- it "compares by id when priority is the same" do
187
- Money::Currency.register(iso_code: "ABD", priority: 15)
188
- Money::Currency.register(iso_code: "ABC", priority: 15)
189
- Money::Currency.register(iso_code: "ABE", priority: 15)
190
- abd = Money::Currency.find("ABD")
191
- abc = Money::Currency.find("ABC")
192
- abe = Money::Currency.find("ABE")
193
- expect(abd).to be > abc
194
- expect(abe).to be > abd
195
- Money::Currency.unregister("ABD")
196
- Money::Currency.unregister("ABC")
197
- Money::Currency.unregister("ABE")
198
- end
211
+ describe "#<=>" do
212
+ it "compares objects by priority" do
213
+ expect(Currency.new(:cad)).to be > Currency.new(:usd)
214
+ expect(Currency.new(:usd)).to be < Currency.new(:eur)
215
+ end
199
216
 
200
- context "when one of the currencies has no 'priority' set" do
201
- it "compares by id" do
202
- Money::Currency.register(iso_code: "ABD") # No priority
203
- abd = Money::Currency.find(:abd)
204
- usd = Money::Currency.find(:usd)
205
- expect(abd).to be < usd
206
- Money::Currency.unregister(iso_code: "ABD")
217
+ it "compares by id when priority is the same" do
218
+ Currency.register(iso_code: "ABD", priority: 15)
219
+ Currency.register(iso_code: "ABC", priority: 15)
220
+ Currency.register(iso_code: "ABE", priority: 15)
221
+ abd = Currency.find("ABD")
222
+ abc = Currency.find("ABC")
223
+ abe = Currency.find("ABE")
224
+ expect(abd).to be > abc
225
+ expect(abe).to be > abd
226
+ Currency.unregister("ABD")
227
+ Currency.unregister("ABC")
228
+ Currency.unregister("ABE")
207
229
  end
208
- end
209
- end
210
230
 
211
- describe "#==" do
212
- it "returns true if self === other" do
213
- currency = Money::Currency.new(:eur)
214
- expect(currency).to eq currency
231
+ context "when one of the currencies has no 'priority' set" do
232
+ it "compares by id" do
233
+ Currency.register(iso_code: "ABD") # No priority
234
+ abd = Currency.find(:abd)
235
+ usd = Currency.find(:usd)
236
+ expect(abd).to be < usd
237
+ Currency.unregister(iso_code: "ABD")
238
+ end
239
+ end
215
240
  end
216
241
 
217
- it "returns true if the id is equal ignorning case" do
218
- expect(Money::Currency.new(:eur)).to eq Money::Currency.new(:eur)
219
- expect(Money::Currency.new(:eur)).to eq Money::Currency.new(:EUR)
220
- expect(Money::Currency.new(:eur)).not_to eq Money::Currency.new(:usd)
221
- end
242
+ describe "#==" do
243
+ it "returns true if self === other" do
244
+ currency = Currency.new(:eur)
245
+ expect(currency).to eq currency
246
+ end
222
247
 
223
- it "allows direct comparison of currencies and symbols/strings" do
224
- expect(Money::Currency.new(:eur)).to eq 'eur'
225
- expect(Money::Currency.new(:eur)).to eq 'EUR'
226
- expect(Money::Currency.new(:eur)).to eq :eur
227
- expect(Money::Currency.new(:eur)).to eq :EUR
228
- expect(Money::Currency.new(:eur)).not_to eq 'usd'
229
- end
248
+ it "returns true if the id is equal ignorning case" do
249
+ expect(Currency.new(:eur)).to eq Currency.new(:eur)
250
+ expect(Currency.new(:eur)).to eq Currency.new(:EUR)
251
+ expect(Currency.new(:eur)).not_to eq Currency.new(:usd)
252
+ end
230
253
 
231
- it "allows comparison with nil and returns false" do
232
- expect(Money::Currency.new(:eur)).not_to be_nil
233
- end
234
- end
254
+ it "allows direct comparison of currencies and symbols/strings" do
255
+ expect(Currency.new(:eur)).to eq 'eur'
256
+ expect(Currency.new(:eur)).to eq 'EUR'
257
+ expect(Currency.new(:eur)).to eq :eur
258
+ expect(Currency.new(:eur)).to eq :EUR
259
+ expect(Currency.new(:eur)).not_to eq 'usd'
260
+ end
235
261
 
236
- describe "#eql?" do
237
- it "returns true if #== returns true" do
238
- expect(Money::Currency.new(:eur).eql?(Money::Currency.new(:eur))).to be true
239
- expect(Money::Currency.new(:eur).eql?(Money::Currency.new(:usd))).to be false
262
+ it "allows comparison with nil and returns false" do
263
+ expect(Currency.new(:eur)).not_to be_nil
264
+ end
240
265
  end
241
- end
242
266
 
243
- describe "#hash" do
244
- it "returns the same value for equal objects" do
245
- expect(Money::Currency.new(:eur).hash).to eq Money::Currency.new(:eur).hash
246
- expect(Money::Currency.new(:eur).hash).not_to eq Money::Currency.new(:usd).hash
267
+ describe "#eql?" do
268
+ it "returns true if #== returns true" do
269
+ expect(Currency.new(:eur).eql?(Currency.new(:eur))).to be true
270
+ expect(Currency.new(:eur).eql?(Currency.new(:usd))).to be false
271
+ end
247
272
  end
248
273
 
249
- it "can be used to return the intersection of Currency object arrays" do
250
- intersection = [Money::Currency.new(:eur), Money::Currency.new(:usd)] & [Money::Currency.new(:eur)]
251
- expect(intersection).to eq [Money::Currency.new(:eur)]
252
- end
253
- end
274
+ describe "#hash" do
275
+ it "returns the same value for equal objects" do
276
+ expect(Currency.new(:eur).hash).to eq Currency.new(:eur).hash
277
+ expect(Currency.new(:eur).hash).not_to eq Currency.new(:usd).hash
278
+ end
254
279
 
255
- describe "#inspect" do
256
- it "works as documented" do
257
- expect(Money::Currency.new(:usd).inspect).to eq %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, exponent: 2.0, iso_code: USD, iso_numeric: 840, subunit: Cent, smallest_denomination: 1>}
280
+ it "can be used to return the intersection of Currency object arrays" do
281
+ intersection = [Currency.new(:eur), Currency.new(:usd)] & [Currency.new(:eur)]
282
+ expect(intersection).to eq [Currency.new(:eur)]
283
+ end
258
284
  end
259
- end
260
285
 
261
- describe "#to_s" do
262
- it "works as documented" do
263
- expect(Money::Currency.new(:usd).to_s).to eq("USD")
264
- expect(Money::Currency.new(:eur).to_s).to eq("EUR")
286
+ describe "#inspect" do
287
+ it "works as documented" do
288
+ expect(Currency.new(:usd).inspect).to eq %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, exponent: 2.0, iso_code: USD, iso_numeric: 840, subunit: Cent, smallest_denomination: 1>}
289
+ end
265
290
  end
266
- end
267
291
 
268
- describe "#to_str" do
269
- it "works as documented" do
270
- expect(Money::Currency.new(:usd).to_str).to eq("USD")
271
- expect(Money::Currency.new(:eur).to_str).to eq("EUR")
292
+ describe "#to_s" do
293
+ it "works as documented" do
294
+ expect(Currency.new(:usd).to_s).to eq("USD")
295
+ expect(Currency.new(:eur).to_s).to eq("EUR")
296
+ end
272
297
  end
273
- end
274
298
 
275
- describe "#to_sym" do
276
- it "works as documented" do
277
- expect(Money::Currency.new(:usd).to_sym).to eq(:USD)
278
- expect(Money::Currency.new(:eur).to_sym).to eq(:EUR)
299
+ describe "#to_str" do
300
+ it "works as documented" do
301
+ expect(Currency.new(:usd).to_str).to eq("USD")
302
+ expect(Currency.new(:eur).to_str).to eq("EUR")
303
+ end
279
304
  end
280
- end
281
305
 
282
- describe "#to_currency" do
283
- it "works as documented" do
284
- usd = Money::Currency.new(:usd)
285
- expect(usd.to_currency).to eq usd
306
+ describe "#to_sym" do
307
+ it "works as documented" do
308
+ expect(Currency.new(:usd).to_sym).to eq(:USD)
309
+ expect(Currency.new(:eur).to_sym).to eq(:EUR)
310
+ end
286
311
  end
287
312
 
288
- it "doesn't create new symbols indefinitely" do
289
- expect { Money::Currency.new("bogus") }.to raise_exception(Money::Currency::UnknownCurrency)
290
- expect(Symbol.all_symbols.map{|s| s.to_s}).not_to include("bogus")
291
- end
292
- end
313
+ describe "#to_currency" do
314
+ it "works as documented" do
315
+ usd = Currency.new(:usd)
316
+ expect(usd.to_currency).to eq usd
317
+ end
293
318
 
294
- describe "#code" do
295
- it "works as documented" do
296
- expect(Money::Currency.new(:usd).code).to eq "$"
297
- expect(Money::Currency.new(:azn).code).to eq "\u20BC"
319
+ it "doesn't create new symbols indefinitely" do
320
+ expect { Currency.new("bogus") }.to raise_exception(Currency::UnknownCurrency)
321
+ expect(Symbol.all_symbols.map{|s| s.to_s}).not_to include("bogus")
322
+ end
298
323
  end
299
- end
300
324
 
301
- describe "#exponent" do
302
- it "conforms to iso 4217" do
303
- Money::Currency.new(:jpy).exponent == 0
304
- Money::Currency.new(:usd).exponent == 2
305
- Money::Currency.new(:iqd).exponent == 3
325
+ describe "#code" do
326
+ it "works as documented" do
327
+ expect(Currency.new(:usd).code).to eq "$"
328
+ expect(Currency.new(:azn).code).to eq "\u20BC"
329
+ end
306
330
  end
307
- end
308
331
 
309
- describe "#decimal_places" do
310
- it "proper places for known currency" do
311
- Money::Currency.new(:mro).decimal_places == 1
312
- Money::Currency.new(:usd).decimal_places == 2
332
+ describe "#exponent" do
333
+ it "conforms to iso 4217" do
334
+ Currency.new(:jpy).exponent == 0
335
+ Currency.new(:usd).exponent == 2
336
+ Currency.new(:iqd).exponent == 3
337
+ end
313
338
  end
314
339
 
315
- it "proper places for custom currency" do
316
- register_foo
317
- Money::Currency.new(:foo).decimal_places == 3
318
- unregister_foo
340
+ describe "#decimal_places" do
341
+ it "proper places for known currency" do
342
+ Currency.new(:mro).decimal_places == 1
343
+ Currency.new(:usd).decimal_places == 2
344
+ end
345
+
346
+ it "proper places for custom currency" do
347
+ register_foo
348
+ Currency.new(:foo).decimal_places == 3
349
+ unregister_foo
350
+ end
319
351
  end
320
352
  end
321
353
  end