timeliness 0.3.7 → 0.3.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  describe Timeliness::Format do
4
2
  describe "#compile!" do
5
3
  it 'should compile valid string format' do
@@ -10,55 +8,55 @@ describe Timeliness::Format do
10
8
 
11
9
  it 'should return self' do
12
10
  format = Timeliness::Format.new('yyyy-mm-dd hh:nn:ss.u zo')
13
- format.compile!.should eq format
11
+ expect(format.compile!).to eq format
14
12
  end
15
13
 
16
14
  it 'should raise compilation error for bad format' do
17
15
  expect {
18
16
  Timeliness::Format.new('|--[)').compile!
19
- }.to raise_error(Timeliness::CompilationError)
17
+ }.to raise_error(Timeliness::Format::CompilationFailed)
20
18
  end
21
19
  end
22
20
 
23
21
  describe "#process" do
24
22
  it "should define method which outputs date array with values in correct order" do
25
- format_for('yyyy-mm-dd').process('2000', '1', '2').should eq [2000,1,2,nil,nil,nil,nil,nil]
23
+ expect(format_for('yyyy-mm-dd').process('2000', '1', '2')).to eq [2000,1,2,nil,nil,nil,nil,nil]
26
24
  end
27
25
 
28
26
  it "should define method which outputs date array from format with different order" do
29
- format_for('dd/mm/yyyy').process('2', '1', '2000').should eq [2000,1,2,nil,nil,nil,nil,nil]
27
+ expect(format_for('dd/mm/yyyy').process('2', '1', '2000')).to eq [2000,1,2,nil,nil,nil,nil,nil]
30
28
  end
31
29
 
32
30
  it "should define method which outputs date array with zeros when month and day are '0'" do
33
- format_for('m/d/yy').process('0', '0', '0000').should eq [0,0,0,nil,nil,nil,nil,nil]
31
+ expect(format_for('m/d/yy').process('0', '0', '0000')).to eq [0,0,0,nil,nil,nil,nil,nil]
34
32
  end
35
33
 
36
34
  it "should define method which outputs date array with zeros when month and day are '00'" do
37
- format_for('m/d/yy').process('00', '00', '0000').should eq [0,0,0,nil,nil,nil,nil,nil]
35
+ expect(format_for('m/d/yy').process('00', '00', '0000')).to eq [0,0,0,nil,nil,nil,nil,nil]
38
36
  end
39
37
 
40
38
  it "should define method which outputs time array" do
41
- format_for('hh:nn:ss').process('01', '02', '03').should eq [nil,nil,nil,1,2,3,nil,nil]
39
+ expect(format_for('hh:nn:ss').process('01', '02', '03')).to eq [nil,nil,nil,1,2,3,nil,nil]
42
40
  end
43
41
 
44
42
  it "should define method which outputs time array with meridian 'pm' adjusted hour" do
45
- format_for('hh:nn:ss ampm').process('01', '02', '03', 'pm').should eq [nil,nil,nil,13,2,3,nil,nil]
43
+ expect(format_for('hh:nn:ss ampm').process('01', '02', '03', 'pm')).to eq [nil,nil,nil,13,2,3,nil,nil]
46
44
  end
47
45
 
48
46
  it "should define method which outputs time array with meridian 'am' unadjusted hour" do
49
- format_for('hh:nn:ss ampm').process('01', '02', '03', 'am').should eq [nil,nil,nil,1,2,3,nil,nil]
47
+ expect(format_for('hh:nn:ss ampm').process('01', '02', '03', 'am')).to eq [nil,nil,nil,1,2,3,nil,nil]
50
48
  end
51
49
 
52
50
  it "should define method which outputs time array with microseconds" do
53
- format_for('hh:nn:ss.u').process('01', '02', '03', '99').should eq [nil,nil,nil,1,2,3,990000,nil]
51
+ expect(format_for('hh:nn:ss.u').process('01', '02', '03', '99')).to eq [nil,nil,nil,1,2,3,990000,nil]
54
52
  end
55
53
 
56
54
  it "should define method which outputs datetime array with zone offset" do
57
- format_for('yyyy-mm-dd hh:nn:ss.u zo').process('2001', '02', '03', '04', '05', '06', '99', '+10:00').should eq [2001,2,3,4,5,6,990000,36000]
55
+ expect(format_for('yyyy-mm-dd hh:nn:ss.u zo').process('2001', '02', '03', '04', '05', '06', '99', '+10:00')).to eq [2001,2,3,4,5,6,990000,36000]
58
56
  end
59
57
 
60
58
  it "should define method which outputs datetime array with timezone string" do
61
- format_for('yyyy-mm-dd hh:nn:ss.u tz').process('2001', '02', '03', '04', '05', '06', '99', 'EST').should eq [2001,2,3,4,5,6,990000,'EST']
59
+ expect(format_for('yyyy-mm-dd hh:nn:ss.u tz').process('2001', '02', '03', '04', '05', '06', '99', 'EST')).to eq [2001,2,3,4,5,6,990000,'EST']
62
60
  end
63
61
 
64
62
  context "with long month" do
@@ -72,11 +70,11 @@ describe Timeliness::Format do
72
70
  end
73
71
 
74
72
  it 'should parse abbreviated month for current locale to correct value' do
75
- format.process('2', 'Ene', '2000').should eq [2000,1,2,nil,nil,nil,nil,nil]
73
+ expect(format.process('2', 'Ene', '2000')).to eq [2000,1,2,nil,nil,nil,nil,nil]
76
74
  end
77
75
 
78
76
  it 'should parse full month for current locale to correct value' do
79
- format.process('2', 'Enero', '2000').should eq [2000,1,2,nil,nil,nil,nil,nil]
77
+ expect(format.process('2', 'Enero', '2000')).to eq [2000,1,2,nil,nil,nil,nil,nil]
80
78
  end
81
79
 
82
80
  after(:all) do
@@ -86,16 +84,16 @@ describe Timeliness::Format do
86
84
 
87
85
  context "without I18n loaded" do
88
86
  before do
89
- format.stub(:i18n_loaded?).and_return(false)
90
- I18n.should_not_receive(:t)
87
+ allow(format).to receive(:i18n_loaded?).and_return(false)
88
+ expect(I18n).not_to receive(:t)
91
89
  end
92
90
 
93
91
  it 'should parse abbreviated month to correct value' do
94
- format.process('2', 'Jan', '2000').should eq [2000,1,2,nil,nil,nil,nil,nil]
92
+ expect(format.process('2', 'Jan', '2000')).to eq [2000,1,2,nil,nil,nil,nil,nil]
95
93
  end
96
94
 
97
95
  it 'should parse full month to correct value' do
98
- format.process('2', 'January', '2000').should eq [2000,1,2,nil,nil,nil,nil,nil]
96
+ expect(format.process('2', 'January', '2000')).to eq [2000,1,2,nil,nil,nil,nil,nil]
99
97
  end
100
98
  end
101
99
  end
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  describe Timeliness::Parser do
4
2
  before(:all) do
5
3
  Timecop.freeze(2010,1,1,0,0,0)
@@ -7,24 +5,31 @@ describe Timeliness::Parser do
7
5
 
8
6
  describe "parse" do
9
7
  it "should return Time object for valid datetime string" do
10
- parse("2000-01-01 12:13:14").should be_kind_of(Time)
8
+ expect(parse("2000-01-01 12:13:14")).to be_kind_of(Time)
11
9
  end
12
10
 
13
11
  it "should return nil for empty string" do
14
- parse("").should be_nil
12
+ expect(parse("")).to be_nil
15
13
  end
16
14
 
17
15
  it "should return nil for nil value" do
18
- parse(nil).should be_nil
16
+ expect(parse(nil)).to be_nil
17
+ end
18
+
19
+ it "should return same value if value is a Time, Date, or DateTime" do
20
+ [Time.now, Date.new, DateTime.new].each do |value|
21
+ expect(parse(value)).to eq value
22
+ end
19
23
  end
20
24
 
21
- it "should return return same value if value not a string" do
22
- value = Time.now
23
- parse(value).should eq value
25
+ it "should return nil for non-string non-temporal values" do
26
+ [ {}, [], Class.new ].each do |value|
27
+ expect(parse(value)).to eq nil
28
+ end
24
29
  end
25
30
 
26
31
  it "should return time object for valid date string" do
27
- parse("2000-01-01").should be_kind_of(Time)
32
+ expect(parse("2000-01-01")).to be_kind_of(Time)
28
33
  end
29
34
 
30
35
  it "should return nil for invalid date string" do
@@ -44,7 +49,7 @@ describe Timeliness::Parser do
44
49
  end
45
50
 
46
51
  it "should return time object for valid time string" do
47
- parse("12:13:14").should be_kind_of(Time)
52
+ expect(parse("12:13:14")).to be_kind_of(Time)
48
53
  end
49
54
 
50
55
  it "should return nil for invalid time string" do
@@ -61,16 +66,26 @@ describe Timeliness::Parser do
61
66
 
62
67
  context "string with zone offset value" do
63
68
  context "when current timezone is earler than string zone" do
69
+ before(:all) do
70
+ Timeliness.default_timezone = :current
71
+ Time.zone = 'Australia/Melbourne'
72
+ end
73
+
64
74
  it 'should return value shifted by positive offset in default timezone' do
65
75
  value = parse("2000-06-01T12:00:00+02:00")
66
- value.should eq Time.local(2000,6,1,20,0,0)
67
- value.utc_offset.should eq 10.hours
76
+ expect(value).to eq Time.zone.local(2000,6,1,20,0,0)
77
+ expect(value.utc_offset).to eq 10.hours
68
78
  end
69
79
 
70
80
  it 'should return value shifted by negative offset in default timezone' do
71
81
  value = parse("2000-06-01T12:00:00-01:00")
72
- value.should eq Time.local(2000,6,1,23,0,0)
73
- value.utc_offset.should eq 10.hours
82
+ expect(value).to eq Time.zone.local(2000,6,1,23,0,0)
83
+ expect(value.utc_offset).to eq 10.hours
84
+ end
85
+
86
+ after(:all) do
87
+ Time.zone = nil
88
+ Timeliness.default_timezone = :local
74
89
  end
75
90
  end
76
91
 
@@ -82,14 +97,14 @@ describe Timeliness::Parser do
82
97
 
83
98
  it 'should return value shifted by positive offset in default timezone' do
84
99
  value = parse("2000-06-01T12:00:00+02:00")
85
- value.should eq Time.zone.local(2000,6,1,3,0,0)
86
- value.utc_offset.should eq -7.hours
100
+ expect(value).to eq Time.zone.local(2000,6,1,3,0,0)
101
+ expect(value.utc_offset).to eq -7.hours
87
102
  end
88
103
 
89
104
  it 'should return value shifted by negative offset in default timezone' do
90
105
  value = parse("2000-06-01T12:00:00-01:00")
91
- value.should eq Time.zone.local(2000,6,1,6,0,0)
92
- value.utc_offset.should eq -7.hours
106
+ expect(value).to eq Time.zone.local(2000,6,1,6,0,0)
107
+ expect(value.utc_offset).to eq -7.hours
93
108
  end
94
109
 
95
110
  after(:all) do
@@ -100,86 +115,86 @@ describe Timeliness::Parser do
100
115
  end
101
116
 
102
117
  context "string with zone abbreviation" do
103
- before do
104
- Time.zone = 'Melbourne'
118
+ before(:all) do
119
+ Time.zone = 'Australia/Melbourne'
105
120
  end
106
121
 
107
122
  it 'should return value using string zone adjusted to default :local timezone' do
108
123
  Timeliness.default_timezone = :local
109
124
  value = parse("Thu, 01 Jun 2000 03:00:00 MST")
110
- value.should eq Time.local(2000,6,1,20,0,0)
111
- value.utc_offset.should eq 10.hours
125
+ expect(value).to eq Time.utc(2000,6,1,10,0,0).getlocal
126
+ expect(value.utc_offset).to eq Time.mktime(2000, 6, 1, 10, 0, 0).utc_offset
112
127
  end
113
128
 
114
129
  it 'should return value using string zone adjusted to default :current timezone' do
115
130
  Timeliness.default_timezone = :current
116
131
  Time.zone = 'Adelaide'
117
132
  value = parse("Thu, 01 Jun 2000 03:00:00 MST")
118
- value.should eq Time.zone.local(2000,6,1,19,30,0)
119
- value.utc_offset.should eq 9.5.hours
133
+ expect(value).to eq Time.zone.local(2000,6,1,19,30,0)
134
+ expect(value.utc_offset).to eq 9.5.hours
120
135
  end
121
136
 
122
137
  it 'should return value using string zone adjusted to :zone option string timezone' do
123
138
  Timeliness.default_timezone = :local
124
139
  value = parse("Thu, 01 Jun 2000 03:00:00 MST", :zone => 'Perth')
125
- value.should eq Time.use_zone('Perth') { Time.zone.local(2000,6,1,18,0,0) }
126
- value.utc_offset.should eq 8.hours
140
+ expect(value).to eq Time.use_zone('Perth') { Time.zone.local(2000,6,1,18,0,0) }
141
+ expect(value.utc_offset).to eq 8.hours
127
142
  end
128
143
 
129
- after do
144
+ after(:all) do
130
145
  Time.zone = nil
131
146
  end
132
147
  end
133
148
 
134
149
  context "with :datetime type" do
135
150
  it "should return time object for valid datetime string" do
136
- parse("2000-01-01 12:13:14", :datetime).should eq Time.local(2000,1,1,12,13,14)
151
+ expect(parse("2000-01-01 12:13:14", :datetime)).to eq Time.local(2000,1,1,12,13,14)
137
152
  end
138
153
 
139
154
  it "should return nil for invalid date string" do
140
- parse("0/01/2000", :datetime).should be_nil
155
+ expect(parse("0/01/2000", :datetime)).to be_nil
141
156
  end
142
157
  end
143
158
 
144
159
  context "with :date type" do
145
160
  it "should return time object for valid date string" do
146
- parse("2000-01-01", :date).should eq Time.local(2000,1,1)
161
+ expect(parse("2000-01-01", :date)).to eq Time.local(2000,1,1)
147
162
  end
148
163
 
149
164
  it "should ignore time in datetime string" do
150
- parse('2000-02-01 12:13', :date).should eq Time.local(2000,2,1)
165
+ expect(parse('2000-02-01 12:13', :date)).to eq Time.local(2000,2,1)
151
166
  end
152
167
 
153
168
  it "should return nil for invalid date string" do
154
- parse("0/01/2000", :date).should be_nil
169
+ expect(parse("0/01/2000", :date)).to be_nil
155
170
  end
156
171
  end
157
172
 
158
173
  context "with :time type" do
159
174
  it "should return time object with a dummy date values" do
160
- parse('12:13', :time).should eq Time.local(2010,1,1,12,13)
175
+ expect(parse('12:13', :time)).to eq Time.local(2010,1,1,12,13)
161
176
  end
162
177
 
163
178
  it "should ignore date in datetime string" do
164
- parse('2010-02-01 12:13', :time).should eq Time.local(2010,1,1,12,13)
179
+ expect(parse('2010-02-01 12:13', :time)).to eq Time.local(2010,1,1,12,13)
165
180
  end
166
181
 
167
182
  it "should raise error if time hour is out of range for AM meridian" do
168
- parse('13:14 am', :time).should be_nil
183
+ expect(parse('13:14 am', :time)).to be_nil
169
184
  end
170
185
  end
171
186
 
172
187
  context "with :now option" do
173
188
  it 'should use date parts if string does not specify' do
174
189
  time = parse("12:13:14", :now => Time.local(2010,1,1))
175
- time.should eq Time.local(2010,1,1,12,13,14)
190
+ expect(time).to eq Time.local(2010,1,1,12,13,14)
176
191
  end
177
192
  end
178
193
 
179
194
  context "with time value argument" do
180
195
  it 'should use argument as :now option value' do
181
196
  time = parse("12:13:14", Time.local(2010,1,1))
182
- time.should eq Time.local(2010,1,1,12,13,14)
197
+ expect(time).to eq Time.local(2010,1,1,12,13,14)
183
198
  end
184
199
  end
185
200
 
@@ -187,22 +202,22 @@ describe Timeliness::Parser do
187
202
  context ":utc" do
188
203
  it "should return time object in utc timezone" do
189
204
  time = parse("2000-06-01 12:13:14", :datetime, :zone => :utc)
190
- time.utc_offset.should eq 0
205
+ expect(time.utc_offset).to eq 0
191
206
  end
192
207
 
193
208
  it 'should return nil for partial invalid time component' do
194
- parse("2000-06-01 12:60", :datetime, :zone => :utc).should be_nil
209
+ expect(parse("2000-06-01 12:60", :datetime, :zone => :utc)).to be_nil
195
210
  end
196
211
  end
197
212
 
198
213
  context ":local" do
199
214
  it "should return time object in local system timezone" do
200
215
  time = parse("2000-06-01 12:13:14", :datetime, :zone => :local)
201
- time.utc_offset.should eq 10.hours
216
+ expect(time.utc_offset).to eq Time.mktime(2000, 6, 1, 12, 13, 14).utc_offset
202
217
  end
203
218
 
204
219
  it 'should return nil for partial invalid time component' do
205
- parse("2000-06-01 12:60", :datetime, :zone => :local).should be_nil
220
+ expect(parse("2000-06-01 12:60", :datetime, :zone => :local)).to be_nil
206
221
  end
207
222
  end
208
223
 
@@ -210,39 +225,39 @@ describe Timeliness::Parser do
210
225
  it "should return time object in current timezone" do
211
226
  Time.zone = 'Adelaide'
212
227
  time = parse("2000-06-01 12:13:14", :datetime, :zone => :current)
213
- time.utc_offset.should eq 9.5.hours
228
+ expect(time.utc_offset).to eq 9.5.hours
214
229
  end
215
230
 
216
231
  it 'should return nil for partial invalid time component' do
217
- parse("2000-06-01 12:60", :datetime, :zone => :current).should be_nil
232
+ expect(parse("2000-06-01 12:60", :datetime, :zone => :current)).to be_nil
218
233
  end
219
234
  end
220
235
 
221
236
  context "named zone" do
222
237
  it "should return time object in the timezone" do
223
238
  time = parse("2000-06-01 12:13:14", :datetime, :zone => 'London')
224
- time.utc_offset.should eq 1.hour
239
+ expect(time.utc_offset).to eq 1.hour
225
240
  end
226
241
 
227
242
  it 'should return nil for partial invalid time component' do
228
- parse("2000-06-01 12:60", :datetime, :zone => 'London').should be_nil
243
+ expect(parse("2000-06-01 12:60", :datetime, :zone => 'London')).to be_nil
229
244
  end
230
245
  end
231
246
 
232
247
  context "without ActiveSupport loaded" do
233
248
  it 'should output message' do
234
249
  expect {
235
- Time.should_receive(:zone).and_raise(NoMethodError.new("undefined method `zone' for Time:Class"))
250
+ expect(Time).to receive(:zone).and_raise(NoMethodError.new("undefined method `zone' for Time:Class"))
236
251
  parse("2000-06-01 12:13:14", :zone => :current)
237
252
  }.to raise_error(Timeliness::Parser::MissingTimezoneSupport)
238
253
 
239
254
  expect {
240
- Time.should_receive(:current).and_raise(NoMethodError.new("undefined method `current' for Time:Class"))
255
+ expect(Time).to receive(:current).and_raise(NoMethodError.new("undefined method `current' for Time:Class"))
241
256
  parse("12:13:14", :zone => :current)
242
257
  }.to raise_error(Timeliness::Parser::MissingTimezoneSupport)
243
258
 
244
259
  expect {
245
- Time.should_receive(:use_zone).and_raise(NoMethodError.new("undefined method `use_zone' for Time:Class"))
260
+ expect(Time).to receive(:use_zone).and_raise(NoMethodError.new("undefined method `use_zone' for Time:Class"))
246
261
  parse("2000-06-01 12:13:14", :zone => 'London')
247
262
  }.to raise_error(Timeliness::Parser::MissingTimezoneSupport)
248
263
  end
@@ -257,12 +272,12 @@ describe Timeliness::Parser do
257
272
 
258
273
  it 'should return date array' do
259
274
  Timeliness.date_for_time_type = [2010,1,1]
260
- parse('12:13:14', :time).should eq Time.local(2010,1,1,12,13,14)
275
+ expect(parse('12:13:14', :time)).to eq Time.local(2010,1,1,12,13,14)
261
276
  end
262
277
 
263
278
  it 'should return date array evaluated lambda' do
264
279
  Timeliness.date_for_time_type = lambda { Time.local(2010,2,1) }
265
- parse('12:13:14', :time).should eq Time.local(2010,2,1,12,13,14)
280
+ expect(parse('12:13:14', :time)).to eq Time.local(2010,2,1,12,13,14)
266
281
  end
267
282
 
268
283
  after do
@@ -272,16 +287,29 @@ describe Timeliness::Parser do
272
287
 
273
288
  context "with :now option" do
274
289
  it 'should use date from :now' do
275
- parse('12:13:14', :time, :now => Time.local(2010, 6, 1)).should eq Time.local(2010,6,1,12,13,14)
290
+ expect(parse('12:13:14', :time, :now => Time.local(2010, 6, 1))).to eq Time.local(2010,6,1,12,13,14)
276
291
  end
277
292
  end
278
293
 
279
294
  context "with :zone option" do
295
+ before(:all) do
296
+ Timecop.return
297
+ @current_tz = ENV['TZ']
298
+ ENV['TZ'] = 'Australia/Melbourne'
299
+ Timecop.freeze(2010,1,1,0,0,0)
300
+ end
301
+
280
302
  it "should use date from the specified zone" do
281
303
  time = parse("12:13:14", :time, :zone => :utc)
282
- time.year.should eq 2009
283
- time.month.should eq 12
284
- time.day.should eq 31
304
+ expect(time.year).to eq 2009
305
+ expect(time.month).to eq 12
306
+ expect(time.day).to eq 31
307
+ end
308
+
309
+ after(:all) do
310
+ Timecop.return
311
+ ENV['TZ'] = @current_tz
312
+ Timecop.freeze(2010,1,1,0,0,0)
285
313
  end
286
314
  end
287
315
 
@@ -292,124 +320,124 @@ describe Timeliness::Parser do
292
320
  context "with no type" do
293
321
  it "should return date array from date string" do
294
322
  time_array = parser._parse('2000-02-01')
295
- time_array.should eq [2000,2,1,nil,nil,nil,nil,nil]
323
+ expect(time_array).to eq [2000,2,1,nil,nil,nil,nil,nil]
296
324
  end
297
325
 
298
326
  it "should return time array from time string" do
299
327
  time_array = parser._parse('12:13:14', :time)
300
- time_array.should eq [nil,nil,nil,12,13,14,nil,nil]
328
+ expect(time_array).to eq [nil,nil,nil,12,13,14,nil,nil]
301
329
  end
302
330
 
303
331
  it "should return datetime array from datetime string" do
304
332
  time_array = parser._parse('2000-02-01 12:13:14')
305
- time_array.should eq [2000,2,1,12,13,14,nil,nil]
333
+ expect(time_array).to eq [2000,2,1,12,13,14,nil,nil]
306
334
  end
307
335
  end
308
336
 
309
337
  context "with type" do
310
338
  it "should return date array from date string" do
311
339
  time_array = parser._parse('2000-02-01', :date)
312
- time_array.should eq [2000,2,1,nil,nil,nil,nil,nil]
340
+ expect(time_array).to eq [2000,2,1,nil,nil,nil,nil,nil]
313
341
  end
314
342
 
315
343
  it "should not return time array from time string for :date type" do
316
344
  time_array = parser._parse('12:13:14', :date)
317
- time_array.should eq nil
345
+ expect(time_array).to eq nil
318
346
  end
319
347
 
320
348
  it "should return time array from time string" do
321
349
  time_array = parser._parse('12:13:14', :time)
322
- time_array.should eq [nil,nil,nil,12,13,14,nil,nil]
350
+ expect(time_array).to eq [nil,nil,nil,12,13,14,nil,nil]
323
351
  end
324
352
 
325
353
  it "should not return date array from date string for :time type" do
326
354
  time_array = parser._parse('2000-02-01', :time)
327
- time_array.should eq nil
355
+ expect(time_array).to eq nil
328
356
  end
329
357
 
330
358
  it "should return datetime array from datetime string when type is date" do
331
359
  time_array = parser._parse('2000-02-01 12:13:14', :date)
332
- time_array.should eq [2000,2,1,12,13,14,nil,nil]
360
+ expect(time_array).to eq [2000,2,1,12,13,14,nil,nil]
333
361
  end
334
362
 
335
363
  it "should return date array from date string when type is datetime" do
336
364
  time_array = parser._parse('2000-02-01', :datetime)
337
- time_array.should eq [2000,2,1,nil,nil,nil,nil,nil]
365
+ expect(time_array).to eq [2000,2,1,nil,nil,nil,nil,nil]
338
366
  end
339
367
 
340
368
  it "should not return time array from time string when type is datetime" do
341
369
  time_array = parser._parse('12:13:14', :datetime)
342
- time_array.should eq nil
370
+ expect(time_array).to eq nil
343
371
  end
344
372
  end
345
373
 
346
374
  context "with :strict => true" do
347
375
  it "should return nil from date string when type is datetime" do
348
376
  time_array = parser._parse('2000-02-01', :datetime, :strict => true)
349
- time_array.should be_nil
377
+ expect(time_array).to be_nil
350
378
  end
351
379
 
352
380
  it "should return nil from datetime string when type is date" do
353
381
  time_array = parser._parse('2000-02-01 12:13:14', :date, :strict => true)
354
- time_array.should be_nil
382
+ expect(time_array).to be_nil
355
383
  end
356
384
 
357
385
  it "should return nil from datetime string when type is time" do
358
386
  time_array = parser._parse('2000-02-01 12:13:14', :time, :strict => true)
359
- time_array.should be_nil
387
+ expect(time_array).to be_nil
360
388
  end
361
389
 
362
390
  it "should parse date string when type is date" do
363
391
  time_array = parser._parse('2000-02-01', :date, :strict => true)
364
- time_array.should_not be_nil
392
+ expect(time_array).not_to be_nil
365
393
  end
366
394
 
367
395
  it "should parse time string when type is time" do
368
396
  time_array = parser._parse('12:13:14', :time, :strict => true)
369
- time_array.should_not be_nil
397
+ expect(time_array).not_to be_nil
370
398
  end
371
399
 
372
400
  it "should parse datetime string when type is datetime" do
373
401
  time_array = parser._parse('2000-02-01 12:13:14', :datetime, :strict => true)
374
- time_array.should_not be_nil
402
+ expect(time_array).not_to be_nil
375
403
  end
376
404
 
377
405
  it "should ignore strict parsing if no type specified" do
378
406
  time_array = parser._parse('2000-02-01', :strict => true)
379
- time_array.should_not be_nil
407
+ expect(time_array).not_to be_nil
380
408
  end
381
409
  end
382
410
 
383
411
  context "with :format option" do
384
412
  it "should return values if string matches specified format" do
385
413
  time_array = parser._parse('2000-02-01 12:13:14', :datetime, :format => 'yyyy-mm-dd hh:nn:ss')
386
- time_array.should eq [2000,2,1,12,13,14,nil,nil]
414
+ expect(time_array).to eq [2000,2,1,12,13,14,nil,nil]
387
415
  end
388
416
 
389
417
  it "should return nil if string does not match specified format" do
390
418
  time_array = parser._parse('2000-02-01 12:13', :datetime, :format => 'yyyy-mm-dd hh:nn:ss')
391
- time_array.should be_nil
419
+ expect(time_array).to be_nil
392
420
  end
393
421
  end
394
422
 
395
423
  context "date with ambiguous year" do
396
424
  it "should return year in current century if year below threshold" do
397
425
  time_array = parser._parse('01-02-29', :date)
398
- time_array.should eq [2029,2,1,nil,nil,nil,nil,nil]
426
+ expect(time_array).to eq [2029,2,1,nil,nil,nil,nil,nil]
399
427
  end
400
428
 
401
429
  it "should return year in last century if year at or above threshold" do
402
430
  time_array = parser._parse('01-02-30', :date)
403
- time_array.should eq [1930,2,1,nil,nil,nil,nil,nil]
431
+ expect(time_array).to eq [1930,2,1,nil,nil,nil,nil,nil]
404
432
  end
405
433
 
406
434
  it "should allow custom threshold" do
407
435
  default = Timeliness.ambiguous_year_threshold
408
436
  Timeliness.ambiguous_year_threshold = 40
409
437
  time_array = parser._parse('01-02-39', :date)
410
- time_array.should eq [2039,2,1,nil,nil,nil,nil,nil]
438
+ expect(time_array).to eq [2039,2,1,nil,nil,nil,nil,nil]
411
439
  time_array = parser._parse('01-02-40', :date)
412
- time_array.should eq [1940,2,1,nil,nil,nil,nil,nil]
440
+ expect(time_array).to eq [1940,2,1,nil,nil,nil,nil,nil]
413
441
  Timeliness.ambiguous_year_threshold = default
414
442
  end
415
443
  end
@@ -418,17 +446,17 @@ describe Timeliness::Parser do
418
446
  describe "make_time" do
419
447
  it "should return time object for valid time array" do
420
448
  time = parser.make_time([2010,9,8,12,13,14])
421
- time.should eq Time.local(2010,9,8,12,13,14)
449
+ expect(time).to eq Time.local(2010,9,8,12,13,14)
422
450
  end
423
451
 
424
452
  it "should return nil for invalid date in array" do
425
453
  time = parser.make_time([2010,13,8,12,13,14])
426
- time.should be_nil
454
+ expect(time).to be_nil
427
455
  end
428
456
 
429
457
  it "should return nil for invalid time in array" do
430
458
  time = parser.make_time([2010,9,8,25,13,14])
431
- time.should be_nil
459
+ expect(time).to be_nil
432
460
  end
433
461
 
434
462
  context "default timezone" do
@@ -439,7 +467,7 @@ describe Timeliness::Parser do
439
467
  it "should be used if no zone value" do
440
468
  Timeliness.default_timezone = :utc
441
469
  time = parser.make_time([2000,6,1,12,0,0])
442
- time.utc_offset.should eq 0
470
+ expect(time.utc_offset).to eq 0
443
471
  end
444
472
 
445
473
  after do
@@ -451,14 +479,14 @@ describe Timeliness::Parser do
451
479
  context ":utc" do
452
480
  it "should return time object in utc timezone" do
453
481
  time = parser.make_time([2000,6,1,12,0,0], :utc)
454
- time.utc_offset.should eq 0
482
+ expect(time.utc_offset).to eq 0
455
483
  end
456
484
  end
457
485
 
458
486
  context ":local" do
459
487
  it "should return time object in local system timezone" do
460
488
  time = parser.make_time([2000,6,1,12,0,0], :local)
461
- time.utc_offset.should eq 10.hours
489
+ expect(time.utc_offset).to eq Time.mktime(2000,6,1,12,0,0).utc_offset
462
490
  end
463
491
  end
464
492
 
@@ -466,14 +494,14 @@ describe Timeliness::Parser do
466
494
  it "should return time object in current timezone" do
467
495
  Time.zone = 'Adelaide'
468
496
  time = parser.make_time([2000,6,1,12,0,0], :current)
469
- time.utc_offset.should eq 9.5.hours
497
+ expect(time.utc_offset).to eq 9.5.hours
470
498
  end
471
499
  end
472
500
 
473
501
  context "named zone" do
474
502
  it "should return time object in the timezone" do
475
503
  time = parser.make_time([2000,6,1,12,0,0], 'London')
476
- time.utc_offset.should eq 1.hour
504
+ expect(time.utc_offset).to eq 1.hour
477
505
  end
478
506
  end
479
507
  end
@@ -484,7 +512,7 @@ describe Timeliness::Parser do
484
512
  context "with no options" do
485
513
  it 'should return date_for_time_type values with no options' do
486
514
  dummy_date = Timeliness.date_for_time_type.call
487
- current_date.should eq [ dummy_date.year, dummy_date.month, dummy_date.day ]
515
+ expect(current_date).to eq [ dummy_date.year, dummy_date.month, dummy_date.day ]
488
516
  end
489
517
  end
490
518
 
@@ -492,7 +520,7 @@ describe Timeliness::Parser do
492
520
  it 'should return date array from Time value' do
493
521
  time = Time.now
494
522
  date_array = [time.year, time.month, time.day]
495
- current_date(:now => time).should eq date_array
523
+ expect(current_date(:now => time)).to eq date_array
496
524
  end
497
525
  end
498
526
 
@@ -500,26 +528,26 @@ describe Timeliness::Parser do
500
528
  it 'should return date array for utc zone' do
501
529
  time = Time.now.getutc
502
530
  date_array = [time.year, time.month, time.day]
503
- current_date(:zone => :utc).should eq date_array
531
+ expect(current_date(:zone => :utc)).to eq date_array
504
532
  end
505
533
 
506
534
  it 'should return date array for local zone' do
507
535
  time = Time.now
508
536
  date_array = [time.year, time.month, time.day]
509
- current_date(:zone => :local).should eq date_array
537
+ expect(current_date(:zone => :local)).to eq date_array
510
538
  end
511
539
 
512
540
  it 'should return date array for current zone' do
513
541
  Time.zone = 'London'
514
542
  time = Time.current
515
543
  date_array = [time.year, time.month, time.day]
516
- current_date(:zone => :current).should eq date_array
544
+ expect(current_date(:zone => :current)).to eq date_array
517
545
  end
518
546
 
519
547
  it 'should return date array for named zone' do
520
548
  time = Time.use_zone('London') { Time.current }
521
549
  date_array = [time.year, time.month, time.day]
522
- current_date(:zone => 'London').should eq date_array
550
+ expect(current_date(:zone => 'London')).to eq date_array
523
551
  end
524
552
  end
525
553
  end