lazier 3.5.7 → 4.0.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.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/.travis-gemfile +5 -4
  3. data/.travis.yml +2 -2
  4. data/CHANGELOG.md +65 -8
  5. data/Gemfile +9 -8
  6. data/README.md +4 -0
  7. data/doc/Lazier.html +178 -110
  8. data/doc/Lazier/Boolean.html +7 -7
  9. data/doc/Lazier/Configuration.html +24 -50
  10. data/doc/Lazier/DateTime.html +50 -305
  11. data/doc/Lazier/DateTime/ClassMethods.html +116 -806
  12. data/doc/Lazier/Exceptions.html +2 -2
  13. data/doc/Lazier/Exceptions/Debug.html +1 -1
  14. data/doc/Lazier/Exceptions/MissingTranslation.html +18 -14
  15. data/doc/Lazier/Exceptions/TranslationExceptionHandler.html +213 -0
  16. data/doc/Lazier/Hash.html +19 -155
  17. data/doc/Lazier/I18n.html +1735 -230
  18. data/doc/Lazier/Math.html +1 -1
  19. data/doc/Lazier/Math/ClassMethods.html +13 -13
  20. data/doc/Lazier/Object.html +353 -339
  21. data/doc/Lazier/Pathname.html +4 -4
  22. data/doc/Lazier/Settings.html +150 -304
  23. data/doc/Lazier/String.html +39 -199
  24. data/doc/Lazier/TimeZone.html +244 -746
  25. data/doc/Lazier/TimeZone/ClassMethods.html +109 -127
  26. data/doc/Lazier/Version.html +4 -4
  27. data/doc/_index.html +15 -15
  28. data/doc/class_list.html +1 -1
  29. data/doc/file.README.html +5 -1
  30. data/doc/index.html +5 -1
  31. data/doc/method_list.html +97 -169
  32. data/doc/top-level-namespace.html +1 -1
  33. data/lazier.gemspec +9 -6
  34. data/lib/lazier.rb +41 -50
  35. data/lib/lazier/boolean.rb +0 -1
  36. data/lib/lazier/configuration.rb +26 -28
  37. data/lib/lazier/datetime.rb +33 -127
  38. data/lib/lazier/exceptions.rb +14 -6
  39. data/lib/lazier/hash.rb +7 -15
  40. data/lib/lazier/i18n.rb +130 -48
  41. data/lib/lazier/math.rb +6 -7
  42. data/lib/lazier/object.rb +79 -97
  43. data/lib/lazier/pathname.rb +0 -1
  44. data/lib/lazier/settings.rb +12 -25
  45. data/lib/lazier/string.rb +17 -38
  46. data/lib/lazier/timezone.rb +168 -164
  47. data/lib/lazier/version.rb +3 -4
  48. data/locales/en.yml +52 -51
  49. data/locales/it.yml +51 -50
  50. data/spec/coverage_helper.rb +0 -1
  51. data/spec/lazier/boolean_spec.rb +2 -3
  52. data/spec/lazier/configuration_spec.rb +3 -5
  53. data/spec/lazier/datetime_spec.rb +34 -95
  54. data/spec/lazier/exceptions_spec.rb +25 -0
  55. data/spec/lazier/hash_spec.rb +0 -21
  56. data/spec/lazier/i18n_spec.rb +135 -51
  57. data/spec/lazier/math_spec.rb +0 -1
  58. data/spec/lazier/object_spec.rb +105 -100
  59. data/spec/lazier/pathname_spec.rb +0 -1
  60. data/spec/lazier/settings_spec.rb +25 -28
  61. data/spec/lazier/string_spec.rb +7 -20
  62. data/spec/lazier/timezone_spec.rb +101 -87
  63. data/spec/lazier_spec.rb +25 -8
  64. data/spec/spec_helper.rb +3 -2
  65. metadata +15 -44
  66. data/doc/Lazier/Localizer.html +0 -545
  67. data/lib/lazier/localizer.rb +0 -41
  68. data/spec/lazier/localizer_spec.rb +0 -45
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  #
3
2
  # This file is part of the lazier gem. Copyright (C) 2013 and above Shogun <shogun@cowtech.it>.
4
3
  # Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  #
3
2
  # This file is part of the lazier gem. Copyright (C) 2013 and above Shogun <shogun@cowtech.it>.
4
3
  # Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
@@ -9,11 +8,10 @@ require "spec_helper"
9
8
  describe Lazier::Settings do
10
9
  let(:subject) { ::Lazier::Settings.instance }
11
10
  let(:number_subject) { 123456.654321 }
12
- let(:date_subject) { DateTime.civil(2005, 6, 7, 8, 9, 10, DateTime.rationalize_offset(25200)) }
11
+ let(:date_subject) { DateTime.civil(2005, 6, 7, 8, 9, 10, ::ActiveSupport::TimeZone.rationalize_offset(25200)) }
13
12
 
14
13
  before(:all) do
15
14
  Lazier.load!
16
- ::Lazier::Settings.instance.i18n = :en
17
15
  end
18
16
 
19
17
  describe ".instance" do
@@ -45,16 +43,16 @@ describe Lazier::Settings do
45
43
 
46
44
  describe "#setup_format_number" do
47
45
  it "should save format numbering options for usage" do
48
- subject.setup_format_number(2)
46
+ subject.setup_format_number(precision: 2)
49
47
  expect(number_subject.format_number).to eq("123,456.65")
50
48
 
51
- subject.setup_format_number(3, "A")
49
+ subject.setup_format_number(precision: 3, decimal_separator: "A")
52
50
  expect(number_subject.format_number).to eq("123,456A654")
53
51
 
54
- subject.setup_format_number(4, "A", "B")
52
+ subject.setup_format_number(precision: 4, decimal_separator: "A", add_string: "B")
55
53
  expect(number_subject.format_number).to eq("123,456A6543 B")
56
54
 
57
- subject.setup_format_number(5, "A", "B", "C")
55
+ subject.setup_format_number(precision: 5, decimal_separator: "A", add_string: "B", k_separator: "C")
58
56
  expect(number_subject.format_number).to eq("123C456A65432 B")
59
57
 
60
58
  subject.setup_format_number
@@ -64,13 +62,13 @@ describe Lazier::Settings do
64
62
 
65
63
  describe "#setup_boolean_names" do
66
64
  it "should save names for boolean values" do
67
- subject.setup_boolean_names("TRUE1")
65
+ subject.setup_boolean_names(true_name: "TRUE1")
68
66
  expect([true.format_boolean, false.format_boolean]).to eq(["TRUE1", "No"])
69
67
 
70
- subject.setup_boolean_names(nil, "FALSE1")
68
+ subject.setup_boolean_names(false_name: "FALSE1")
71
69
  expect([true.format_boolean, false.format_boolean]).to eq(["Yes", "FALSE1"])
72
70
 
73
- subject.setup_boolean_names("TRUE2", "FALSE2")
71
+ subject.setup_boolean_names(true_name: "TRUE2", false_name: "FALSE2")
74
72
  expect([true.format_boolean, false.format_boolean]).to eq(["TRUE2", "FALSE2"])
75
73
 
76
74
  subject.setup_boolean_names
@@ -83,26 +81,25 @@ describe Lazier::Settings do
83
81
  subject.setup_date_formats(nil, true)
84
82
 
85
83
  subject.setup_date_formats({c1: "%Y"})
86
- expect(date_subject.lstrftime(:ct_date)).to eq(date_subject.strftime("%Y-%m-%d"))
87
- expect(date_subject.lstrftime("c1")).to eq(date_subject.year.to_s)
84
+ expect(date_subject.format(:ct_date)).to eq(date_subject.strftime("%Y-%m-%d"))
85
+ expect(date_subject.format("c1")).to eq(date_subject.year.to_s)
88
86
 
89
87
  subject.setup_date_formats({c1: "%Y"}, true)
90
- expect(date_subject.lstrftime("ct_date")).to eq("ct_date")
91
- expect(date_subject.lstrftime(:c1)).to eq(date_subject.year.to_s)
88
+ expect(date_subject.format("ct_date")).to eq("ct_date")
89
+ expect(date_subject.format(:c1)).to eq(date_subject.year.to_s)
92
90
 
93
91
  subject.setup_date_formats
94
- expect(date_subject.lstrftime(:ct_date)).to eq(date_subject.strftime("%Y-%m-%d"))
95
- expect(date_subject.lstrftime("c1")).to eq(date_subject.year.to_s)
92
+ expect(date_subject.format(:ct_date)).to eq(date_subject.strftime("%Y-%m-%d"))
93
+ expect(date_subject.format("c1")).to eq(date_subject.year.to_s)
96
94
 
97
95
  subject.setup_date_formats(nil, true)
98
- expect(date_subject.lstrftime("ct_date")).to eq(date_subject.strftime("%Y-%m-%d"))
99
- expect(date_subject.lstrftime(:c1)).to eq("c1")
96
+ expect(date_subject.format("ct_date")).to eq(date_subject.strftime("%Y-%m-%d"))
97
+ expect(date_subject.format(:c1)).to eq("c1")
100
98
  end
101
99
  end
102
100
 
103
101
  describe "#setup_date_names" do
104
102
  it "should save names for days and months" do
105
- subject.i18n = :en
106
103
  subject.setup_date_names
107
104
  subject.setup_date_formats({sdn: "%B %b %A %a"})
108
105
 
@@ -111,20 +108,20 @@ describe Lazier::Settings do
111
108
  long_days = 7.times.map {|i| (i + 1).to_s * 2}
112
109
  short_days = 7.times.map {|i| (i + 1).to_s}
113
110
 
114
- subject.setup_date_names(long_months)
115
- expect(date_subject.lstrftime(:sdn)).to eq("66 Jun Tuesday Tue")
111
+ subject.setup_date_names(long_months: long_months)
112
+ expect(date_subject.format(:sdn)).to eq("66 Jun Tuesday Tue")
116
113
 
117
- subject.setup_date_names(long_months, short_months)
118
- expect(date_subject.lstrftime("sdn")).to eq("66 6 Tuesday Tue")
114
+ subject.setup_date_names(long_months: long_months, short_months: short_months)
115
+ expect(date_subject.format("sdn")).to eq("66 6 Tuesday Tue")
119
116
 
120
- subject.setup_date_names(long_months, short_months, long_days)
121
- expect(date_subject.lstrftime(:sdn)).to eq("66 6 33 Tue")
117
+ subject.setup_date_names(long_months: long_months, short_months: short_months, long_days: long_days)
118
+ expect(date_subject.format(:sdn)).to eq("66 6 33 Tue")
122
119
 
123
- subject.setup_date_names(long_months, short_months, long_days, short_days)
124
- expect(date_subject.lstrftime("sdn")).to eq("66 6 33 3")
120
+ subject.setup_date_names(long_months: long_months, short_months: short_months, long_days: long_days, short_days: short_days)
121
+ expect(date_subject.format("sdn")).to eq("66 6 33 3")
125
122
 
126
123
  subject.setup_date_names
127
- expect(date_subject.lstrftime(:sdn)).to eq("June Jun Tuesday Tue")
124
+ expect(date_subject.format(:sdn)).to eq("June Jun Tuesday Tue")
128
125
  end
129
126
  end
130
127
  end
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  #
3
2
  # This file is part of the lazier gem. Copyright (C) 2013 and above Shogun <shogun@cowtech.it>.
4
3
  # Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
@@ -30,18 +29,6 @@ describe Lazier::String do
30
29
  end
31
30
  end
32
31
 
33
- describe "#untitleize" do
34
- it "should convert spaces to dashes" do
35
- expect(subject.untitleize).to eq(untitleized_subject)
36
- end
37
- end
38
-
39
- describe "#replace_ampersands" do
40
- it "should remove HTML ampersands" do
41
- expect(subject.replace_ampersands).to eq(amp_subject)
42
- end
43
- end
44
-
45
32
  describe "#value" do
46
33
  it "should return the string itself" do
47
34
  expect(subject.value).to eq(subject)
@@ -51,14 +38,14 @@ describe Lazier::String do
51
38
  end
52
39
  end
53
40
 
54
- describe "split_tokens" do
41
+ describe "tokenize" do
55
42
  it "should return a valid array" do
56
- expect(" 1, 2,3,4,,,,,5,5".split_tokens()).to eq(["1", "2", "3", "4", "5", "5"])
57
- expect(" 1, 2,3,4,,,,,5,5".split_tokens(false)).to eq(["1", "2", "3", "4", "", "", "", "", "5", "5"])
58
- expect(" 1, 2,3,4,,,,,5,5".split_tokens(true, false)).to eq([" 1", "2", "3", "4", "5", "5"])
59
- expect(" 1, 2,3,4,,,,,5,5".split_tokens(true, true, true)).to eq(["1", "2", "3", "4", "5"])
60
- expect(" 1, 2,3,4,,,,,5,5".split_tokens(true, true, false, "@")).to eq(["1, 2,3,4,,,,,5,5"])
61
- expect("1@2@3@4@5".split_tokens(true, true, false, "@")).to eq(["1", "2", "3", "4", "5"])
43
+ expect(" 1, 2,3,4,,,,,5,5".tokenize()).to eq(["1", "2", "3", "4", "5", "5"])
44
+ expect(" 1, 2,3,4,,,,,5,5".tokenize(no_blanks: false)).to eq(["1", "2", "3", "4", "", "", "", "", "5", "5"])
45
+ expect(" 1, 2,3,4,,,,,5,5".tokenize(strip: false)).to eq([" 1", "2", "3", "4", "5", "5"])
46
+ expect(" 1, 2,3,4,,,,,5,5".tokenize(no_duplicates: true)).to eq(["1", "2", "3", "4", "5"])
47
+ expect(" 1, 2,3,4,,,,,5,5".tokenize(pattern: "@")).to eq(["1, 2,3,4,,,,,5,5"])
48
+ expect("1@2@3@4@5".tokenize(pattern: "@")).to eq(["1", "2", "3", "4", "5"])
62
49
  end
63
50
  end
64
51
  end
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  #
3
2
  # This file is part of the lazier gem. Copyright (C) 2013 and above Shogun <shogun@cowtech.it>.
4
3
  # Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
@@ -7,18 +6,17 @@
7
6
  require "spec_helper"
8
7
 
9
8
  describe Lazier::TimeZone do
9
+ let(:subject_zone) { ::ActiveSupport::TimeZone["Mountain Time (US & Canada)"] }
10
10
  let(:subject_zone) { ::ActiveSupport::TimeZone["Mountain Time (US & Canada)"] }
11
11
  let(:zone_without_dst) { ::ActiveSupport::TimeZone["International Date Line West"] }
12
12
 
13
13
  before(:all) do
14
14
  ::Lazier.load!
15
- ::Lazier::Settings.instance(true)
16
- ::Lazier::Settings.instance.i18n = :en
15
+ ::Time.zone = ::ActiveSupport::TimeZone["Mountain Time (US & Canada)"]
17
16
  end
18
17
 
19
18
  describe ".rationalize_offset" do
20
19
  it "should return the correct rational value" do
21
- expect(::ActiveSupport::TimeZone.rationalize_offset(::ActiveSupport::TimeZone[4])).to eq(Rational(1, 6))
22
20
  expect(::ActiveSupport::TimeZone.rationalize_offset(-25200)).to eq(Rational(-7, 24))
23
21
  end
24
22
  end
@@ -30,52 +28,74 @@ describe Lazier::TimeZone do
30
28
  end
31
29
  end
32
30
 
33
- describe ".parameterize_zone" do
34
- it "should return the parameterized version of the zone" do
35
- expect(::ActiveSupport::TimeZone.parameterize_zone(subject_zone.to_str)).to eq(subject_zone.to_str_parameterized)
36
- expect(::ActiveSupport::TimeZone.parameterize_zone(subject_zone.to_str)).to eq(subject_zone.to_str_parameterized)
37
- expect(::ActiveSupport::TimeZone.parameterize_zone(subject_zone.to_str, false)).to eq(subject_zone.to_str_parameterized(false))
38
- expect(::ActiveSupport::TimeZone.parameterize_zone("INVALID")).to eq("invalid")
31
+ describe ".find" do
32
+ it "should find timezones" do
33
+ expect(::ActiveSupport::TimeZone.find("(GMT-07:00) Mountain Time (US & Canada)")).to eq(subject_zone)
34
+ expect(::ActiveSupport::TimeZone.find("(GMT-06:00) Mountain Time (US & Canada) (DST)")).to eq(subject_zone)
35
+ expect(::ActiveSupport::TimeZone.find("(GMT-06:00) Mountain Time (US & Canada) Daylight Saving Time", " Daylight Saving Time")).to eq(subject_zone)
36
+ expect(::ActiveSupport::TimeZone.find("INVALID", "INVALID")).to be_nil
37
+ end
38
+ end
39
+
40
+ describe ".list" do
41
+ it "should list all timezones as list" do
42
+ expect(::ActiveSupport::TimeZone.list(false)).to include("(GMT-11:00) Pacific/American Samoa", "(GMT-11:00) International Date Line West")
43
+ expect(::ActiveSupport::TimeZone.list(false).first).to eq("(GMT+01:00) Africa/Algiers")
44
+ expect(::ActiveSupport::TimeZone.list(false, sort_by_name: false).first).to eq("(GMT-11:00) Pacific/American Samoa")
45
+ expect(::ActiveSupport::TimeZone.list(false)).to include("(GMT-11:00) Pacific/American Samoa", "(GMT-11:00) International Date Line West")
46
+ expect(::ActiveSupport::TimeZone.list(true)).to include("(GMT-06:00) #{subject_zone.aliases.first} (DST)")
47
+ expect(::ActiveSupport::TimeZone.list(true, dst_label: " Daylight Saving Time")).to include("(GMT-06:00) #{subject_zone.aliases.first} Daylight Saving Time")
48
+ expect(::ActiveSupport::TimeZone.list(true, parameterized: true)).to include("-0600@mountain-time-us-canada-dst")
49
+ end
50
+
51
+ it "should list all timezones as hash" do
52
+ expect(::ActiveSupport::TimeZone.list(true, sort_by_name: true, as_hash: true)["(GMT-06:00) #{subject_zone.aliases.first} (DST)"]).to eq(subject_zone)
53
+ expect(::ActiveSupport::TimeZone.list(true, sort_by_name: true, as_hash: true).keys.first).to eq("(GMT+01:00) Africa/Algiers")
54
+ expect(::ActiveSupport::TimeZone.list(true, sort_by_name: false, as_hash: true).keys.first).to eq("(GMT-11:00) Pacific/American Samoa")
55
+ expect(::ActiveSupport::TimeZone.list(true, as_hash: true, parameterized: true)).to include("-0700@mountain-time-us-canada")
56
+
39
57
  end
40
58
  end
41
59
 
42
- describe ".unparameterize_zone" do
60
+ describe ".parameterize" do
43
61
  it "should return the parameterized version of the zone" do
44
- expect(::ActiveSupport::TimeZone.unparameterize_zone(subject_zone.to_str_parameterized)).to eq(subject_zone)
45
- expect(::ActiveSupport::TimeZone.unparameterize_zone(subject_zone.to_str_parameterized, true)).to eq(subject_zone.to_str)
46
- expect(::ActiveSupport::TimeZone.unparameterize_zone(subject_zone.to_str_with_dst_parameterized)).to eq(subject_zone)
47
- expect(::ActiveSupport::TimeZone.unparameterize_zone(subject_zone.to_str_with_dst_parameterized, true)).to eq(subject_zone.to_str_with_dst)
48
- expect(::ActiveSupport::TimeZone.unparameterize_zone("INVALID")).to eq(nil)
62
+ expect(::ActiveSupport::TimeZone.parameterize(subject_zone)).to eq("-0700@mountain-time-us-canada")
63
+ expect(::ActiveSupport::TimeZone.parameterize(subject_zone.to_str)).to eq("-0700@mountain-time-us-canada")
64
+ expect(::ActiveSupport::TimeZone.parameterize(subject_zone, false)).to eq("mountain-time-us-canada")
65
+ expect(::ActiveSupport::TimeZone.parameterize("INVALID")).to eq("invalid")
66
+ expect(::ActiveSupport::TimeZone.parameterize("-0700@mountain-time-us-canada")).to eq("-0700@mountain-time-us-canada")
49
67
  end
50
68
  end
51
69
 
52
- describe ".find" do
53
- it "should find timezones" do
54
- expect(::ActiveSupport::TimeZone.find("(GMT-07:00) Mountain Time (US & Canada)")).to eq(subject_zone)
55
- expect(::ActiveSupport::TimeZone.find("(GMT-06:00) Mountain Time (US & Canada) (DST)")).to eq(subject_zone)
56
- expect(::ActiveSupport::TimeZone.find("(GMT-06:00) Mountain Time (US & Canada) Daylight Saving Time", "Daylight Saving Time")).to eq(subject_zone)
57
- expect(::ActiveSupport::TimeZone.find("INVALID", "INVALID")).to be_nil
70
+ describe ".unparameterize" do
71
+ it "should return the parameterized version of the zone" do
72
+ expect(::ActiveSupport::TimeZone.unparameterize("-0700@mountain-time-us-canada")).to eq(subject_zone)
73
+ expect(::ActiveSupport::TimeZone.unparameterize("mountain-time-us-canada")).to be_nil
74
+ expect(::ActiveSupport::TimeZone.unparameterize("-0600@mountain-time-us-canada-day", " DAY")).to eq(subject_zone)
75
+ expect(::ActiveSupport::TimeZone.unparameterize(subject_zone.to_str)).to eq(subject_zone)
76
+ expect(::ActiveSupport::TimeZone.unparameterize("INVALID")).to eq(nil)
58
77
  end
59
78
  end
60
79
 
61
- describe ".list_all" do
62
- it "should list all timezones" do
63
- expect(::ActiveSupport::TimeZone.list_all(false)).to eq(::ActiveSupport::TimeZone.all.map(&:to_s))
64
- expect(::ActiveSupport::TimeZone.list_all(true)).to include("(GMT-06:00) #{subject_zone.aliases.first} (DST)")
65
- expect(::ActiveSupport::TimeZone.list_all(true, "Daylight Saving Time")).to include("(GMT-06:00) #{subject_zone.aliases.first} Daylight Saving Time")
80
+ describe "#compare" do
81
+ it "should correctly compare timezones" do
82
+ expect(::ActiveSupport::TimeZone.compare(::ActiveSupport::TimeZone["Africa/Algiers"], ::ActiveSupport::TimeZone["International Date Line West"])).to eq(-1)
83
+ expect(::ActiveSupport::TimeZone.compare(::ActiveSupport::TimeZone["Africa/Algiers"], ::ActiveSupport::TimeZone["Africa/Algiers"])).to eq(0)
84
+ expect(::ActiveSupport::TimeZone.compare(::ActiveSupport::TimeZone["Europe/Madrid"], ::ActiveSupport::TimeZone["Europe/Copenhagen"])).to eq(1)
85
+ expect(::ActiveSupport::TimeZone.compare("(GMT+01:00) Europe/Rome", "(GMT+02:00) Europe/Kiev")).to eq(1)
66
86
  end
67
87
  end
68
88
 
69
- describe "#offset" do
70
- it "should correctly return zone offset" do
71
- expect(subject_zone.offset).to eq(subject_zone.utc_offset)
89
+ describe "#aliases" do
90
+ it "should return the right list of aliases" do
91
+ expect(ActiveSupport::TimeZone["America/Los_Angeles"].aliases).to eq(["America/Los Angeles", "Pacific Time (US & Canada)"])
72
92
  end
73
93
  end
74
94
 
75
95
  describe "#current_offset" do
76
96
  it "should correctly return current zone offset" do
77
- expect(subject_zone.current_offset(false, ::DateTime.civil(2012, 1, 15))).to eq(subject_zone.offset)
78
- expect(subject_zone.current_offset(true, ::DateTime.civil(2012, 7, 15))).to eq(subject_zone.dst_offset(true))
97
+ expect(subject_zone.current_offset(false, ::DateTime.civil(2012, 1, 15))).to eq(-25200)
98
+ expect(subject_zone.current_offset(true, ::DateTime.civil(2012, 7, 15))).to eq(Rational(-1, 4))
79
99
  end
80
100
  end
81
101
 
@@ -83,43 +103,44 @@ describe Lazier::TimeZone do
83
103
  it "should correctly return current zone alias or the first one" do
84
104
  zone = ActiveSupport::TimeZone["America/Halifax"]
85
105
  expect(zone.current_alias).to eq("America/Halifax")
86
- allow(zone.tzinfo).to receive(:identifier).and_return("INVALID")
106
+ allow(zone).to receive(:name).and_return("INVALID")
87
107
  expect(zone.current_alias).to eq("America/Atlantic Time (Canada)")
88
108
  end
89
109
  end
90
110
 
91
- describe "#current_alias=" do
92
- it "should set the current alias alias" do
93
- zone = ActiveSupport::TimeZone["America/Halifax"]
94
- zone.current_alias = "ALIAS"
95
- expect(zone.current_alias).to eq("ALIAS")
111
+ describe "#current_name" do
112
+ it "should correctly get zone name with Daylight Saving Time" do
113
+ expect(subject_zone.current_name).to eq("Mountain Time (US & Canada)")
114
+ expect(subject_zone.current_name(true)).to eq("Mountain Time (US & Canada) (DST)")
115
+ expect(subject_zone.current_name(true, dst_label: "-dst")).to eq("Mountain Time (US & Canada)-dst")
116
+ expect(subject_zone.current_name(true, year: 1000)).to eq("Mountain Time (US & Canada)")
96
117
  end
97
118
  end
98
119
 
99
- describe "#dst_period" do
120
+ describe "#offset" do
100
121
  it "should correctly return zone offset" do
101
- expect(subject_zone.dst_period).to be_a(::TZInfo::TimezonePeriod)
102
- expect(subject_zone.dst_period(1000)).to be_nil
103
- expect(zone_without_dst.dst_period).to be_nil
122
+ expect(subject_zone.offset).to eq(subject_zone.utc_offset)
104
123
  end
105
124
  end
106
125
 
107
126
  describe "#uses_dst?" do
108
127
  it "should correctly detect offset usage" do
109
- expect(subject_zone.uses_dst?).to be_true
110
- expect(subject_zone.uses_dst?(::DateTime.civil(2012, 7, 15))).to be_true
111
- expect(subject_zone.uses_dst?(::DateTime.civil(2012, 1, 15))).to be_false
112
- expect(subject_zone.uses_dst?(1000)).to be_false
113
- expect(zone_without_dst.uses_dst?).to be_false
128
+ expect(subject_zone.uses_dst?).to be_truthy
129
+ expect(subject_zone.uses_dst?(::DateTime.civil(2012, 7, 15))).to be_truthy
130
+ expect(subject_zone.uses_dst?(::DateTime.civil(2012, 1, 15))).to be_falsey
131
+ expect(subject_zone.uses_dst?(1000)).to be_falsey
132
+ expect(zone_without_dst.uses_dst?).to be_falsey
114
133
  end
115
134
  end
116
135
 
117
- describe "#dst_name" do
118
- it "should correctly get zone name with Daylight Saving Time" do
119
- expect(subject_zone.dst_name).to eq("Mountain Time (US & Canada) (DST)")
120
- expect(subject_zone.dst_name("Daylight Saving Time")).to eq("Mountain Time (US & Canada) Daylight Saving Time")
121
- expect(subject_zone.dst_name(nil, 1000)).to be_nil
122
- expect(zone_without_dst.to_str_with_dst).to be_nil
136
+ describe "#dst_period" do
137
+ it "should correctly return zone offset" do
138
+ expect(subject_zone.dst_period).to be_a(::TZInfo::TimezonePeriod)
139
+ expect(subject_zone.dst_period(1000)).to be_nil
140
+ expect(zone_without_dst.dst_period).to be_nil
141
+
142
+ expect(zone_without_dst).to receive(:period_for_utc).and_raise(RuntimeError)
143
+ expect(zone_without_dst.dst_period).to be_nil
123
144
  end
124
145
  end
125
146
 
@@ -132,40 +153,33 @@ describe Lazier::TimeZone do
132
153
  end
133
154
  end
134
155
 
135
- describe "#dst_offset" do
136
- it "should correctly return zone offset" do
137
- expect(subject_zone.dst_offset).to eq(subject_zone.dst_correction + subject_zone.utc_offset)
138
- expect(subject_zone.dst_offset(true)).to eq(::ActiveSupport::TimeZone.rationalize_offset(subject_zone.dst_correction + subject_zone.utc_offset))
139
- expect(zone_without_dst.dst_offset(false, 1000)).to eq(0)
140
- expect(zone_without_dst.dst_offset).to eq(0)
141
- end
142
- end
143
-
144
- describe "#to_str_with_dst" do
145
- it "should correctly format zone with Daylight Saving Time" do
146
- expect(subject_zone.to_str_with_dst).to eq("(GMT-06:00) #{subject_zone.current_alias} (DST)")
147
- expect(subject_zone.to_str_with_dst("Daylight Saving Time")).to eq("(GMT-06:00) #{subject_zone.current_alias} Daylight Saving Time")
148
- expect(subject_zone.to_str_with_dst("Daylight Saving Time", nil, "NAME")).to eq("(GMT-06:00) NAME Daylight Saving Time")
149
- expect(subject_zone.to_str_with_dst(nil, 1000)).to be_nil
150
- expect(zone_without_dst.to_str_with_dst).to be_nil
151
- end
152
- end
153
-
154
- describe "#to_str_parameterized" do
155
- it "should correctly format (parameterized) zone" do
156
- expect(subject_zone.to_str_parameterized).to eq(::ActiveSupport::TimeZone.parameterize_zone(subject_zone.to_str))
157
- expect(subject_zone.to_str_parameterized(false)).to eq(::ActiveSupport::TimeZone.parameterize_zone(subject_zone.to_str, false))
158
- expect(subject_zone.to_str_parameterized(false, "NAME SPACE")).to eq(::ActiveSupport::TimeZone.parameterize_zone("NAME SPACE", false))
159
- end
160
- end
161
-
162
- describe "#to_str_with_dst_parameterized" do
163
- it "should correctly format (parameterized) zone with Daylight Saving Time" do
164
- expect(subject_zone.to_str_with_dst_parameterized).to eq("-0600@mountain-time-us-canada-dst")
165
- expect(subject_zone.to_str_with_dst_parameterized("Daylight Saving Time")).to eq("-0600@mountain-time-us-canada-daylight-saving-time")
166
- expect(subject_zone.to_str_with_dst_parameterized(nil, 1000)).to be_nil
167
- expect(subject_zone.to_str_with_dst_parameterized("Daylight Saving Time", nil, "NAME SPACE")).to eq("-0600@name-space-daylight-saving-time")
168
- expect(zone_without_dst.to_str_with_dst_parameterized).to be_nil
156
+ describe "#to_str" do
157
+ describe "parameterized" do
158
+ it "should correctly parameterize the zone" do
159
+ expect(subject_zone.to_str(parameterized: true, label: "FOO")).to eq("-0700@foo")
160
+ expect(subject_zone.to_str(parameterized: true)).to eq("-0700@mountain-time-us-canada")
161
+ expect(subject_zone.to_str(true, parameterized: true)).to eq("-0600@mountain-time-us-canada-dst")
162
+ expect(subject_zone.to_str(true, parameterized: true, dst_label: "-DAY")).to eq("-0600@mountain-time-us-canada-day")
163
+ expect(subject_zone.to_str(true, parameterized: true, utc_label: "UTC")).to eq("-0600@mountain-time-us-canada-dst")
164
+ expect(subject_zone.to_str(parameterized: true, year: 1000)).to eq("-0700@mountain-time-us-canada")
165
+ expect(subject_zone.to_str(parameterized: true, with_offset: false)).to eq("mountain-time-us-canada")
166
+ end
167
+ end
168
+
169
+ describe "not parameterized" do
170
+ it "should correctly parameterize the zone" do
171
+ expect(subject_zone.to_str(label: "FOO")).to eq("(GMT-07:00) FOO")
172
+ expect(subject_zone.to_str).to eq("(GMT-07:00) Mountain Time (US & Canada)")
173
+ expect(subject_zone.to_str(true)).to eq("(GMT-06:00) Mountain Time (US & Canada) (DST)")
174
+ expect(subject_zone.to_str(true, dst_label: "-DAY")).to eq("(GMT-06:00) Mountain Time (US & Canada)-DAY")
175
+ expect(subject_zone.to_str(true, utc_label: "UTC")).to eq("(UTC-06:00) Mountain Time (US & Canada) (DST)")
176
+ expect(subject_zone.to_str(year: 1000)).to eq("(GMT-07:00) Mountain Time (US & Canada)")
177
+ expect(subject_zone.to_str(with_offset: false)).to eq("Mountain Time (US & Canada)")
178
+ expect(subject_zone.to_str(offset_position: :end)).to eq("Mountain Time (US & Canada) (GMT-07:00)")
179
+ expect(subject_zone.to_str(offset_position: :other)).to eq("(GMT-07:00) Mountain Time (US & Canada)")
180
+ expect(subject_zone.to_str(colon: false)).to eq("(GMT-0700) Mountain Time (US & Canada)")
181
+ expect(subject_zone.to_str).to eq("(GMT-07:00) Mountain Time (US & Canada)")
182
+ end
169
183
  end
170
184
  end
171
185
  end
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  #
3
2
  # This file is part of the lazier gem. Copyright (C) 2013 and above Shogun <shogun@cowtech.it>.
4
3
  # Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
@@ -9,7 +8,6 @@ require "spec_helper"
9
8
  describe Lazier do
10
9
  describe ".load!" do
11
10
  describe "should load all extensions by default" do
12
- ENV["LANG"] = "en"
13
11
  ::Lazier.load!
14
12
 
15
13
  it "for Boolean" do
@@ -19,7 +17,7 @@ describe Lazier do
19
17
 
20
18
  it "for DateTime" do
21
19
  expect(::DateTime).to respond_to(:custom_format)
22
- expect(::DateTime.now).to respond_to(:lstrftime)
20
+ expect(::DateTime.now).to respond_to(:format)
23
21
  end
24
22
 
25
23
  it "for Hash" do
@@ -31,7 +29,7 @@ describe Lazier do
31
29
  end
32
30
 
33
31
  it "for Object" do
34
- expect(0).to respond_to(:for_debug)
32
+ expect(0).to respond_to(:to_debug)
35
33
  end
36
34
 
37
35
  it "for Pathname" do
@@ -39,7 +37,7 @@ describe Lazier do
39
37
  end
40
38
 
41
39
  it "for String" do
42
- expect("").to respond_to(:remove_accents)
40
+ expect("").to respond_to(:ensure_valid_utf8)
43
41
  end
44
42
  end
45
43
  end
@@ -87,12 +85,31 @@ describe Lazier do
87
85
  end
88
86
 
89
87
  it "without a message should return the elapsed time" do
90
- expect(Lazier.benchmark { control = "OK" }).to be_a(Float)
88
+ expect(Lazier.benchmark { "OK" }).to be_a(Float)
91
89
  end
92
90
 
93
91
  it "with a message should embed the elapsed time into the given message" do
94
- expect(Lazier.benchmark("MESSAGE") { control = "OK" }).to match(/^MESSAGE \(\d+ ms\)$/)
95
- expect(Lazier.benchmark("MESSAGE", 2) { control = "OK" }).to match(/^MESSAGE \(\d+\.\d+ ms\)$/)
92
+ expect(Lazier.benchmark(message: "MESSAGE") { "OK" }).to match(/^MESSAGE \(\d+ ms\)$/)
93
+ expect(Lazier.benchmark(message: "MESSAGE", precision: 2) { "OK" }).to match(/^MESSAGE \(\d+\.\d+ ms\)$/)
94
+ end
95
+ end
96
+
97
+ describe ".platform" do
98
+ it "should detect the right platform" do
99
+ stub_const("RUBY_PLATFORM", "cygwin")
100
+ expect(Lazier.platform(true)).to eq(:win32)
101
+
102
+ stub_const("RUBY_PLATFORM", "darwin")
103
+ expect(Lazier.platform(true)).to eq(:osx)
104
+
105
+ stub_const("RUBY_PLATFORM", "java")
106
+ expect(Lazier.platform(true)).to eq(:java)
107
+
108
+ stub_const("RUBY_PLATFORM", "whatever")
109
+ expect(Lazier.platform(true)).to eq(:posix)
110
+
111
+ stub_const("RUBY_PLATFORM", "osx")
112
+ expect(Lazier.platform).to eq(:posix)
96
113
  end
97
114
  end
98
115
  end