money 6.1.1 → 6.2.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.
@@ -9,10 +9,15 @@ describe Money, "formatting" do
9
9
  EU4 = '{ "priority": 1, "iso_code": "EU4", "iso_numeric": "841", "name": "Euro with 4 decimal places", "symbol": "€", "subunit": "Cent", "subunit_to_unit": 10000, "symbol_first": true, "html_entity": "€", "decimal_mark": ",", "thousands_separator": "." }'
10
10
 
11
11
  context "without i18n" do
12
- subject { Money.empty("USD") }
12
+ subject(:money) { Money.empty("USD") }
13
13
 
14
- its(:thousands_separator) { should == "," }
15
- its(:decimal_mark) { should == "." }
14
+ it "should use ',' as the thousands separator" do
15
+ expect(money.thousands_separator).to eq ','
16
+ end
17
+
18
+ it "should use '.' as the decimal mark" do
19
+ expect(money.decimal_mark).to eq '.'
20
+ end
16
21
  end
17
22
 
18
23
  context "with i18n but use_i18n = false" do
@@ -32,10 +37,15 @@ describe Money, "formatting" do
32
37
  Money.use_i18n = true
33
38
  end
34
39
 
35
- subject { Money.empty("USD") }
40
+ subject(:money) { Money.empty("USD") }
36
41
 
37
- its(:thousands_separator) { should == "," }
38
- its(:decimal_mark) { should == "." }
42
+ it "should use ',' as the thousands separator" do
43
+ expect(money.thousands_separator).to eq ','
44
+ end
45
+
46
+ it "should use '.' as the decimal mark" do
47
+ expect(money.decimal_mark).to eq '.'
48
+ end
39
49
  end
40
50
 
41
51
  context "with i18n" do
@@ -54,10 +64,15 @@ describe Money, "formatting" do
54
64
  )
55
65
  end
56
66
 
57
- subject { Money.empty("USD") }
67
+ subject(:money) { Money.empty("USD") }
58
68
 
59
- its(:thousands_separator) { should == "." }
60
- its(:decimal_mark) { should == "," }
69
+ it "should use '.' as the thousands separator" do
70
+ expect(money.thousands_separator).to eq '.'
71
+ end
72
+
73
+ it "should use ',' as the decimal mark" do
74
+ expect(money.decimal_mark).to eq ','
75
+ end
61
76
  end
62
77
 
63
78
  context "with number.currency.format.*" do
@@ -70,10 +85,15 @@ describe Money, "formatting" do
70
85
  )
71
86
  end
72
87
 
73
- subject { Money.empty("USD") }
88
+ subject(:money) { Money.empty("USD") }
89
+
90
+ it "should use '.' as the thousands separator" do
91
+ expect(money.thousands_separator).to eq '.'
92
+ end
74
93
 
75
- its(:thousands_separator) { should == "." }
76
- its(:decimal_mark) { should == "," }
94
+ it "should use ',' as the decimal mark" do
95
+ expect(money.decimal_mark).to eq ','
96
+ end
77
97
  end
78
98
  end
79
99
 
@@ -83,24 +103,24 @@ describe Money, "formatting" do
83
103
 
84
104
  it "formats Japanese currency in Japanese properly" do
85
105
  money = Money.new(1000, "JPY")
86
- money.format.should == "1,000円"
87
- money.format(:symbol => false).should == "1,000"
106
+ expect(money.format).to eq "1,000円"
107
+ expect(money.format(:symbol => false)).to eq "1,000"
88
108
  end
89
109
 
90
110
  after { I18n.locale = @_locale }
91
111
  end
92
112
 
93
113
  it "returns the monetary value as a string" do
94
- Money.ca_dollar(100).format.should == "$1.00"
95
- Money.new(40008).format.should == "$400.08"
114
+ expect(Money.ca_dollar(100).format).to eq "$1.00"
115
+ expect(Money.new(40008).format).to eq "$400.08"
96
116
  end
97
117
 
98
118
  it "respects :subunit_to_unit currency property" do
99
- Money.new(10_00, "BHD").format.should == "ب.د1.000"
119
+ expect(Money.new(10_00, "BHD").format).to eq "ب.د1.000"
100
120
  end
101
121
 
102
122
  it "does not display a decimal when :subunit_to_unit is 1" do
103
- Money.new(10_00, "CLP").format.should == "$1.000"
123
+ expect(Money.new(10_00, "CLP").format).to eq "$1.000"
104
124
  end
105
125
 
106
126
  it "respects the thousands_separator and decimal_mark defaults" do
@@ -109,109 +129,109 @@ describe Money, "formatting" do
109
129
  end
110
130
 
111
131
  # Pounds
112
- one_thousand["GBP"].should == "£1,000.00"
132
+ expect(one_thousand["GBP"]).to eq "£1,000.00"
113
133
 
114
134
  # Dollars
115
- one_thousand["USD"].should == "$1,000.00"
116
- one_thousand["CAD"].should == "$1,000.00"
117
- one_thousand["AUD"].should == "$1,000.00"
118
- one_thousand["NZD"].should == "$1,000.00"
119
- one_thousand["ZWD"].should == "$1,000.00"
135
+ expect(one_thousand["USD"]).to eq "$1,000.00"
136
+ expect(one_thousand["CAD"]).to eq "$1,000.00"
137
+ expect(one_thousand["AUD"]).to eq "$1,000.00"
138
+ expect(one_thousand["NZD"]).to eq "$1,000.00"
139
+ expect(one_thousand["ZWD"]).to eq "$1,000.00"
120
140
 
121
141
  # Yen
122
- one_thousand["JPY"].should == "¥100,000"
123
- one_thousand["CNY"].should == "¥1,000.00"
142
+ expect(one_thousand["JPY"]).to eq "¥100,000"
143
+ expect(one_thousand["CNY"]).to eq "¥1,000.00"
124
144
 
125
145
  # Euro
126
- one_thousand["EUR"].should == "€1.000,00"
146
+ expect(one_thousand["EUR"]).to eq "€1.000,00"
127
147
 
128
148
  # Rupees
129
- one_thousand["INR"].should == "₹1,000.00"
130
- one_thousand["NPR"].should == "₨1,000.00"
131
- one_thousand["SCR"].should == "1,000.00 ₨"
132
- one_thousand["LKR"].should == "1,000.00 ₨"
149
+ expect(one_thousand["INR"]).to eq "₹1,000.00"
150
+ expect(one_thousand["NPR"]).to eq "₨1,000.00"
151
+ expect(one_thousand["SCR"]).to eq "1,000.00 ₨"
152
+ expect(one_thousand["LKR"]).to eq "1,000.00 ₨"
133
153
 
134
154
  # Brazilian Real
135
- one_thousand["BRL"].should == "R$1.000,00"
155
+ expect(one_thousand["BRL"]).to eq "R$1.000,00"
136
156
 
137
157
  # Other
138
- one_thousand["SEK"].should == "1 000,00 kr"
139
- one_thousand["GHC"].should == "₵1,000.00"
158
+ expect(one_thousand["SEK"]).to eq "1 000,00 kr"
159
+ expect(one_thousand["GHC"]).to eq "₵1,000.00"
140
160
  end
141
161
 
142
162
  it "inserts commas into the result if the amount is sufficiently large" do
143
- Money.us_dollar(1_000_000_000_12).format.should == "$1,000,000,000.12"
144
- Money.us_dollar(1_000_000_000_12).format(:no_cents => true).should == "$1,000,000,000"
163
+ expect(Money.us_dollar(1_000_000_000_12).format).to eq "$1,000,000,000.12"
164
+ expect(Money.us_dollar(1_000_000_000_12).format(:no_cents => true)).to eq "$1,000,000,000"
145
165
  end
146
166
 
147
167
  it "inserts thousands separator into the result if the amount is sufficiently large and the currency symbol is at the end" do
148
- Money.euro(1_234_567_12).format.should == "€1.234.567,12"
149
- Money.euro(1_234_567_12).format(:no_cents => true).should == "€1.234.567"
168
+ expect(Money.euro(1_234_567_12).format).to eq "€1.234.567,12"
169
+ expect(Money.euro(1_234_567_12).format(:no_cents => true)).to eq "€1.234.567"
150
170
  end
151
171
 
152
172
  describe ":with_currency option" do
153
173
  specify "(:with_currency option => true) works as documented" do
154
- Money.ca_dollar(100).format(:with_currency => true).should == "$1.00 CAD"
155
- Money.us_dollar(85).format(:with_currency => true).should == "$0.85 USD"
174
+ expect(Money.ca_dollar(100).format(:with_currency => true)).to eq "$1.00 CAD"
175
+ expect(Money.us_dollar(85).format(:with_currency => true)).to eq "$0.85 USD"
156
176
  end
157
177
  end
158
178
 
159
179
  describe ":no_cents option" do
160
180
  specify "(:with_currency option => true) works as documented" do
161
- Money.ca_dollar(100).format(:no_cents => true).should == "$1"
162
- Money.ca_dollar(599).format(:no_cents => true).should == "$5"
163
- Money.ca_dollar(570).format(:no_cents => true, :with_currency => true).should == "$5 CAD"
164
- Money.ca_dollar(39000).format(:no_cents => true).should == "$390"
181
+ expect(Money.ca_dollar(100).format(:no_cents => true)).to eq "$1"
182
+ expect(Money.ca_dollar(599).format(:no_cents => true)).to eq "$5"
183
+ expect(Money.ca_dollar(570).format(:no_cents => true, :with_currency => true)).to eq "$5 CAD"
184
+ expect(Money.ca_dollar(39000).format(:no_cents => true)).to eq "$390"
165
185
  end
166
186
 
167
187
  it "respects :subunit_to_unit currency property" do
168
- Money.new(10_00, "BHD").format(:no_cents => true).should == "ب.د1"
188
+ expect(Money.new(10_00, "BHD").format(:no_cents => true)).to eq "ب.د1"
169
189
  end
170
190
 
171
191
  it "inserts thousand separators if symbol contains decimal mark and no_cents is true" do
172
- Money.new(100000000, "AMD").format(:no_cents => true).should == "1,000,000 դր."
173
- Money.new(100000000, "USD").format(:no_cents => true).should == "$1,000,000"
174
- Money.new(100000000, "RUB").format(:no_cents => true).should == "1.000.000 р."
192
+ expect(Money.new(100000000, "AMD").format(:no_cents => true)).to eq "1,000,000 դր."
193
+ expect(Money.new(100000000, "USD").format(:no_cents => true)).to eq "$1,000,000"
194
+ expect(Money.new(100000000, "RUB").format(:no_cents => true)).to eq "1.000.000 р."
175
195
  end
176
196
 
177
197
  it "doesn't incorrectly format HTML" do
178
198
  money = ::Money.new(1999, "RUB")
179
199
  output = money.format(:html => true, :no_cents => true)
180
- output.should == "19 руб"
200
+ expect(output).to eq "19 руб"
181
201
  end
182
202
  end
183
203
 
184
204
  describe ":no_cents_if_whole option" do
185
205
  specify "(:no_cents_if_whole => true) works as documented" do
186
- Money.new(10000, "VUV").format(:no_cents_if_whole => true, :symbol => false).should == "10,000"
187
- Money.new(10034, "VUV").format(:no_cents_if_whole => true, :symbol => false).should == "10,034"
188
- Money.new(10000, "MGA").format(:no_cents_if_whole => true, :symbol => false).should == "2,000"
189
- Money.new(10034, "MGA").format(:no_cents_if_whole => true, :symbol => false).should == "2,006.4"
190
- Money.new(10000, "VND").format(:no_cents_if_whole => true, :symbol => false).should == "1.000"
191
- Money.new(10034, "VND").format(:no_cents_if_whole => true, :symbol => false).should == "1.003,4"
192
- Money.new(10000, "USD").format(:no_cents_if_whole => true, :symbol => false).should == "100"
193
- Money.new(10034, "USD").format(:no_cents_if_whole => true, :symbol => false).should == "100.34"
194
- Money.new(10000, "IQD").format(:no_cents_if_whole => true, :symbol => false).should == "10"
195
- Money.new(10034, "IQD").format(:no_cents_if_whole => true, :symbol => false).should == "10.034"
206
+ expect(Money.new(10000, "VUV").format(:no_cents_if_whole => true, :symbol => false)).to eq "10,000"
207
+ expect(Money.new(10034, "VUV").format(:no_cents_if_whole => true, :symbol => false)).to eq "10,034"
208
+ expect(Money.new(10000, "MGA").format(:no_cents_if_whole => true, :symbol => false)).to eq "2,000"
209
+ expect(Money.new(10034, "MGA").format(:no_cents_if_whole => true, :symbol => false)).to eq "2,006.4"
210
+ expect(Money.new(10000, "VND").format(:no_cents_if_whole => true, :symbol => false)).to eq "1.000"
211
+ expect(Money.new(10034, "VND").format(:no_cents_if_whole => true, :symbol => false)).to eq "1.003,4"
212
+ expect(Money.new(10000, "USD").format(:no_cents_if_whole => true, :symbol => false)).to eq "100"
213
+ expect(Money.new(10034, "USD").format(:no_cents_if_whole => true, :symbol => false)).to eq "100.34"
214
+ expect(Money.new(10000, "IQD").format(:no_cents_if_whole => true, :symbol => false)).to eq "10"
215
+ expect(Money.new(10034, "IQD").format(:no_cents_if_whole => true, :symbol => false)).to eq "10.034"
196
216
  end
197
217
 
198
218
  specify "(:no_cents_if_whole => false) works as documented" do
199
- Money.new(10000, "VUV").format(:no_cents_if_whole => false, :symbol => false).should == "10,000"
200
- Money.new(10034, "VUV").format(:no_cents_if_whole => false, :symbol => false).should == "10,034"
201
- Money.new(10000, "MGA").format(:no_cents_if_whole => false, :symbol => false).should == "2,000.0"
202
- Money.new(10034, "MGA").format(:no_cents_if_whole => false, :symbol => false).should == "2,006.4"
203
- Money.new(10000, "VND").format(:no_cents_if_whole => false, :symbol => false).should == "1.000,0"
204
- Money.new(10034, "VND").format(:no_cents_if_whole => false, :symbol => false).should == "1.003,4"
205
- Money.new(10000, "USD").format(:no_cents_if_whole => false, :symbol => false).should == "100.00"
206
- Money.new(10034, "USD").format(:no_cents_if_whole => false, :symbol => false).should == "100.34"
207
- Money.new(10000, "IQD").format(:no_cents_if_whole => false, :symbol => false).should == "10.000"
208
- Money.new(10034, "IQD").format(:no_cents_if_whole => false, :symbol => false).should == "10.034"
219
+ expect(Money.new(10000, "VUV").format(:no_cents_if_whole => false, :symbol => false)).to eq "10,000"
220
+ expect(Money.new(10034, "VUV").format(:no_cents_if_whole => false, :symbol => false)).to eq "10,034"
221
+ expect(Money.new(10000, "MGA").format(:no_cents_if_whole => false, :symbol => false)).to eq "2,000.0"
222
+ expect(Money.new(10034, "MGA").format(:no_cents_if_whole => false, :symbol => false)).to eq "2,006.4"
223
+ expect(Money.new(10000, "VND").format(:no_cents_if_whole => false, :symbol => false)).to eq "1.000,0"
224
+ expect(Money.new(10034, "VND").format(:no_cents_if_whole => false, :symbol => false)).to eq "1.003,4"
225
+ expect(Money.new(10000, "USD").format(:no_cents_if_whole => false, :symbol => false)).to eq "100.00"
226
+ expect(Money.new(10034, "USD").format(:no_cents_if_whole => false, :symbol => false)).to eq "100.34"
227
+ expect(Money.new(10000, "IQD").format(:no_cents_if_whole => false, :symbol => false)).to eq "10.000"
228
+ expect(Money.new(10034, "IQD").format(:no_cents_if_whole => false, :symbol => false)).to eq "10.034"
209
229
  end
210
230
  end
211
231
 
212
232
  describe ":symbol option" do
213
233
  specify "(:symbol => a symbol string) uses the given value as the money symbol" do
214
- Money.new(100, "GBP").format(:symbol => "£").should == "£1.00"
234
+ expect(Money.new(100, "GBP").format(:symbol => "£")).to eq "£1.00"
215
235
  end
216
236
 
217
237
  specify "(:symbol => true) returns symbol based on the given currency code" do
@@ -220,92 +240,92 @@ describe Money, "formatting" do
220
240
  end
221
241
 
222
242
  # Pounds
223
- one["GBP"].should == "£1.00"
243
+ expect(one["GBP"]).to eq "£1.00"
224
244
 
225
245
  # Dollars
226
- one["USD"].should == "$1.00"
227
- one["CAD"].should == "$1.00"
228
- one["AUD"].should == "$1.00"
229
- one["NZD"].should == "$1.00"
230
- one["ZWD"].should == "$1.00"
246
+ expect(one["USD"]).to eq "$1.00"
247
+ expect(one["CAD"]).to eq "$1.00"
248
+ expect(one["AUD"]).to eq "$1.00"
249
+ expect(one["NZD"]).to eq "$1.00"
250
+ expect(one["ZWD"]).to eq "$1.00"
231
251
 
232
252
  # Yen
233
- one["JPY"].should == "¥100"
234
- one["CNY"].should == "¥1.00"
253
+ expect(one["JPY"]).to eq "¥100"
254
+ expect(one["CNY"]).to eq "¥1.00"
235
255
 
236
256
  # Euro
237
- one["EUR"].should == "€1,00"
257
+ expect(one["EUR"]).to eq "€1,00"
238
258
 
239
259
  # Rupees
240
- one["INR"].should == "₹1.00"
241
- one["NPR"].should == "₨1.00"
242
- one["SCR"].should == "1.00 ₨"
243
- one["LKR"].should == "1.00 ₨"
260
+ expect(one["INR"]).to eq "₹1.00"
261
+ expect(one["NPR"]).to eq "₨1.00"
262
+ expect(one["SCR"]).to eq "1.00 ₨"
263
+ expect(one["LKR"]).to eq "1.00 ₨"
244
264
 
245
265
  # Brazilian Real
246
- one["BRL"].should == "R$1,00"
266
+ expect(one["BRL"]).to eq "R$1,00"
247
267
 
248
268
  # Other
249
- one["SEK"].should == "1,00 kr"
250
- one["GHC"].should == "₵1.00"
269
+ expect(one["SEK"]).to eq "1,00 kr"
270
+ expect(one["GHC"]).to eq "₵1.00"
251
271
  end
252
272
 
253
273
  specify "(:symbol => true) returns $ when currency code is not recognized" do
254
274
  currency = Money::Currency.new("EUR")
255
- currency.should_receive(:symbol).and_return(nil)
256
- Money.new(100, currency).format(:symbol => true).should == "¤1,00"
275
+ expect(currency).to receive(:symbol).and_return(nil)
276
+ expect(Money.new(100, currency).format(:symbol => true)).to eq "¤1,00"
257
277
  end
258
278
 
259
279
  specify "(:symbol => some non-Boolean value that evaluates to true) returns symbol based on the given currency code" do
260
- Money.new(100, "GBP").format(:symbol => true).should == "£1.00"
261
- Money.new(100, "EUR").format(:symbol => true).should == "€1,00"
262
- Money.new(100, "SEK").format(:symbol => true).should == "1,00 kr"
280
+ expect(Money.new(100, "GBP").format(:symbol => true)).to eq "£1.00"
281
+ expect(Money.new(100, "EUR").format(:symbol => true)).to eq "€1,00"
282
+ expect(Money.new(100, "SEK").format(:symbol => true)).to eq "1,00 kr"
263
283
  end
264
284
 
265
285
  specify "(:symbol => "", nil or false) returns the amount without a symbol" do
266
286
  money = Money.new(100, "GBP")
267
- money.format(:symbol => "").should == "1.00"
268
- money.format(:symbol => nil).should == "1.00"
269
- money.format(:symbol => false).should == "1.00"
287
+ expect(money.format(:symbol => "")).to eq "1.00"
288
+ expect(money.format(:symbol => nil)).to eq "1.00"
289
+ expect(money.format(:symbol => false)).to eq "1.00"
270
290
 
271
291
  money = Money.new(100, "JPY")
272
- money.format(:symbol => false).should == "100"
292
+ expect(money.format(:symbol => false)).to eq "100"
273
293
  end
274
294
 
275
295
  it "defaults :symbol to true" do
276
296
  money = Money.new(100)
277
- money.format.should == "$1.00"
297
+ expect(money.format).to eq "$1.00"
278
298
 
279
299
  money = Money.new(100, "GBP")
280
- money.format.should == "£1.00"
300
+ expect(money.format).to eq "£1.00"
281
301
 
282
302
  money = Money.new(100, "EUR")
283
- money.format.should == "€1,00"
303
+ expect(money.format).to eq "€1,00"
284
304
  end
285
305
 
286
306
  specify "(:symbol => false) returns a signed amount without a symbol" do
287
307
  money = Money.new(-100, "EUR")
288
- money.format(:symbol => false).should == "-1,00"
308
+ expect(money.format(:symbol => false)).to eq "-1,00"
289
309
 
290
310
  money = Money.new(100, "EUR")
291
- money.format(:symbol => false,
292
- :sign_positive => true).should == "+1,00"
311
+ expect(money.format(:symbol => false,
312
+ :sign_positive => true)).to eq "+1,00"
293
313
  end
294
314
  end
295
315
 
296
316
  describe ":decimal_mark option" do
297
317
  specify "(:decimal_mark => a decimal_mark string) works as documented" do
298
- Money.us_dollar(100).format(:decimal_mark => ",").should == "$1,00"
318
+ expect(Money.us_dollar(100).format(:decimal_mark => ",")).to eq "$1,00"
299
319
  end
300
320
 
301
321
  it "defaults to '.' if currency isn't recognized" do
302
- Money.new(100, "ZWD").format.should == "$1.00"
322
+ expect(Money.new(100, "ZWD").format).to eq "$1.00"
303
323
  end
304
324
  end
305
325
 
306
326
  describe ":separator option" do
307
327
  specify "(:separator => a separator string) works as documented" do
308
- Money.us_dollar(100).format(:separator => ",").should == "$1,00"
328
+ expect(Money.us_dollar(100).format(:separator => ",")).to eq "$1,00"
309
329
  end
310
330
  end
311
331
 
@@ -319,131 +339,138 @@ describe Money, "formatting" do
319
339
  end
320
340
 
321
341
  specify "(:south_asian_number_formatting => true) works as documented" do
322
- Money.new(10000000, 'INR').format(:south_asian_number_formatting => true, :symbol => false).should == "1,00,000.00"
323
- Money.new(1000000000, 'INDIAN_BAR').format(:south_asian_number_formatting => true, :symbol => false).should == "1,00,000.0000"
324
- Money.new(10000000).format(:south_asian_number_formatting => true).should == "$1,00,000.00"
342
+ expect(Money.new(10000000, 'INR').format(:south_asian_number_formatting => true, :symbol => false)).to eq "1,00,000.00"
343
+ expect(Money.new(1000000000, 'INDIAN_BAR').format(:south_asian_number_formatting => true, :symbol => false)).to eq "1,00,000.0000"
344
+ expect(Money.new(10000000).format(:south_asian_number_formatting => true)).to eq "$1,00,000.00"
325
345
  end
326
346
  end
327
347
 
328
348
  describe ":thousands_separator option" do
329
349
  specify "(:thousands_separator => a thousands_separator string) works as documented" do
330
- Money.us_dollar(100000).format(:thousands_separator => ".").should == "$1.000.00"
331
- Money.us_dollar(200000).format(:thousands_separator => "").should == "$2000.00"
350
+ expect(Money.us_dollar(100000).format(:thousands_separator => ".")).to eq "$1.000.00"
351
+ expect(Money.us_dollar(200000).format(:thousands_separator => "")).to eq "$2000.00"
332
352
  end
333
353
 
334
354
  specify "(:thousands_separator => false or nil) works as documented" do
335
- Money.us_dollar(100000).format(:thousands_separator => false).should == "$1000.00"
336
- Money.us_dollar(200000).format(:thousands_separator => nil).should == "$2000.00"
355
+ expect(Money.us_dollar(100000).format(:thousands_separator => false)).to eq "$1000.00"
356
+ expect(Money.us_dollar(200000).format(:thousands_separator => nil)).to eq "$2000.00"
337
357
  end
338
358
 
339
359
  specify "(:delimiter => a delimiter string) works as documented" do
340
- Money.us_dollar(100000).format(:delimiter => ".").should == "$1.000.00"
341
- Money.us_dollar(200000).format(:delimiter => "").should == "$2000.00"
360
+ expect(Money.us_dollar(100000).format(:delimiter => ".")).to eq "$1.000.00"
361
+ expect(Money.us_dollar(200000).format(:delimiter => "")).to eq "$2000.00"
342
362
  end
343
363
 
344
364
  specify "(:delimiter => false or nil) works as documented" do
345
- Money.us_dollar(100000).format(:delimiter => false).should == "$1000.00"
346
- Money.us_dollar(200000).format(:delimiter => nil).should == "$2000.00"
365
+ expect(Money.us_dollar(100000).format(:delimiter => false)).to eq "$1000.00"
366
+ expect(Money.us_dollar(200000).format(:delimiter => nil)).to eq "$2000.00"
347
367
  end
348
368
 
349
369
  it "defaults to ',' if currency isn't recognized" do
350
- Money.new(100000, "ZWD").format.should == "$1,000.00"
370
+ expect(Money.new(100000, "ZWD").format).to eq "$1,000.00"
371
+ end
372
+ end
373
+
374
+ describe ":thousands_separator and :decimal_mark option" do
375
+ specify "(:thousands_separator => a thousands_separator string, :decimal_mark => a decimal_mark string) works as documented" do
376
+ expect(Money.new(123_456_789, "USD").format(thousands_separator: ".", decimal_mark: ",")).to eq("$1.234.567,89")
377
+ expect(Money.new(987_654_321, "USD").format(thousands_separator: " ", decimal_mark: ".")).to eq("$9 876 543.21")
351
378
  end
352
379
  end
353
380
 
354
381
  describe ":html option" do
355
382
  specify "(:html => true) works as documented" do
356
383
  string = Money.ca_dollar(570).format(:html => true, :with_currency => true)
357
- string.should == "$5.70 <span class=\"currency\">CAD</span>"
384
+ expect(string).to eq "$5.70 <span class=\"currency\">CAD</span>"
358
385
  end
359
386
 
360
387
  specify "should fallback to symbol if entity is not available" do
361
388
  string = Money.new(570, 'DKK').format(:html => true)
362
- string.should == "5,70 kr"
389
+ expect(string).to eq "5,70 kr"
363
390
  end
364
391
  end
365
392
 
366
393
  describe ":html_wrap_symbol option" do
367
394
  specify "(:html_wrap_symbol => true) works as documented" do
368
395
  string = Money.ca_dollar(570).format(:html_wrap_symbol => true)
369
- string.should == "<span class=\"currency_symbol\">$</span>5.70"
396
+ expect(string).to eq "<span class=\"currency_symbol\">$</span>5.70"
370
397
  end
371
398
  end
372
399
 
373
400
  describe ":symbol_position option" do
374
401
  it "inserts currency symbol before the amount when set to :before" do
375
- Money.euro(1_234_567_12).format(:symbol_position => :before).should == "€1.234.567,12"
402
+ expect(Money.euro(1_234_567_12).format(:symbol_position => :before)).to eq "€1.234.567,12"
376
403
  end
377
404
 
378
405
  it "inserts currency symbol after the amount when set to :after" do
379
- Money.us_dollar(1_000_000_000_12).format(:symbol_position => :after).should == "1,000,000,000.12 $"
406
+ expect(Money.us_dollar(1_000_000_000_12).format(:symbol_position => :after)).to eq "1,000,000,000.12 $"
380
407
  end
381
408
  end
382
409
 
383
410
  describe ":sign_before_symbol option" do
384
411
  specify "(:sign_before_symbol => true) works as documented" do
385
- Money.us_dollar(-100000).format(:sign_before_symbol => true).should == "-$1,000.00"
412
+ expect(Money.us_dollar(-100000).format(:sign_before_symbol => true)).to eq "-$1,000.00"
386
413
  end
387
414
 
388
415
  specify "(:sign_before_symbol => false) works as documented" do
389
- Money.us_dollar(-100000).format(:sign_before_symbol => false).should == "$-1,000.00"
390
- Money.us_dollar(-100000).format(:sign_before_symbol => nil).should == "$-1,000.00"
416
+ expect(Money.us_dollar(-100000).format(:sign_before_symbol => false)).to eq "$-1,000.00"
417
+ expect(Money.us_dollar(-100000).format(:sign_before_symbol => nil)).to eq "$-1,000.00"
391
418
  end
392
419
  end
393
420
 
394
421
  describe ":symbol_before_without_space option" do
395
422
  it "does not insert space between currency symbol and amount when set to true" do
396
- Money.euro(1_234_567_12).format(:symbol_position => :before, :symbol_before_without_space => true).should == "€1.234.567,12"
423
+ expect(Money.euro(1_234_567_12).format(:symbol_position => :before, :symbol_before_without_space => true)).to eq "€1.234.567,12"
397
424
  end
398
425
 
399
426
  it "inserts space between currency symbol and amount when set to false" do
400
- Money.euro(1_234_567_12).format(:symbol_position => :before, :symbol_before_without_space => false).should == "€ 1.234.567,12"
427
+ expect(Money.euro(1_234_567_12).format(:symbol_position => :before, :symbol_before_without_space => false)).to eq "€ 1.234.567,12"
401
428
  end
402
429
 
403
430
  it "defaults to true" do
404
- Money.euro(1_234_567_12).format(:symbol_position => :before).should == "€1.234.567,12"
431
+ expect(Money.euro(1_234_567_12).format(:symbol_position => :before)).to eq "€1.234.567,12"
405
432
  end
406
433
  end
407
434
 
408
435
  describe ":symbol_after_without_space option" do
409
436
  it "does not insert space between amount and currency symbol when set to true" do
410
- Money.euro(1_234_567_12).format(:symbol_position => :after, :symbol_after_without_space => true).should == "1.234.567,12€"
437
+ expect(Money.euro(1_234_567_12).format(:symbol_position => :after, :symbol_after_without_space => true)).to eq "1.234.567,12€"
411
438
  end
412
439
 
413
440
  it "inserts space between amount and currency symbol when set to false" do
414
- Money.euro(1_234_567_12).format(:symbol_position => :after, :symbol_after_without_space => false).should == "1.234.567,12 €"
441
+ expect(Money.euro(1_234_567_12).format(:symbol_position => :after, :symbol_after_without_space => false)).to eq "1.234.567,12 €"
415
442
  end
416
443
 
417
444
  it "defaults to false" do
418
- Money.euro(1_234_567_12).format(:symbol_position => :after).should == "1.234.567,12 €"
445
+ expect(Money.euro(1_234_567_12).format(:symbol_position => :after)).to eq "1.234.567,12 €"
419
446
  end
420
447
  end
421
448
 
422
449
  describe ":sign_positive option" do
423
450
  specify "(:sign_positive => true, :sign_before_symbol => true) works as documented" do
424
- Money.us_dollar( 0).format(:sign_positive => true, :sign_before_symbol => true).should == "$0.00"
425
- Money.us_dollar( 100000).format(:sign_positive => true, :sign_before_symbol => true).should == "+$1,000.00"
426
- Money.us_dollar(-100000).format(:sign_positive => true, :sign_before_symbol => true).should == "-$1,000.00"
451
+ expect(Money.us_dollar( 0).format(:sign_positive => true, :sign_before_symbol => true)).to eq "$0.00"
452
+ expect(Money.us_dollar( 100000).format(:sign_positive => true, :sign_before_symbol => true)).to eq "+$1,000.00"
453
+ expect(Money.us_dollar(-100000).format(:sign_positive => true, :sign_before_symbol => true)).to eq "-$1,000.00"
427
454
  end
428
455
 
429
456
  specify "(:sign_positive => true, :sign_before_symbol => false) works as documented" do
430
- Money.us_dollar( 0).format(:sign_positive => true, :sign_before_symbol => false).should == "$0.00"
431
- Money.us_dollar( 100000).format(:sign_positive => true, :sign_before_symbol => false).should == "$+1,000.00"
432
- Money.us_dollar( 100000).format(:sign_positive => true, :sign_before_symbol => nil).should == "$+1,000.00"
433
- Money.us_dollar(-100000).format(:sign_positive => true, :sign_before_symbol => false).should == "$-1,000.00"
434
- Money.us_dollar(-100000).format(:sign_positive => true, :sign_before_symbol => nil).should == "$-1,000.00"
457
+ expect(Money.us_dollar( 0).format(:sign_positive => true, :sign_before_symbol => false)).to eq "$0.00"
458
+ expect(Money.us_dollar( 100000).format(:sign_positive => true, :sign_before_symbol => false)).to eq "$+1,000.00"
459
+ expect(Money.us_dollar( 100000).format(:sign_positive => true, :sign_before_symbol => nil)).to eq "$+1,000.00"
460
+ expect(Money.us_dollar(-100000).format(:sign_positive => true, :sign_before_symbol => false)).to eq "$-1,000.00"
461
+ expect(Money.us_dollar(-100000).format(:sign_positive => true, :sign_before_symbol => nil)).to eq "$-1,000.00"
435
462
  end
436
463
 
437
464
  specify "(:sign_positive => false, :sign_before_symbol => true) works as documented" do
438
- Money.us_dollar( 100000).format(:sign_positive => false, :sign_before_symbol => true).should == "$1,000.00"
439
- Money.us_dollar(-100000).format(:sign_positive => false, :sign_before_symbol => true).should == "-$1,000.00"
465
+ expect(Money.us_dollar( 100000).format(:sign_positive => false, :sign_before_symbol => true)).to eq "$1,000.00"
466
+ expect(Money.us_dollar(-100000).format(:sign_positive => false, :sign_before_symbol => true)).to eq "-$1,000.00"
440
467
  end
441
468
 
442
469
  specify "(:sign_positive => false, :sign_before_symbol => false) works as documented" do
443
- Money.us_dollar( 100000).format(:sign_positive => false, :sign_before_symbol => false).should == "$1,000.00"
444
- Money.us_dollar( 100000).format(:sign_positive => false, :sign_before_symbol => nil).should == "$1,000.00"
445
- Money.us_dollar(-100000).format(:sign_positive => false, :sign_before_symbol => false).should == "$-1,000.00"
446
- Money.us_dollar(-100000).format(:sign_positive => false, :sign_before_symbol => nil).should == "$-1,000.00"
470
+ expect(Money.us_dollar( 100000).format(:sign_positive => false, :sign_before_symbol => false)).to eq "$1,000.00"
471
+ expect(Money.us_dollar( 100000).format(:sign_positive => false, :sign_before_symbol => nil)).to eq "$1,000.00"
472
+ expect(Money.us_dollar(-100000).format(:sign_positive => false, :sign_before_symbol => false)).to eq "$-1,000.00"
473
+ expect(Money.us_dollar(-100000).format(:sign_positive => false, :sign_before_symbol => nil)).to eq "$-1,000.00"
447
474
  end
448
475
  end
449
476
 
@@ -457,23 +484,45 @@ describe Money, "formatting" do
457
484
  end
458
485
 
459
486
  it "does round fractional when set to true" do
460
- Money.new(BigDecimal.new('12.1'), "USD").format(:rounded_infinite_precision => true).should == "$0.12"
461
- Money.new(BigDecimal.new('12.5'), "USD").format(:rounded_infinite_precision => true).should == "$0.13"
462
- Money.new(BigDecimal.new('123.1'), "BHD").format(:rounded_infinite_precision => true).should == "ب.د0.123"
463
- Money.new(BigDecimal.new('123.5'), "BHD").format(:rounded_infinite_precision => true).should == "ب.د0.124"
464
- Money.new(BigDecimal.new('100.1'), "USD").format(:rounded_infinite_precision => true).should == "$1.00"
465
- Money.new(BigDecimal.new('109.5'), "USD").format(:rounded_infinite_precision => true).should == "$1.10"
466
- Money.new(BigDecimal.new('1'), "MGA").format(:rounded_infinite_precision => true).should == "Ar0.2"
487
+ expect(Money.new(BigDecimal.new('12.1'), "USD").format(:rounded_infinite_precision => true)).to eq "$0.12"
488
+ expect(Money.new(BigDecimal.new('12.5'), "USD").format(:rounded_infinite_precision => true)).to eq "$0.13"
489
+ expect(Money.new(BigDecimal.new('123.1'), "BHD").format(:rounded_infinite_precision => true)).to eq "ب.د0.123"
490
+ expect(Money.new(BigDecimal.new('123.5'), "BHD").format(:rounded_infinite_precision => true)).to eq "ب.د0.124"
491
+ expect(Money.new(BigDecimal.new('100.1'), "USD").format(:rounded_infinite_precision => true)).to eq "$1.00"
492
+ expect(Money.new(BigDecimal.new('109.5'), "USD").format(:rounded_infinite_precision => true)).to eq "$1.10"
493
+ expect(Money.new(BigDecimal.new('1'), "MGA").format(:rounded_infinite_precision => true)).to eq "Ar0.2"
467
494
  end
468
495
 
469
496
  it "does not round fractional when set to false" do
470
- Money.new(BigDecimal.new('12.1'), "USD").format(:rounded_infinite_precision => false).should == "$0.121"
471
- Money.new(BigDecimal.new('12.5'), "USD").format(:rounded_infinite_precision => false).should == "$0.125"
472
- Money.new(BigDecimal.new('123.1'), "BHD").format(:rounded_infinite_precision => false).should == "ب.د0.1231"
473
- Money.new(BigDecimal.new('123.5'), "BHD").format(:rounded_infinite_precision => false).should == "ب.د0.1235"
474
- Money.new(BigDecimal.new('100.1'), "USD").format(:rounded_infinite_precision => false).should == "$1.001"
475
- Money.new(BigDecimal.new('109.5'), "USD").format(:rounded_infinite_precision => false).should == "$1.095"
476
- Money.new(BigDecimal.new('1'), "MGA").format(:rounded_infinite_precision => false).should == "Ar0.1"
497
+ expect(Money.new(BigDecimal.new('12.1'), "USD").format(:rounded_infinite_precision => false)).to eq "$0.121"
498
+ expect(Money.new(BigDecimal.new('12.5'), "USD").format(:rounded_infinite_precision => false)).to eq "$0.125"
499
+ expect(Money.new(BigDecimal.new('123.1'), "BHD").format(:rounded_infinite_precision => false)).to eq "ب.د0.1231"
500
+ expect(Money.new(BigDecimal.new('123.5'), "BHD").format(:rounded_infinite_precision => false)).to eq "ب.د0.1235"
501
+ expect(Money.new(BigDecimal.new('100.1'), "USD").format(:rounded_infinite_precision => false)).to eq "$1.001"
502
+ expect(Money.new(BigDecimal.new('109.5'), "USD").format(:rounded_infinite_precision => false)).to eq "$1.095"
503
+ expect(Money.new(BigDecimal.new('1'), "MGA").format(:rounded_infinite_precision => false)).to eq "Ar0.1"
504
+ end
505
+
506
+ describe ":rounded_infinite_precision option with i18n = false" do
507
+ before do
508
+ Money.use_i18n = false
509
+ Money.infinite_precision = true
510
+ end
511
+
512
+ after do
513
+ Money.use_i18n = true
514
+ Money.infinite_precision = false
515
+ end
516
+
517
+ it 'does round fractional when set to true' do
518
+ expect(Money.new(BigDecimal.new('12.1'), "EUR").format(:rounded_infinite_precision => true)).to eq "€0,12"
519
+ expect(Money.new(BigDecimal.new('12.5'), "EUR").format(:rounded_infinite_precision => true)).to eq "€0,13"
520
+ expect(Money.new(BigDecimal.new('100.1'), "EUR").format(:rounded_infinite_precision => true)).to eq "€1,00"
521
+ expect(Money.new(BigDecimal.new('109.5'), "EUR").format(:rounded_infinite_precision => true)).to eq "€1,10"
522
+
523
+ expect(Money.new(BigDecimal.new('100012.1'), "EUR").format(:rounded_infinite_precision => true)).to eq "€1.000,12"
524
+ expect(Money.new(BigDecimal.new('100012.5'), "EUR").format(:rounded_infinite_precision => true)).to eq "€1.000,13"
525
+ end
477
526
  end
478
527
  end
479
528
 
@@ -481,17 +530,17 @@ describe Money, "formatting" do
481
530
  let(:money) { Money.us_dollar(0) }
482
531
 
483
532
  it "returns 'free' when :display_free is true" do
484
- money.format(:display_free => true).should == 'free'
533
+ expect(money.format(:display_free => true)).to eq 'free'
485
534
  end
486
535
 
487
536
  it "returns '$0.00' when :display_free is false or not given" do
488
- money.format.should == '$0.00'
489
- money.format(:display_free => false).should == '$0.00'
490
- money.format(:display_free => nil).should == '$0.00'
537
+ expect(money.format).to eq '$0.00'
538
+ expect(money.format(:display_free => false)).to eq '$0.00'
539
+ expect(money.format(:display_free => nil)).to eq '$0.00'
491
540
  end
492
541
 
493
542
  it "returns the value specified by :display_free if it's a string-like object" do
494
- money.format(:display_free => 'gratis').should == 'gratis'
543
+ expect(money.format(:display_free => 'gratis')).to eq 'gratis'
495
544
  end
496
545
  end
497
546
  end
@@ -508,32 +557,32 @@ describe Money, "formatting" do
508
557
  end
509
558
 
510
559
  it "respects custom subunit to unit, decimal and thousands separator" do
511
- Money.new(4, "BAR").format.should == "$0.0004"
512
- Money.new(4, "EU4").format.should == "€0,0004"
560
+ expect(Money.new(4, "BAR").format).to eq "$0.0004"
561
+ expect(Money.new(4, "EU4").format).to eq "€0,0004"
513
562
 
514
- Money.new(24, "BAR").format.should == "$0.0024"
515
- Money.new(24, "EU4").format.should == "€0,0024"
563
+ expect(Money.new(24, "BAR").format).to eq "$0.0024"
564
+ expect(Money.new(24, "EU4").format).to eq "€0,0024"
516
565
 
517
- Money.new(324, "BAR").format.should == "$0.0324"
518
- Money.new(324, "EU4").format.should == "€0,0324"
566
+ expect(Money.new(324, "BAR").format).to eq "$0.0324"
567
+ expect(Money.new(324, "EU4").format).to eq "€0,0324"
519
568
 
520
- Money.new(5324, "BAR").format.should == "$0.5324"
521
- Money.new(5324, "EU4").format.should == "€0,5324"
569
+ expect(Money.new(5324, "BAR").format).to eq "$0.5324"
570
+ expect(Money.new(5324, "EU4").format).to eq "€0,5324"
522
571
 
523
- Money.new(65324, "BAR").format.should == "$6.5324"
524
- Money.new(65324, "EU4").format.should == "€6,5324"
572
+ expect(Money.new(65324, "BAR").format).to eq "$6.5324"
573
+ expect(Money.new(65324, "EU4").format).to eq "€6,5324"
525
574
 
526
- Money.new(865324, "BAR").format.should == "$86.5324"
527
- Money.new(865324, "EU4").format.should == "€86,5324"
575
+ expect(Money.new(865324, "BAR").format).to eq "$86.5324"
576
+ expect(Money.new(865324, "EU4").format).to eq "€86,5324"
528
577
 
529
- Money.new(1865324, "BAR").format.should == "$186.5324"
530
- Money.new(1865324, "EU4").format.should == "€186,5324"
578
+ expect(Money.new(1865324, "BAR").format).to eq "$186.5324"
579
+ expect(Money.new(1865324, "EU4").format).to eq "€186,5324"
531
580
 
532
- Money.new(33310034, "BAR").format.should == "$3,331.0034"
533
- Money.new(33310034, "EU4").format.should == "€3.331,0034"
581
+ expect(Money.new(33310034, "BAR").format).to eq "$3,331.0034"
582
+ expect(Money.new(33310034, "EU4").format).to eq "€3.331,0034"
534
583
 
535
- Money.new(88833310034, "BAR").format.should == "$8,883,331.0034"
536
- Money.new(88833310034, "EU4").format.should == "€8.883.331,0034"
584
+ expect(Money.new(88833310034, "BAR").format).to eq "$8,883,331.0034"
585
+ expect(Money.new(88833310034, "EU4").format).to eq "€8.883.331,0034"
537
586
  end
538
587
 
539
588
  end