active_object 1.1.1 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,191 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Hash do
4
-
5
- describe "#assert_valid_keys" do
6
- it "to be {}" do
7
- expect({}.assert_valid_keys(:foo)).to eq({})
8
- end
9
-
10
- it "to be { foo: 'bar' }" do
11
- expect({ foo: "bar" }.assert_valid_keys(:foo)).to eq({ foo: "bar" })
12
- end
13
-
14
- it "to raise error" do
15
- expect { { foo: "bar", baz: "boz" }.assert_valid_keys(:foo) }.to raise_error(ArgumentError)
16
- end
17
- end
18
-
19
- describe "#compact(!)" do
20
- it "to be nil" do
21
- expect({}.compact!).to eq(nil)
22
- end
23
-
24
- it "to be {}" do
25
- expect({}.compact).to eq({})
26
- expect({ foo: nil }.compact).to eq({})
27
- expect({ foo: nil }.compact!).to eq({})
28
- end
29
-
30
- it "to be { foo: 'bar', baz: false, boo: nil }" do
31
- expect({ foo: "bar", baz: false, boo: nil }.compact).to eq({ foo: "bar", baz: false })
32
- expect({ foo: "bar", baz: false, boo: nil }.compact!).to eq({ foo: "bar", baz: false })
33
- end
34
- end
35
-
36
- describe "#deep_dup(!)" do
37
- it "to be { a: false, b: { c: [1, 2, 3], x: [3, 4, 5] } }" do
38
- h1 = { a: true, b: { c: [1, 2, 3] } }
39
- h2 = { a: false, b: { x: [3, 4, 5] } }
40
-
41
- expect(h1.deep_merge(h2)).to eq({ a: false, b: { c: [1, 2, 3], x: [3, 4, 5] } })
42
- expect(h1.deep_merge!(h2)).to eq({ a: false, b: { c: [1, 2, 3], x: [3, 4, 5] } })
43
- end
44
- end
45
-
46
- describe "#except(!)" do
47
- it "to be {}" do
48
- expect({}.except(:foo)).to eq({})
49
- expect({}.except!(:foo)).to eq({})
50
- end
51
-
52
- it "to be { :foo => 1 }" do
53
- expect({ foo: 1, baz: 2, bar: 3 }.except(:baz, :bar)).to eq({ foo: 1 })
54
- expect({ foo: 1, baz: 2, bar: 3 }.except!(:baz, :bar)).to eq({ foo: 1 })
55
- expect({ :foo => 1, :baz => 2, :bar => 3 }.except(:baz, :bar)).to eq({ :foo => 1 })
56
- expect({ :foo => 1, :baz => 2, :bar => 3 }.except!(:baz, :bar)).to eq({ :foo => 1 })
57
- end
58
-
59
- it "to be { :baz => 2, :bar => 3 }" do
60
- expect({ foo: 1, baz: 2, bar: 3 }.except(:foo)).to eq({ baz: 2, bar: 3 })
61
- expect({ foo: 1, baz: 2, bar: 3 }.except!(:foo)).to eq({ baz: 2, bar: 3 })
62
- expect({ :foo => 1, :baz => 2, :bar => 3 }.except(:foo)).to eq({ :baz => 2, :bar => 3 })
63
- expect({ :foo => 1, :baz => 2, :bar => 3 }.except!(:foo)).to eq({ :baz => 2, :bar => 3 })
64
- end
65
- end
66
-
67
- describe "#nillify" do
68
- it "to be {a: 1, b: 'test', c: nil, d: nil, e: nil, f: nil}" do
69
- expect({ a: 1, b: "test", c: nil, d: false, e: "", f: " " }.nillify).to eq({a: 1, b: 'test', c: nil, d: nil, e: nil, f: nil})
70
- expect({ a: 1, b: "test", c: nil, d: false, e: "", f: " " }.nillify!).to eq({a: 1, b: 'test', c: nil, d: nil, e: nil, f: nil})
71
- end
72
- end
73
-
74
- describe "#only(!)" do
75
- it "to be {}" do
76
- expect({}.only(:foo)).to eq({})
77
- expect({}.only!(:foo)).to eq({})
78
- end
79
-
80
- it "to be { :foo => 1 }" do
81
- expect({ foo: 1, baz: 2, bar: 3 }.only(:foo)).to eq({ foo: 1 })
82
- expect({ foo: 1, baz: 2, bar: 3 }.only!(:foo)).to eq({ foo: 1 })
83
- expect({ :foo => 1, :baz => 2, :bar => 3 }.only(:foo)).to eq({ :foo => 1 })
84
- expect({ :foo => 1, :baz => 2, :bar => 3 }.only!(:foo)).to eq({ :foo => 1 })
85
- end
86
-
87
- it "to be { :baz => 2, :bar => 3 }" do
88
- expect({ foo: 1, baz: 2, bar: 3 }.only(:baz, :bar)).to eq({ baz: 2, bar: 3 })
89
- expect({ foo: 1, baz: 2, bar: 3 }.only!(:baz, :bar)).to eq({ baz: 2, bar: 3 })
90
- expect({ :foo => 1, :baz => 2, :bar => 3 }.only(:baz, :bar)).to eq({ :baz => 2, :bar => 3 })
91
- expect({ :foo => 1, :baz => 2, :bar => 3 }.only!(:baz, :bar)).to eq({ :baz => 2, :bar => 3 })
92
- end
93
- end
94
-
95
- describe "#rename_keys(!)" do
96
- it "to be [:baz, :bar]" do
97
- expect({ foo: 'foo', baz: 'baz' }.rename_keys(foo: :bar).keys).to eq([:baz, :bar])
98
- expect({ foo: 'foo', baz: 'baz' }.rename_keys!(foo: :bar).keys).to eq([:baz, :bar])
99
- end
100
-
101
- it "to be [:foo, 'tick']" do
102
- expect({ foo: 'foo', 'baz' => 'baz' }.rename_keys('baz' => 'tick').keys).to eq([:foo, 'tick'])
103
- expect({ foo: 'foo', 'baz' => 'baz' }.rename_keys!('baz' => 'tick').keys).to eq([:foo, 'tick'])
104
- end
105
-
106
- it "to be [:bar, :tick]" do
107
- expect({ foo: 'foo', baz: 'baz' }.rename_keys(foo: :bar, baz: :tick).keys).to eq([:bar, :tick])
108
- expect({ foo: 'foo', baz: 'baz' }.rename_keys!(foo: :bar, baz: :tick).keys).to eq([:bar, :tick])
109
- end
110
-
111
- it "to be [:bar, 'tick']" do
112
- expect({ foo: 'foo', 'baz' => 'baz' }.rename_keys(foo: :bar, 'baz' => 'tick').keys).to eq([:bar, 'tick'])
113
- expect({ foo: 'foo', 'baz' => 'baz' }.rename_keys!(foo: :bar, 'baz' => 'tick').keys).to eq([:bar, 'tick'])
114
- end
115
- end
116
-
117
- describe "#reverse_merge(!)" do
118
- it "to be { foo: 'bar' }" do
119
- expect({}.reverse_merge(foo: "bar")).to eq({ foo: "bar" })
120
- expect({}.reverse_merge!(foo: "bar")).to eq({ foo: "bar" })
121
- end
122
-
123
- it "to be { foo: 'bar', baz: 'boo', boo: 'bam' }" do
124
- expect({ foo: "bar" }.reverse_merge(baz: "boo", boo: "bam")).to eq({ foo: "bar", baz: "boo", boo: "bam" })
125
- expect({ foo: "bar" }.reverse_merge!(baz: "boo", boo: "bam")).to eq({ foo: "bar", baz: "boo", boo: "bam" })
126
- end
127
- end
128
-
129
- describe "#slice(!)" do
130
- it "to be { a: 1, b: 2 }" do
131
- expect({ a: 1, b: 2, c: 3, d: 4 }.slice(:a, :b)).to eq({ a: 1, b: 2 })
132
- end
133
-
134
- it "to be { a: 3, b: 4 }" do
135
- expect({ a: 1, b: 2, c: 3, d: 4 }.slice!(:a, :b)).to eq({ c: 3, d: 4 })
136
- end
137
- end
138
-
139
- describe "#stringify_keys(!)" do
140
- it "to be { 'foo' => 'foo', 'bar' => 'bar' }" do
141
- expect({ foo: 'foo', 'bar' => 'bar' }.stringify_keys).to eq({ 'foo' => 'foo', 'bar' => 'bar' })
142
- expect({ foo: 'foo', 'bar' => 'bar' }.stringify_keys!).to eq({ 'foo' => 'foo', 'bar' => 'bar' })
143
- end
144
- end
145
-
146
- describe "#strip(!)" do
147
- it "to be nil" do
148
- expect({}.strip!).to eq(nil)
149
- end
150
-
151
- it "to be {}" do
152
- expect({}.strip).to eq({})
153
- expect({ foo: nil, baz: false, boo: '', faz: ' ' }.strip).to eq({})
154
- expect({ foo: nil, baz: false, boo: '', faz: ' ' }.strip!).to eq({})
155
- end
156
-
157
- it "to be { foo: 'bar', baz: false, boo: nil }" do
158
- expect({ foo: "bar", baz: false, boo: nil, boz: '', faz: ' ' }.strip).to eq({ foo: "bar" })
159
- expect({ foo: "bar", baz: false, boo: nil, boz: '', faz: ' ' }.strip!).to eq({ foo: "bar" })
160
- end
161
- end
162
-
163
- describe "#symbolize_keys(!)" do
164
- it "to be { foo: 'foo', bar: 'bar' }" do
165
- expect({ foo: 'foo', 'bar' => 'bar' }.symbolize_keys).to eq({ foo: 'foo', bar: 'bar' })
166
- expect({ foo: 'foo', 'bar' => 'bar' }.symbolize_keys!).to eq({ foo: 'foo', bar: 'bar' })
167
- end
168
- end
169
-
170
- describe "#symbolize_and_underscore_keys(!)" do
171
- it "to be { foo_bar: 'example', baz_bar: 'string' }" do
172
- expect({ 'foo Bar' => 'example', bazBar: 'string' }.symbolize_and_underscore_keys).to eq({ foo_bar: 'example', baz_bar: 'string' })
173
- expect({ 'foo Bar' => 'example', bazBar: 'string' }.symbolize_and_underscore_keys!).to eq({ foo_bar: 'example', baz_bar: 'string' })
174
- end
175
- end
176
-
177
- describe "#transform_keys(!)" do
178
- it "to be { 'FOO' => 'foo', 'BAZ' => 'bar' }" do
179
- expect({ foo: 'bar', baz: 'boo' }.transform_keys { |k| k.to_s.upcase }).to eq({ "FOO" => 'bar', "BAZ" => 'boo' })
180
- expect({ foo: 'bar', baz: 'boo' }.transform_keys! { |k| k.to_s.upcase }).to eq({ "FOO" => 'bar', "BAZ" => 'boo' })
181
- end
182
- end
183
-
184
- describe "#transform_values(!)" do
185
- it "to be { foo: 'BAR', baz: 'BOO' }" do
186
- expect({ foo: 'bar', baz: 'boo' }.transform_values { |v| v.to_s.upcase }).to eq({ foo: 'BAR', baz: 'BOO' })
187
- expect({ foo: 'bar', baz: 'boo' }.transform_values! { |v| v.to_s.upcase }).to eq({ foo: 'BAR', baz: 'BOO' })
188
- end
189
- end
190
-
191
- end
@@ -1,11 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Integer do
4
-
5
- describe "#time" do
6
- it "to be 1969-12-31 19:00:03 -0500" do
7
- expect(3.time.to_s).to eq("1969-12-31 19:00:03 -0500")
8
- end
9
- end
10
-
11
- end
@@ -1,656 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Numeric do
4
-
5
- describe "#add" do
6
- it "to be 6" do
7
- expect(4.add(2)).to eq(6)
8
- end
9
- end
10
-
11
- describe "#byte_in_bytes" do
12
- it "to be 3" do
13
- expect(3.byte_in_bytes).to eq(3)
14
- expect(3.bytes_in_bytes).to eq(3)
15
- end
16
- end
17
-
18
- describe "#centigram_in_grams" do
19
- it "to be 0.03" do
20
- expect(3.centigram_in_grams).to eq(0.03)
21
- expect(3.centigrams_in_grams).to eq(0.03)
22
- end
23
- end
24
-
25
- describe "#centimeter_in_meters" do
26
- it "to be 0.03" do
27
- expect(3.centimeter_in_meters).to eq(0.03)
28
- expect(3.centimeters_in_meters).to eq(0.03)
29
- end
30
- end
31
-
32
- describe "#century_in_second" do
33
- it "to be 259200" do
34
- expect(3.century_in_seconds).to eq(9467280000.0)
35
- expect(3.centuries_in_seconds).to eq(9467280000.0)
36
- end
37
- end
38
-
39
- describe "#decade_in_second" do
40
- it "to be 259200" do
41
- expect(3.decade_in_seconds).to eq(946728000.0)
42
- expect(3.decades_in_seconds).to eq(946728000.0)
43
- end
44
- end
45
-
46
- describe "#decagram_in_grams" do
47
- it "to be 30" do
48
- expect(3.decagram_in_grams).to eq(30)
49
- expect(3.decagrams_in_grams).to eq(30)
50
- end
51
- end
52
-
53
- describe "#decameter_in_meters" do
54
- it "to be 30" do
55
- expect(3.decameter_in_meters).to eq(30)
56
- expect(3.decameters_in_meters).to eq(30)
57
- end
58
- end
59
-
60
- describe "#decigrams_in_grams" do
61
- it "to be 0.3" do
62
- expect(3.decigram_in_grams).to eq(0.30000000000000004)
63
- expect(3.decigrams_in_grams).to eq(0.30000000000000004)
64
- end
65
- end
66
-
67
- describe "#decimeter_in_meters" do
68
- it "to be 0.3" do
69
- expect(3.decimeter_in_meters).to eq(0.30000000000000004)
70
- expect(3.decimeters_in_meters).to eq(0.30000000000000004)
71
- end
72
- end
73
-
74
- describe "#day_in_second" do
75
- it "to be 259200" do
76
- expect(3.day_in_seconds).to eq(259200)
77
- expect(3.days_in_seconds).to eq(259200)
78
- end
79
- end
80
-
81
- describe "#divide" do
82
- it "to be 2" do
83
- expect(4.divide(2)).to eq(2)
84
- end
85
- end
86
-
87
- describe "#exabyte_in_bytes" do
88
- it "to be 3458764513820540928" do
89
- expect(3.exabyte_in_bytes).to eq(3458764513820540928)
90
- expect(3.exabytes_in_bytes).to eq(3458764513820540928)
91
- end
92
- end
93
-
94
- describe "#feet_in_inches" do
95
- it "to be 36" do
96
- expect(3.foot_in_inches).to eq(36)
97
- expect(3.feet_in_inches).to eq(36)
98
- end
99
- end
100
-
101
- describe "#gigabyte_in_bytes" do
102
- it "to be 3221225472" do
103
- expect(3.gigabyte_in_bytes).to eq(3221225472)
104
- expect(3.gigabytes_in_bytes).to eq(3221225472)
105
- end
106
- end
107
-
108
- describe "#gram_in_grams" do
109
- it "to be 300" do
110
- expect(3.gram_in_grams).to eq(3)
111
- expect(3.grams_in_grams).to eq(3)
112
- end
113
- end
114
-
115
- describe "#hectogram_in_grams" do
116
- it "to be 300" do
117
- expect(3.hectogram_in_grams).to eq(300)
118
- expect(3.hectograms_in_grams).to eq(300)
119
- end
120
- end
121
-
122
- describe "#hectometer_in_meters" do
123
- it "to be 300" do
124
- expect(3.hectometer_in_meters).to eq(300)
125
- expect(3.hectometers_in_meters).to eq(300)
126
- end
127
- end
128
-
129
- describe "#hour_in_second" do
130
- it "to be 10800" do
131
- expect(3.hour_in_seconds).to eq(10800)
132
- expect(3.hours_in_seconds).to eq(10800)
133
- end
134
- end
135
-
136
- describe "#inch_in_inches" do
137
- it "to be 3" do
138
- expect(3.inch_in_inches).to eq(3)
139
- expect(3.inches_in_inches).to eq(3)
140
- end
141
- end
142
-
143
- describe "#kilobytes_in_bytes" do
144
- it "to be 3072" do
145
- expect(3.kilobyte_in_bytes).to eq(3072)
146
- expect(3.kilobytes_in_bytes).to eq(3072)
147
- end
148
- end
149
-
150
- describe "#kilograms_in_grams" do
151
- it "to be 3000" do
152
- expect(3.kilogram_in_grams).to eq(3000)
153
- expect(3.kilograms_in_grams).to eq(3000)
154
- end
155
- end
156
-
157
- describe "#kilometer_in_meters" do
158
- it "to be 3000" do
159
- expect(3.kilometer_in_meters).to eq(3000)
160
- expect(3.kilometers_in_meters).to eq(3000)
161
- end
162
- end
163
-
164
- describe "#metric_ton_in_grams" do
165
- it "to be 3000000" do
166
- expect(3.metric_ton_in_grams).to eq(3000000)
167
- expect(3.metric_tons_in_grams).to eq(3000000)
168
- end
169
- end
170
-
171
- describe "#megabyte_in_bytes" do
172
- it "to be 3145728" do
173
- expect(3.megabyte_in_bytes).to eq(3145728)
174
- expect(3.megabytes_in_bytes).to eq(3145728)
175
- end
176
- end
177
-
178
- describe "#meter_in_meters" do
179
- it "to be 3" do
180
- expect(3.meter_in_meters).to eq(3)
181
- expect(3.meters_in_meters).to eq(3)
182
- end
183
- end
184
-
185
- describe "#mile_in_inches" do
186
- it "to be 36" do
187
- expect(3.mile_in_inches).to eq(190080)
188
- expect(3.miles_in_inches).to eq(190080)
189
- end
190
- end
191
-
192
- describe "#millennium_in_second" do
193
- it "to be 94672800000.0" do
194
- expect(3.millennium_in_seconds).to eq(94672800000.0)
195
- expect(3.millenniums_in_seconds).to eq(94672800000.0)
196
- end
197
- end
198
-
199
- describe "#milligrams_in_grams" do
200
- it "to be 0.003" do
201
- expect(3.milligram_in_grams).to eq(0.003)
202
- expect(3.milligrams_in_grams).to eq(0.003)
203
- end
204
- end
205
-
206
- describe "#millimeter_in_meters" do
207
- it "to be 0.003" do
208
- expect(3.millimeter_in_meters).to eq(0.003)
209
- expect(3.millimeters_in_meters).to eq(0.003)
210
- end
211
- end
212
-
213
- describe "#minute_in_second" do
214
- it "to be 180" do
215
- expect(3.minute_in_seconds).to eq(180)
216
- expect(3.minutes_in_seconds).to eq(180)
217
- end
218
- end
219
-
220
- describe "#multiply" do
221
- it "to be 8" do
222
- expect(4.multiply(2)).to eq(8)
223
- end
224
- end
225
-
226
- describe "#multiple_of?" do
227
- it "to be true" do
228
- expect(9.multiple_of?(3)).to eq(true)
229
- expect(12.multiple_of?(3)).to eq(true)
230
- end
231
-
232
- it "to be false" do
233
- expect(10.multiple_of?(3)).to eq(false)
234
- end
235
- end
236
-
237
- describe "#nautical_mile_in_inches" do
238
- it "to be 218740.26239999998" do
239
- expect(3.nautical_mile_in_inches).to eq(218740.26239999998)
240
- expect(3.nautical_miles_in_inches).to eq(218740.26239999998)
241
- end
242
- end
243
-
244
- describe "#negative?" do
245
- it "to be true" do
246
- expect(-1.negative?).to eq(true)
247
- end
248
-
249
- it "to be false" do
250
- expect(1.negative?).to eq(false)
251
- end
252
- end
253
-
254
- describe "#ordinal" do
255
- it "to be st" do
256
- expect(1.ordinal).to eq("st")
257
- end
258
-
259
- it "to be nd" do
260
- expect(2.ordinal).to eq("nd")
261
- end
262
-
263
- it "to be rd" do
264
- expect(3.ordinal).to eq("rd")
265
- end
266
-
267
- it "to be th" do
268
- expect(11.ordinal).to eq("th")
269
- end
270
- end
271
-
272
- describe "#ordinalize" do
273
- it "to be st" do
274
- expect(1.ordinalize).to eq("1st")
275
- end
276
-
277
- it "to be nd" do
278
- expect(2.ordinalize).to eq("2nd")
279
- end
280
-
281
- it "to be rd" do
282
- expect(3.ordinalize).to eq("3rd")
283
- end
284
-
285
- it "to be th" do
286
- expect(11.ordinalize).to eq("11th")
287
- end
288
- end
289
-
290
- describe "#ounce_in_ounces" do
291
- it "to be 3" do
292
- expect(3.ounce_in_ounces).to eq(3)
293
- expect(3.ounces_in_ounces).to eq(3)
294
- end
295
- end
296
-
297
- describe "#pad" do
298
- it "to be 003" do
299
- expect(3.pad).to eq("003")
300
- end
301
-
302
- it "to be 113" do
303
- expect(3.pad(pad_number: 1)).to eq("113")
304
- end
305
-
306
- it "to be 0003" do
307
- expect(3.pad(precision: 4)).to eq("0003")
308
- end
309
-
310
- it "to be 003.5" do
311
- expect(3.5.pad(precision: 5)).to eq("003.5")
312
- end
313
- end
314
-
315
- describe "#pad_precision" do
316
- it "to be 3" do
317
- expect(3.pad_precision).to eq("3.00")
318
- end
319
-
320
- it "to be 3.50" do
321
- expect(3.5.pad_precision).to eq("3.50")
322
- end
323
-
324
- it "to be 3.11" do
325
- expect(3.pad_precision(pad_number: 1)).to eq("3.11")
326
- end
327
-
328
- it "to be 3.000" do
329
- expect(3.pad_precision(precision: 3)).to eq("3.000")
330
- end
331
-
332
- it "to be 3,00" do
333
- expect(3.pad_precision(separator: ",")).to eq("3,00")
334
- end
335
- end
336
-
337
- describe "#petabyte_in_bytes" do
338
- it "to be 3377699720527872" do
339
- expect(3.petabyte_in_bytes).to eq(3377699720527872)
340
- expect(3.petabytes_in_bytes).to eq(3377699720527872)
341
- end
342
- end
343
-
344
- describe "#positive?" do
345
- it "to be true" do
346
- expect(1.positive?).to eq(true)
347
- end
348
-
349
- it "to be false" do
350
- expect(-1.positive?).to eq(false)
351
- end
352
- end
353
-
354
- describe "#pound_in_ounces" do
355
- it "to be 48" do
356
- expect(3.pound_in_ounces).to eq(48)
357
- expect(3.pounds_in_ounces).to eq(48)
358
- end
359
- end
360
-
361
- describe "#power" do
362
- it "to be 16" do
363
- expect(4.power(2)).to eq(16)
364
- end
365
- end
366
-
367
- describe "#root" do
368
- it "to be 2" do
369
- expect(4.root(2)).to eq(2)
370
- end
371
- end
372
-
373
- describe "#second_in_seconds" do
374
- it "to be 3" do
375
- expect(3.second_in_seconds).to eq(3)
376
- expect(3.seconds_in_seconds).to eq(3)
377
- end
378
- end
379
-
380
- describe "#stone_in_ounces" do
381
- it "to be 672" do
382
- expect(3.stone_in_ounces).to eq(672)
383
- expect(3.stones_in_ounces).to eq(672)
384
- end
385
- end
386
-
387
- describe "#subtract" do
388
- it "to be 2" do
389
- expect(4.subtract(2)).to eq(2)
390
- end
391
- end
392
-
393
- describe "#terabyte_in_bytes" do
394
- it "to be 3298534883328" do
395
- expect(3.terabyte_in_bytes).to eq(3298534883328)
396
- expect(3.terabytes_in_bytes).to eq(3298534883328)
397
- end
398
- end
399
-
400
- describe "#to_byte" do
401
- it "to be 1" do
402
- expect(1024.to_byte(:kilobyte, :megabyte)).to eq(1)
403
- end
404
-
405
- it "to be 5" do
406
- expect(5120.to_byte(:kilobyte, :megabyte)).to eq(5)
407
- end
408
-
409
- it "to be 1024" do
410
- expect(1024.to_byte(:kilobyte, :kilobyte)).to eq(1024)
411
- expect(1.to_byte(:megabyte, :kilobyte)).to eq(1024)
412
- end
413
-
414
- it "to be 1048576" do
415
- expect(1.to_byte(:gigabyte, :kilobyte)).to eq(1048576)
416
- end
417
-
418
- it "to be 0.078125" do
419
- expect(80.to_byte(:megabyte, :gigabyte)).to eq(0.078125)
420
- end
421
-
422
- it "to raise error" do
423
- expect { 1.to_byte }.to raise_error(ArgumentError)
424
- expect { 1.to_byte(:bad, :kilobyte) }.to raise_error(ArgumentError)
425
- expect { 1.to_byte(:kilobyte, :bad) }.to raise_error(ArgumentError)
426
- expect { 1.to_byte(:bad, :bad) }.to raise_error(ArgumentError)
427
- end
428
- end
429
-
430
- describe "#to_currency" do
431
- it "to be $3.00" do
432
- expect(3.to_currency).to eq("$3.00")
433
- end
434
-
435
- it "to be $3.10" do
436
- expect(3.1.to_currency).to eq("$3.10")
437
- end
438
-
439
- it "to be $3.11" do
440
- expect(3.11.to_currency).to eq("$3.11")
441
- end
442
-
443
- it "to be @3.11" do
444
- expect(3.11.to_currency(unit: "@")).to eq("@3.11")
445
- end
446
-
447
- it "to be $3.00000" do
448
- expect(3.to_currency(precision: 5)).to eq("$3.00000")
449
- end
450
-
451
- it "to be $3.11" do
452
- expect(3.11111.to_currency).to eq("$3.11")
453
- end
454
- end
455
-
456
- describe "#to_length" do
457
- it "to be 1" do
458
- expect(1.to_length(:millimeter, :millimeter)).to eq(1)
459
- expect(1.to_length(:inches, :inches)).to eq(1)
460
- expect(10.to_length(:millimeters, :centimeters)).to eq(1)
461
- expect(12.to_length(:inches, :feet)).to eq(1)
462
- end
463
-
464
- it "to be 10" do
465
- expect(1.to_length(:centimeters, :millimeters)).to eq(10)
466
- end
467
-
468
- it "to be 12" do
469
- expect(1.to_length(:feet, :inches)).to eq(12)
470
- end
471
-
472
- it "to be 30.479999999999997" do
473
- expect(1.to_length(:feet, :centimeters)).to eq(30.479999999999997)
474
- end
475
-
476
- it "to be 1093.6138888888888" do
477
- expect(1.to_length(:kilometer, :yard)).to eq(1093.6138888888888)
478
- end
479
-
480
- it "to be 6076.118399999999" do
481
- expect(1.to_length(:nautical_miles, :feet)).to eq(6076.118399999999)
482
- end
483
-
484
- it "to raise error" do
485
- expect { 1.to_length }.to raise_error(ArgumentError)
486
- expect { 1.to_length(:bad, :meters) }.to raise_error(ArgumentError)
487
- expect { 1.to_length(:meters, :bad) }.to raise_error(ArgumentError)
488
- expect { 1.to_length(:bad, :bad) }.to raise_error(ArgumentError)
489
- end
490
- end
491
-
492
- describe "#to_mass" do
493
- it "to be 1" do
494
- expect(1.to_mass(:milligram, :milligram)).to eq(1)
495
- expect(1.to_mass(:ounces, :ounces)).to eq(1)
496
- expect(10.to_mass(:milligram, :centigram)).to eq(1)
497
- expect(16.to_mass(:ounces, :pounds)).to eq(1)
498
- end
499
-
500
- it "to be 1.360776" do
501
- expect(3.to_mass(:pound, :kilogram)).to eq(1.360776)
502
- end
503
-
504
- it "to be 1.1023125" do
505
- expect(1.to_mass(:metric_ton, :ton)).to eq(1.1023125)
506
- end
507
-
508
- it "to be 2.204625" do
509
- expect(1.to_mass(:kilograms, :pounds)).to eq(2.204625)
510
- end
511
-
512
- it "to be 10" do
513
- expect(1.to_mass(:centigrams, :milligrams)).to eq(10)
514
- end
515
-
516
- it "to be 16" do
517
- expect(1.to_mass(:pounds, :ounces)).to eq(16)
518
- end
519
-
520
- it "to be 64000" do
521
- expect(2.to_mass(:tons, :pounds)).to eq(4000)
522
- end
523
-
524
- it "to raise error" do
525
- expect { 1.to_mass }.to raise_error(ArgumentError)
526
- expect { 1.to_mass(:bad, :pound) }.to raise_error(ArgumentError)
527
- expect { 1.to_mass(:pound, :bad) }.to raise_error(ArgumentError)
528
- expect { 1.to_mass(:bad, :bad) }.to raise_error(ArgumentError)
529
- end
530
- end
531
-
532
- describe "#to_nearest_value" do
533
- it "to be 6" do
534
- expect(5.to_nearest_value([1, 3, 6, 9])).to eq(6)
535
- end
536
-
537
- it "to be 3.6" do
538
- expect(3.5.to_nearest_value([3.0, 3.3, 3.6, 3.9])).to eq(3.6)
539
- end
540
- end
541
-
542
- describe "#to_percentage" do
543
- it "to be 3.00%" do
544
- expect(3.to_percentage).to eq("3.00%")
545
- end
546
-
547
- it "to be 3.10%" do
548
- expect(3.1.to_percentage).to eq("3.10%")
549
- end
550
-
551
- it "to be 3.11%" do
552
- expect(3.11.to_percentage).to eq("3.11%")
553
- end
554
-
555
- it "to be 3.11@" do
556
- expect(3.11.to_percentage(unit: "@")).to eq("3.11@")
557
- end
558
-
559
- it "to be 3.00000%" do
560
- expect(3.to_percentage(precision: 5)).to eq("3.00000%")
561
- end
562
-
563
- it "to be 3.11%" do
564
- expect(3.11111.to_percentage).to eq("3.11%")
565
- end
566
- end
567
-
568
- describe "#to_temperature" do
569
- it "to be 212" do
570
- expect(100.to_temperature(:celsius, :fahrenheit)).to eq(212)
571
- end
572
-
573
- it "to be 100" do
574
- expect(100.to_temperature(:celsius, :celsius)).to eq(100)
575
- expect(212.to_temperature(:fahrenheit, :celsius)).to eq(100)
576
- end
577
-
578
- it "to be 373.15" do
579
- expect(100.to_temperature(:celsius, :kelvin)).to eq(373.15)
580
- expect(212.to_temperature(:fahrenheit, :kelvin)).to eq(373.15)
581
- end
582
-
583
- it "to be -173.15" do
584
- expect(100.to_temperature(:kelvin, :celsius)).to eq(-173.14999999999998)
585
- end
586
-
587
- it "to be -279.67" do
588
- expect(100.to_temperature(:kelvin, :fahrenheit)).to eq(-279.66999999999996)
589
- end
590
-
591
- it "to raise error" do
592
- expect { 1.to_temperature }.to raise_error(ArgumentError)
593
- expect { 1.to_temperature(:bad, :kelvin) }.to raise_error(ArgumentError)
594
- expect { 1.to_temperature(:kelvin, :bad) }.to raise_error(ArgumentError)
595
- expect { 1.to_temperature(:bad, :bad) }.to raise_error(ArgumentError)
596
- end
597
- end
598
-
599
- describe "#to_time" do
600
- it "to be 2" do
601
- expect(120.to_time(:seconds, :minutes)).to eq(2)
602
- end
603
-
604
- it "to be 40" do
605
- expect(2400.to_time(:minutes, :hours)).to eq(40)
606
- end
607
-
608
- it "to be 3" do
609
- expect(72.to_time(:hours, :days)).to eq(3)
610
- end
611
-
612
- it "to be 5" do
613
- expect(1825.to_time(:days, :years)).to eq(4.996577686516085)
614
- end
615
-
616
- it "to be 172800" do
617
- expect(2.to_time(:days, :seconds)).to eq(172800)
618
- end
619
-
620
- it "to raise error" do
621
- expect { 1.to_time }.to raise_error(ArgumentError)
622
- expect { 1.to_time(:bad, :days) }.to raise_error(ArgumentError)
623
- expect { 1.to_time(:days, :bad) }.to raise_error(ArgumentError)
624
- expect { 1.to_time(:bad, :bad) }.to raise_error(ArgumentError)
625
- end
626
- end
627
-
628
- describe "#ton_in_ounces" do
629
- it "to be 96000" do
630
- expect(3.ton_in_ounces).to eq(96000)
631
- expect(3.tons_in_ounces).to eq(96000)
632
- end
633
- end
634
-
635
- describe "#week_in_seconds" do
636
- it "to be 1814400" do
637
- expect(3.week_in_seconds).to eq(1814400)
638
- expect(3.weeks_in_seconds).to eq(1814400)
639
- end
640
- end
641
-
642
- describe "#yard_in_inches" do
643
- it "to be 36" do
644
- expect(3.yard_in_inches).to eq(108)
645
- expect(3.yards_in_inches).to eq(108)
646
- end
647
- end
648
-
649
- describe "#year_in_seconds" do
650
- it "to be 94672800.0" do
651
- expect(3.year_in_seconds).to eq(94672800.0)
652
- expect(3.years_in_seconds).to eq(94672800.0)
653
- end
654
- end
655
-
656
- end