lazier 3.5.0 → 3.5.1

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.
data/lib/lazier/hash.rb CHANGED
@@ -7,6 +7,14 @@
7
7
  module Lazier
8
8
  # Extensions for Hash objects.
9
9
  module Hash
10
+ # The supported accesses for #ensure_access
11
+ VALID_ACCESSES = {
12
+ strings: :stringify_keys,
13
+ symbols: :symbolize_keys,
14
+ indifferent: :with_indifferent_access,
15
+ dotted: :enable_dotted_access
16
+ }
17
+
10
18
  extend ::ActiveSupport::Concern
11
19
 
12
20
  # Returns a new hash, removing all keys which values are blank.
@@ -28,11 +36,14 @@ module Lazier
28
36
 
29
37
  # Makes sure that the keys of the hash are accessible in the desired way.
30
38
  #
31
- # @param access [Symbol|NilClass] The requested access for the keys. Can be `:strings`, `:symbols` or `:indifferent`. If `nil` the keys are not modified.
39
+ # @param accesses [Array] The requested access for the keys. Can be `:strings`, `:symbols` or `:indifferent`. If `nil` the keys are not modified.
32
40
  # @return [Hash] The current hash with keys modified.
33
- def ensure_access(access)
34
- method = {strings: :stringify_keys, symbols: :symbolize_keys, indifferent: :with_indifferent_access, dotted: :enable_dotted_access}.fetch(access, nil)
35
- method ? send(method) : self
41
+ def ensure_access(*accesses)
42
+ accesses.compact.inject(self) do |rv, access|
43
+ method = VALID_ACCESSES.fetch(access.ensure_string.to_sym, nil)
44
+ rv = rv.send(method) if method
45
+ rv
46
+ end
36
47
  end
37
48
 
38
49
  # Makes sure that the hash is accessible using dotted notation. This is also applied to every embedded hash.
@@ -16,7 +16,7 @@ module Lazier
16
16
  MINOR = 5
17
17
 
18
18
  # The patch version.
19
- PATCH = 0
19
+ PATCH = 1
20
20
 
21
21
  # The current version of lazier.
22
22
  STRING = [MAJOR, MINOR, PATCH].compact.join(".")
@@ -22,10 +22,10 @@ describe Lazier::Configuration do
22
22
  end
23
23
 
24
24
  it "should not allow writing readonly properties" do
25
- reference = ConfigurationSpecSample.new(required: 1)
25
+ subject = ConfigurationSpecSample.new(required: 1)
26
26
 
27
- expect { reference.readonly = "4" }.to raise_error(ArgumentError)
28
- expect(reference.readonly).to eq("2")
27
+ expect { subject .readonly = "4" }.to raise_error(ArgumentError)
28
+ expect(subject .readonly).to eq("2")
29
29
  end
30
30
 
31
31
  it "should blow up for require properties" do
@@ -7,9 +7,9 @@
7
7
  require "spec_helper"
8
8
 
9
9
  describe Lazier::DateTime do
10
- let(:random_reference) { ::DateTime.civil(1990 + rand(30), 1 + rand(10), 1 + rand(25), 1 + rand(20), 1 + rand(58), 1 + rand(58)).in_time_zone }
11
- let(:fixed_reference){ ::DateTime.civil(2005, 6, 7, 8, 9, 10, ::DateTime.rationalize_offset(25200)) }
12
- let(:reference_zone) { ::ActiveSupport::TimeZone["Mountain Time (US & Canada)"] }
10
+ let(:random_subject) { ::DateTime.civil(1990 + rand(30), 1 + rand(10), 1 + rand(25), 1 + rand(20), 1 + rand(58), 1 + rand(58)).in_time_zone }
11
+ let(:fixed_subject){ ::DateTime.civil(2005, 6, 7, 8, 9, 10, ::DateTime.rationalize_offset(25200)) }
12
+ let(:subject_zone) { ::ActiveSupport::TimeZone["Mountain Time (US & Canada)"] }
13
13
  let(:zone_without_dst) { ::ActiveSupport::TimeZone["International Date Line West"] }
14
14
 
15
15
  before(:all) do
@@ -73,7 +73,7 @@ describe Lazier::DateTime do
73
73
  describe ".find_timezone" do
74
74
  it "should forward to ActiveSupport::TimeZone" do
75
75
  expect(::ActiveSupport::TimeZone).to receive(:find)
76
- ::DateTime.find_timezone(reference_zone.name)
76
+ ::DateTime.find_timezone(subject_zone.name)
77
77
  end
78
78
  end
79
79
 
@@ -87,14 +87,14 @@ describe Lazier::DateTime do
87
87
  describe ".parameterize_zone" do
88
88
  it "should forward to ActiveSupport::TimeZone" do
89
89
  expect(::ActiveSupport::TimeZone).to receive(:parameterize_zone)
90
- ::DateTime.parameterize_zone(reference_zone)
90
+ ::DateTime.parameterize_zone(subject_zone)
91
91
  end
92
92
  end
93
93
 
94
94
  describe ".unparameterize_zone" do
95
95
  it "should forward to ActiveSupport::TimeZone" do
96
96
  expect(::ActiveSupport::TimeZone).to receive(:unparameterize_zone)
97
- ::DateTime.unparameterize_zone(reference_zone)
97
+ ::DateTime.unparameterize_zone(subject_zone)
98
98
  end
99
99
  end
100
100
 
@@ -136,40 +136,40 @@ describe Lazier::DateTime do
136
136
 
137
137
  describe "#utc_time" do
138
138
  it "should convert to UTC Time" do
139
- expect(random_reference.utc_time).to be_a(::Time)
139
+ expect(random_subject.utc_time).to be_a(::Time)
140
140
  end
141
141
  end
142
142
 
143
143
  describe "#in_months" do
144
- it "should return the amount of months passed since the start of the reference year" do
144
+ it "should return the amount of months passed since the start of the subject year" do
145
145
  expect(::Date.today.in_months).to eq(::Date.today.month)
146
- expect(fixed_reference.in_months(2000)).to eq(66)
146
+ expect(fixed_subject.in_months(2000)).to eq(66)
147
147
  end
148
148
  end
149
149
 
150
150
  describe "#padded_month" do
151
151
  it "should pad the month number" do
152
- expect(random_reference.padded_month).to eq(random_reference.month.to_s.rjust(2, "0"))
152
+ expect(random_subject.padded_month).to eq(random_subject.month.to_s.rjust(2, "0"))
153
153
  expect(::Date.civil(2000, 8, 8).padded_month).to eq("08")
154
154
  end
155
155
  end
156
156
 
157
157
  describe "#lstrftime" do
158
158
  it "should return corrected formatted string" do
159
- expect(fixed_reference.lstrftime(:db)).to eq("db")
160
- expect(fixed_reference.lstrftime("%F")).to eq("2005-06-07")
161
- expect(fixed_reference.lstrftime(:ct_iso_8601)).to eq("2005-06-07T08:09:10+0700")
159
+ expect(fixed_subject.lstrftime(:db)).to eq("db")
160
+ expect(fixed_subject.lstrftime("%F")).to eq("2005-06-07")
161
+ expect(fixed_subject.lstrftime(:ct_iso_8601)).to eq("2005-06-07T08:09:10+0700")
162
162
 
163
163
  ::Lazier.settings.setup_date_names
164
164
  ::Lazier.settings.setup_date_formats({ct_local_test: "%a %A %b %B %d %Y %H"})
165
- expect(fixed_reference.lstrftime(:ct_local_test)).to eq("Tue Tuesday Jun June 07 2005 08")
165
+ expect(fixed_subject.lstrftime(:ct_local_test)).to eq("Tue Tuesday Jun June 07 2005 08")
166
166
 
167
167
  ::Lazier.settings.setup_date_names(
168
168
  12.times.map {|i| (i + 1).to_s * 2}, 12.times.map {|i| (i + 1).to_s},
169
169
  7.times.map {|i| (i + 1).to_s * 2}, 7.times.map {|i| (i + 1).to_s}
170
170
  )
171
171
 
172
- expect(fixed_reference.lstrftime(:ct_local_test)).to eq("3 33 6 66 07 2005 08")
172
+ expect(fixed_subject.lstrftime(:ct_local_test)).to eq("3 33 6 66 07 2005 08")
173
173
  end
174
174
  end
175
175
 
@@ -177,7 +177,7 @@ describe Lazier::DateTime do
177
177
  it "should retrieve the date in the current timezone" do
178
178
  ::Time.zone = ::ActiveSupport::TimeZone[0]
179
179
  ::Lazier.settings.setup_date_formats({ct_local_test: "%a %A %b %B %d %Y %H"})
180
- expect(fixed_reference.local_strftime(:ct_local_test)).to eq("Tue Tuesday Jun June 07 2005 01")
180
+ expect(fixed_subject.local_strftime(:ct_local_test)).to eq("Tue Tuesday Jun June 07 2005 01")
181
181
  end
182
182
  end
183
183
 
@@ -193,14 +193,14 @@ describe Lazier::DateTime do
193
193
  7.times.map {|i| (i + 1).to_s * 2}, 7.times.map {|i| (i + 1).to_s}
194
194
  )
195
195
 
196
- expect(fixed_reference.local_lstrftime(:ct_local_test)).to eq("3 33 6 66 07 2005 01")
196
+ expect(fixed_subject.local_lstrftime(:ct_local_test)).to eq("3 33 6 66 07 2005 01")
197
197
  end
198
198
  end
199
199
  end
200
200
 
201
201
  describe Lazier::TimeZone do
202
- let(:reference_zone) { ::ActiveSupport::TimeZone["Mountain Time (US & Canada)"] }
203
- let(:reference_zone) { ::ActiveSupport::TimeZone["Mountain Time (US & Canada)"] }
202
+ let(:subject_zone) { ::ActiveSupport::TimeZone["Mountain Time (US & Canada)"] }
203
+ let(:subject_zone) { ::ActiveSupport::TimeZone["Mountain Time (US & Canada)"] }
204
204
  let(:zone_without_dst) { ::ActiveSupport::TimeZone["International Date Line West"] }
205
205
 
206
206
  before(:all) do
@@ -225,28 +225,28 @@ describe Lazier::TimeZone do
225
225
 
226
226
  describe ".parameterize_zone" do
227
227
  it "should return the parameterized version of the zone" do
228
- expect(::ActiveSupport::TimeZone.parameterize_zone(reference_zone.to_str)).to eq(reference_zone.to_str_parameterized)
229
- expect(::ActiveSupport::TimeZone.parameterize_zone(reference_zone.to_str)).to eq(reference_zone.to_str_parameterized)
230
- expect(::ActiveSupport::TimeZone.parameterize_zone(reference_zone.to_str, false)).to eq(reference_zone.to_str_parameterized(false))
228
+ expect(::ActiveSupport::TimeZone.parameterize_zone(subject_zone.to_str)).to eq(subject_zone.to_str_parameterized)
229
+ expect(::ActiveSupport::TimeZone.parameterize_zone(subject_zone.to_str)).to eq(subject_zone.to_str_parameterized)
230
+ expect(::ActiveSupport::TimeZone.parameterize_zone(subject_zone.to_str, false)).to eq(subject_zone.to_str_parameterized(false))
231
231
  expect(::ActiveSupport::TimeZone.parameterize_zone("INVALID")).to eq("invalid")
232
232
  end
233
233
  end
234
234
 
235
235
  describe ".unparameterize_zone" do
236
236
  it "should return the parameterized version of the zone" do
237
- expect(::ActiveSupport::TimeZone.unparameterize_zone(reference_zone.to_str_parameterized)).to eq(reference_zone)
238
- expect(::ActiveSupport::TimeZone.unparameterize_zone(reference_zone.to_str_parameterized, true)).to eq(reference_zone.to_str)
239
- expect(::ActiveSupport::TimeZone.unparameterize_zone(reference_zone.to_str_with_dst_parameterized)).to eq(reference_zone)
240
- expect(::ActiveSupport::TimeZone.unparameterize_zone(reference_zone.to_str_with_dst_parameterized, true)).to eq(reference_zone.to_str_with_dst)
237
+ expect(::ActiveSupport::TimeZone.unparameterize_zone(subject_zone.to_str_parameterized)).to eq(subject_zone)
238
+ expect(::ActiveSupport::TimeZone.unparameterize_zone(subject_zone.to_str_parameterized, true)).to eq(subject_zone.to_str)
239
+ expect(::ActiveSupport::TimeZone.unparameterize_zone(subject_zone.to_str_with_dst_parameterized)).to eq(subject_zone)
240
+ expect(::ActiveSupport::TimeZone.unparameterize_zone(subject_zone.to_str_with_dst_parameterized, true)).to eq(subject_zone.to_str_with_dst)
241
241
  expect(::ActiveSupport::TimeZone.unparameterize_zone("INVALID")).to eq(nil)
242
242
  end
243
243
  end
244
244
 
245
245
  describe ".find" do
246
246
  it "should find timezones" do
247
- expect(::ActiveSupport::TimeZone.find("(GMT-07:00) Mountain Time (US & Canada)")).to eq(reference_zone)
248
- expect(::ActiveSupport::TimeZone.find("(GMT-06:00) Mountain Time (US & Canada) (DST)")).to eq(reference_zone)
249
- expect(::ActiveSupport::TimeZone.find("(GMT-06:00) Mountain Time (US & Canada) Daylight Saving Time", "Daylight Saving Time")).to eq(reference_zone)
247
+ expect(::ActiveSupport::TimeZone.find("(GMT-07:00) Mountain Time (US & Canada)")).to eq(subject_zone)
248
+ expect(::ActiveSupport::TimeZone.find("(GMT-06:00) Mountain Time (US & Canada) (DST)")).to eq(subject_zone)
249
+ expect(::ActiveSupport::TimeZone.find("(GMT-06:00) Mountain Time (US & Canada) Daylight Saving Time", "Daylight Saving Time")).to eq(subject_zone)
250
250
  expect(::ActiveSupport::TimeZone.find("INVALID", "INVALID")).to be_nil
251
251
  end
252
252
  end
@@ -254,21 +254,21 @@ describe Lazier::TimeZone do
254
254
  describe ".list_all" do
255
255
  it "should list all timezones" do
256
256
  expect(::ActiveSupport::TimeZone.list_all(false)).to eq(::ActiveSupport::TimeZone.all.map(&:to_s))
257
- expect(::ActiveSupport::TimeZone.list_all(true)).to include("(GMT-06:00) #{reference_zone.aliases.first} (DST)")
258
- expect(::ActiveSupport::TimeZone.list_all(true, "Daylight Saving Time")).to include("(GMT-06:00) #{reference_zone.aliases.first} Daylight Saving Time")
257
+ expect(::ActiveSupport::TimeZone.list_all(true)).to include("(GMT-06:00) #{subject_zone.aliases.first} (DST)")
258
+ expect(::ActiveSupport::TimeZone.list_all(true, "Daylight Saving Time")).to include("(GMT-06:00) #{subject_zone.aliases.first} Daylight Saving Time")
259
259
  end
260
260
  end
261
261
 
262
262
  describe "#offset" do
263
263
  it "should correctly return zone offset" do
264
- expect(reference_zone.offset).to eq(reference_zone.utc_offset)
264
+ expect(subject_zone.offset).to eq(subject_zone.utc_offset)
265
265
  end
266
266
  end
267
267
 
268
268
  describe "#current_offset" do
269
269
  it "should correctly return current zone offset" do
270
- expect(reference_zone.current_offset(false, ::DateTime.civil(2012, 1, 15))).to eq(reference_zone.offset)
271
- expect(reference_zone.current_offset(true, ::DateTime.civil(2012, 7, 15))).to eq(reference_zone.dst_offset(true))
270
+ expect(subject_zone.current_offset(false, ::DateTime.civil(2012, 1, 15))).to eq(subject_zone.offset)
271
+ expect(subject_zone.current_offset(true, ::DateTime.civil(2012, 7, 15))).to eq(subject_zone.dst_offset(true))
272
272
  end
273
273
  end
274
274
 
@@ -283,44 +283,44 @@ describe Lazier::TimeZone do
283
283
 
284
284
  describe "#dst_period" do
285
285
  it "should correctly return zone offset" do
286
- expect(reference_zone.dst_period).to be_a(::TZInfo::TimezonePeriod)
287
- expect(reference_zone.dst_period(1000)).to be_nil
286
+ expect(subject_zone.dst_period).to be_a(::TZInfo::TimezonePeriod)
287
+ expect(subject_zone.dst_period(1000)).to be_nil
288
288
  expect(zone_without_dst.dst_period).to be_nil
289
289
  end
290
290
  end
291
291
 
292
292
  describe "#uses_dst?" do
293
293
  it "should correctly detect offset usage" do
294
- expect(reference_zone.uses_dst?).to be_true
295
- expect(reference_zone.uses_dst?(::DateTime.civil(2012, 7, 15))).to be_true
296
- expect(reference_zone.uses_dst?(::DateTime.civil(2012, 1, 15))).to be_false
297
- expect(reference_zone.uses_dst?(1000)).to be_false
294
+ expect(subject_zone.uses_dst?).to be_true
295
+ expect(subject_zone.uses_dst?(::DateTime.civil(2012, 7, 15))).to be_true
296
+ expect(subject_zone.uses_dst?(::DateTime.civil(2012, 1, 15))).to be_false
297
+ expect(subject_zone.uses_dst?(1000)).to be_false
298
298
  expect(zone_without_dst.uses_dst?).to be_false
299
299
  end
300
300
  end
301
301
 
302
302
  describe "#dst_name" do
303
303
  it "should correctly get zone name with Daylight Saving Time" do
304
- expect(reference_zone.dst_name).to eq("Mountain Time (US & Canada) (DST)")
305
- expect(reference_zone.dst_name("Daylight Saving Time")).to eq("Mountain Time (US & Canada) Daylight Saving Time")
306
- expect(reference_zone.dst_name(nil, 1000)).to be_nil
304
+ expect(subject_zone.dst_name).to eq("Mountain Time (US & Canada) (DST)")
305
+ expect(subject_zone.dst_name("Daylight Saving Time")).to eq("Mountain Time (US & Canada) Daylight Saving Time")
306
+ expect(subject_zone.dst_name(nil, 1000)).to be_nil
307
307
  expect(zone_without_dst.to_str_with_dst).to be_nil
308
308
  end
309
309
  end
310
310
 
311
311
  describe "#dst_correction" do
312
312
  it "should correctly detect offset usage" do
313
- expect(reference_zone.dst_correction).to eq(3600)
314
- expect(reference_zone.dst_correction(true)).to eq(Rational(1, 24))
315
- expect(reference_zone.dst_correction(false, 1000)).to eq(0)
313
+ expect(subject_zone.dst_correction).to eq(3600)
314
+ expect(subject_zone.dst_correction(true)).to eq(Rational(1, 24))
315
+ expect(subject_zone.dst_correction(false, 1000)).to eq(0)
316
316
  expect(zone_without_dst.dst_correction).to eq(0)
317
317
  end
318
318
  end
319
319
 
320
320
  describe "#dst_offset" do
321
321
  it "should correctly return zone offset" do
322
- expect(reference_zone.dst_offset).to eq(reference_zone.dst_correction + reference_zone.utc_offset)
323
- expect(reference_zone.dst_offset(true)).to eq(::ActiveSupport::TimeZone.rationalize_offset(reference_zone.dst_correction + reference_zone.utc_offset))
322
+ expect(subject_zone.dst_offset).to eq(subject_zone.dst_correction + subject_zone.utc_offset)
323
+ expect(subject_zone.dst_offset(true)).to eq(::ActiveSupport::TimeZone.rationalize_offset(subject_zone.dst_correction + subject_zone.utc_offset))
324
324
  expect(zone_without_dst.dst_offset(false, 1000)).to eq(0)
325
325
  expect(zone_without_dst.dst_offset).to eq(0)
326
326
  end
@@ -328,28 +328,28 @@ describe Lazier::TimeZone do
328
328
 
329
329
  describe "#to_str_with_dst" do
330
330
  it "should correctly format zone with Daylight Saving Time" do
331
- expect(reference_zone.to_str_with_dst).to eq("(GMT-06:00) #{reference_zone.aliases.first} (DST)")
332
- expect(reference_zone.to_str_with_dst("Daylight Saving Time")).to eq("(GMT-06:00) #{reference_zone.aliases.first} Daylight Saving Time")
333
- expect(reference_zone.to_str_with_dst("Daylight Saving Time", nil, "NAME")).to eq("(GMT-06:00) NAME Daylight Saving Time")
334
- expect(reference_zone.to_str_with_dst(nil, 1000)).to be_nil
331
+ expect(subject_zone.to_str_with_dst).to eq("(GMT-06:00) #{subject_zone.aliases.first} (DST)")
332
+ expect(subject_zone.to_str_with_dst("Daylight Saving Time")).to eq("(GMT-06:00) #{subject_zone.aliases.first} Daylight Saving Time")
333
+ expect(subject_zone.to_str_with_dst("Daylight Saving Time", nil, "NAME")).to eq("(GMT-06:00) NAME Daylight Saving Time")
334
+ expect(subject_zone.to_str_with_dst(nil, 1000)).to be_nil
335
335
  expect(zone_without_dst.to_str_with_dst).to be_nil
336
336
  end
337
337
  end
338
338
 
339
339
  describe "#to_str_parameterized" do
340
340
  it "should correctly format (parameterized) zone" do
341
- expect(reference_zone.to_str_parameterized).to eq(::ActiveSupport::TimeZone.parameterize_zone(reference_zone.to_str))
342
- expect(reference_zone.to_str_parameterized(false)).to eq(::ActiveSupport::TimeZone.parameterize_zone(reference_zone.to_str, false))
343
- expect(reference_zone.to_str_parameterized(false, "NAME SPACE")).to eq(::ActiveSupport::TimeZone.parameterize_zone("NAME SPACE", false))
341
+ expect(subject_zone.to_str_parameterized).to eq(::ActiveSupport::TimeZone.parameterize_zone(subject_zone.to_str))
342
+ expect(subject_zone.to_str_parameterized(false)).to eq(::ActiveSupport::TimeZone.parameterize_zone(subject_zone.to_str, false))
343
+ expect(subject_zone.to_str_parameterized(false, "NAME SPACE")).to eq(::ActiveSupport::TimeZone.parameterize_zone("NAME SPACE", false))
344
344
  end
345
345
  end
346
346
 
347
347
  describe "#to_str_with_dst_parameterized" do
348
348
  it "should correctly format (parameterized) zone with Daylight Saving Time" do
349
- expect(reference_zone.to_str_with_dst_parameterized).to eq("-0600@america-denver-dst")
350
- expect(reference_zone.to_str_with_dst_parameterized("Daylight Saving Time")).to eq("-0600@america-denver-daylight-saving-time")
351
- expect(reference_zone.to_str_with_dst_parameterized(nil, 1000)).to be_nil
352
- expect(reference_zone.to_str_with_dst_parameterized("Daylight Saving Time", nil, "NAME SPACE")).to eq("-0600@name-space-daylight-saving-time")
349
+ expect(subject_zone.to_str_with_dst_parameterized).to eq("-0600@america-denver-dst")
350
+ expect(subject_zone.to_str_with_dst_parameterized("Daylight Saving Time")).to eq("-0600@america-denver-daylight-saving-time")
351
+ expect(subject_zone.to_str_with_dst_parameterized(nil, 1000)).to be_nil
352
+ expect(subject_zone.to_str_with_dst_parameterized("Daylight Saving Time", nil, "NAME SPACE")).to eq("-0600@name-space-daylight-saving-time")
353
353
  expect(zone_without_dst.to_str_with_dst_parameterized).to be_nil
354
354
  end
355
355
  end
@@ -7,7 +7,7 @@
7
7
  require "spec_helper"
8
8
 
9
9
  describe Lazier::Hash do
10
- let(:reference) {
10
+ subject {
11
11
  rv = {a: 1, "b" => {c: 2, d: {"e" => 3}}}
12
12
  rv.default = 0
13
13
  rv
@@ -17,10 +17,9 @@ describe Lazier::Hash do
17
17
  ::Lazier.load!
18
18
  end
19
19
 
20
-
21
20
  describe "method access" do
22
21
  it "it is not enabled by default" do
23
- expect { reference.b }.to raise_error(NoMethodError)
22
+ expect { subject.b }.to raise_error(NoMethodError)
24
23
  end
25
24
  end
26
25
 
@@ -29,12 +28,12 @@ describe Lazier::Hash do
29
28
  ::Lazier.load!(:hash_method_access)
30
29
  end
31
30
 
32
- it "should allow method reference for symbol key" do
33
- reference.b.f = 4
31
+ it "should allow method subject for symbol key" do
32
+ subject.b.f = 4
34
33
 
35
- expect(reference.a).to eq(1)
36
- expect(reference.b.c).to eq(2)
37
- expect(reference["b"]["f"]).to eq(4)
34
+ expect(subject.a).to eq(1)
35
+ expect(subject.b.c).to eq(2)
36
+ expect(subject["b"]["f"]).to eq(4)
38
37
  end
39
38
  end
40
39
 
@@ -48,23 +47,23 @@ describe Lazier::Hash do
48
47
  end
49
48
 
50
49
  it "should not be destructive" do
51
- reference = {a: 1, b: nil}
52
- reference.compact
53
- expect(reference).to eq({a: 1, b: nil})
50
+ subject = {a: 1, b: nil}
51
+ subject.compact
52
+ expect(subject).to eq({a: 1, b: nil})
54
53
  end
55
54
  end
56
55
 
57
56
  describe "#compact!" do
58
57
  it "should remove blank keys" do
59
- reference = {a: 1, b: nil}
60
- reference.compact!
61
- expect(reference).to eq({a: 1})
58
+ subject = {a: 1, b: nil}
59
+ subject.compact!
60
+ expect(subject).to eq({a: 1})
62
61
  end
63
62
 
64
63
  it "should use a custom validator" do
65
- reference = {a: 1, b: nil, c: 3}
66
- reference.compact! {|k, v| v == 1 || k == :c}
67
- expect(reference).to eq({b: nil})
64
+ subject = {a: 1, b: nil, c: 3}
65
+ subject.compact! {|k, v| v == 1 || k == :c}
66
+ expect(subject).to eq({b: nil})
68
67
  end
69
68
  end
70
69
 
@@ -79,25 +78,27 @@ describe Lazier::Hash do
79
78
  expect({a: "b"}.ensure_access(:indifferent)).to be_a(::HashWithIndifferentAccess)
80
79
  expect({a: "b"}.ensure_access(:other)).to eq({a: "b"})
81
80
 
82
- reference.ensure_access(:dotted)
83
- expect(reference.a).to eq(1)
84
- expect(reference.b.c).to eq(2)
81
+ accessed = subject.ensure_access(:indifferent, :dotted)
82
+ expect(accessed[:a]).to eq(1)
83
+ expect(accessed["a"]).to eq(1)
84
+ expect(accessed.a).to eq(1)
85
+ expect(accessed.b.c).to eq(2)
85
86
  end
86
87
  end
87
88
 
88
89
  describe "#with_dotted_access" do
89
90
  it "should recursively enable dotted access on a hash" do
90
- reference = {a: 1, b: {c: 3}, c: [1, {f: {g: 1}}]}
91
+ subject = {a: 1, b: {c: 3}, c: [1, {f: {g: 1}}]}
91
92
 
92
- reference.enable_dotted_access
93
- expect(reference.b.c).to eq(3)
94
- expect(reference.c[1].f.g).to eq(1)
93
+ subject.enable_dotted_access
94
+ expect(subject.b.c).to eq(3)
95
+ expect(subject.c[1].f.g).to eq(1)
95
96
  end
96
97
 
97
98
  it "should also provide write access if asked" do
98
- reference.enable_dotted_access(false)
99
- expect { reference.b.f = 4 }.not_to raise_error
100
- expect(reference["b"]["f"]).to eq(4)
99
+ subject.enable_dotted_access(false)
100
+ expect { subject.b.f = 4 }.not_to raise_error
101
+ expect(subject["b"]["f"]).to eq(4)
101
102
  end
102
103
  end
103
104
  end
@@ -7,8 +7,8 @@
7
7
  require "spec_helper"
8
8
 
9
9
  describe Lazier::I18n do
10
- let(:object) {
11
- c = Object.new
10
+ subject {
11
+ c = ::Object.new
12
12
  c.class_eval { include Lazier::I18n }
13
13
  c
14
14
  }
@@ -22,39 +22,39 @@ describe Lazier::I18n do
22
22
 
23
23
  describe "#i18n_setup" do
24
24
  it "should set the root and the path" do
25
- object.i18n_setup("ROOT", root_path)
26
- expect(object.instance_variable_get(:@i18n_root)).to eq(:ROOT)
27
- expect(object.instance_variable_get(:@i18n_locales_path)).to eq(root_path)
25
+ subject.i18n_setup("ROOT", root_path)
26
+ expect(subject.instance_variable_get(:@i18n_root)).to eq(:ROOT)
27
+ expect(subject.instance_variable_get(:@i18n_locales_path)).to eq(root_path)
28
28
  end
29
29
  end
30
30
 
31
31
  describe "#i18n" do
32
32
  it "should call the private method if nothing is set" do
33
- object.instance_variable_set(:@i18n, nil)
34
- expect(object).to receive(:i18n_load_locale)
35
- object.i18n
33
+ subject.instance_variable_set(:@i18n, nil)
34
+ expect(subject).to receive(:i18n_load_locale)
35
+ subject.i18n
36
36
  end
37
37
  end
38
38
 
39
39
  describe "#i18n=" do
40
40
  it "should call the private method if nothing is set" do
41
- expect(object).to receive(:i18n_load_locale).and_return("LOCALE")
42
- object.i18n = :en
43
- expect(object.instance_variable_get(:@i18n)).to eq("LOCALE")
41
+ expect(subject).to receive(:i18n_load_locale).and_return("LOCALE")
42
+ subject.i18n = :en
43
+ expect(subject.instance_variable_get(:@i18n)).to eq("LOCALE")
44
44
  end
45
45
  end
46
46
 
47
47
  describe "#i18n_load_locale" do
48
48
  it "should set using system locale if called without arguments" do
49
- object.i18n_setup("lazier", root_path)
49
+ subject.i18n_setup("lazier", root_path)
50
50
  expect(::R18n::I18n).to receive(:new).with([ENV["LANG"]].compact.uniq, root_path).and_call_original
51
- object.i18n = nil
51
+ subject.i18n = nil
52
52
  end
53
53
 
54
54
  it "should set the requested locale" do
55
- object.i18n_setup("lazier", root_path)
55
+ subject.i18n_setup("lazier", root_path)
56
56
  expect(::R18n::I18n).to receive(:new).with(["it", ENV["LANG"]].compact.uniq, root_path).and_call_original
57
- object.i18n = :it
57
+ subject.i18n = :it
58
58
  end
59
59
 
60
60
  it "should call the root" do
@@ -62,21 +62,21 @@ describe Lazier::I18n do
62
62
  t = ::Object.new
63
63
  expect_any_instance_of(::R18n::I18n).to receive(:t).and_return(t)
64
64
  expect(t).to receive("ROOT")
65
- object.i18n_setup("ROOT", root_path)
66
- object.i18n = :it
65
+ subject.i18n_setup("ROOT", root_path)
66
+ subject.i18n = :it
67
67
  end
68
68
 
69
69
  it "should only pass valid translations" do
70
- object.i18n_setup("lazier", root_path)
70
+ subject.i18n_setup("lazier", root_path)
71
71
  expect(::R18n::I18n).to receive(:new).with([ENV["LANG"]].compact.uniq, root_path).and_call_original
72
- object.i18n = "INVALID"
72
+ subject.i18n = "INVALID"
73
73
  end
74
74
 
75
75
  it "should raise an exception if no valid translation are found" do
76
76
  ENV["LANG"] = "INVALID"
77
77
  allow(::R18n::I18n).to receive(:system_locale).and_return("INVALID")
78
- object.i18n_setup("ROOT", "/dev/")
79
- expect { object.i18n = "INVALID" }.to raise_error(::Lazier::Exceptions::MissingTranslation)
78
+ subject.i18n_setup("ROOT", "/dev/")
79
+ expect { subject.i18n = "INVALID" }.to raise_error(::Lazier::Exceptions::MissingTranslation)
80
80
  end
81
81
  end
82
82
  end