dotiw 4.0.1 → 5.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.
@@ -1,5 +1,5 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  module DOTIW
4
- VERSION = "4.0.1"
4
+ VERSION = '5.0.0'
5
5
  end
@@ -1,13 +1,17 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- describe "A better distance_of_time_in_words" do
6
- include ActionView::Helpers::DateHelper
7
- include ActionView::Helpers::TextHelper
8
- include ActionView::Helpers::NumberHelper
5
+ describe 'A better distance_of_time_in_words' do
6
+ if defined?(ActionView)
7
+ include ActionView::Helpers::DateHelper
8
+ include ActionView::Helpers::TextHelper
9
+ include ActionView::Helpers::NumberHelper
10
+ else
11
+ include DOTIW::Methods
12
+ end
9
13
 
10
- START_TIME = "01-08-2009".to_time
14
+ START_TIME = '01-08-2009'.to_time
11
15
 
12
16
  before do
13
17
  I18n.locale = :en
@@ -15,57 +19,56 @@ describe "A better distance_of_time_in_words" do
15
19
  allow(Time.zone).to receive(:now).and_return(START_TIME)
16
20
  end
17
21
 
18
- describe "distance of time" do
19
- fragments = [
20
- [0.5.minutes, "30 seconds"],
21
- [4.5.minutes, "4 minutes and 30 seconds"],
22
- [5.minutes.to_i, "5 minutes"],
23
- [10.minutes.to_i, "10 minutes"],
24
- [1.hour.to_i, "1 hour"],
25
- [1.hour + 30.seconds, "1 hour and 30 seconds"],
26
- [4.weeks.to_i, "4 weeks"],
27
- [4.weeks + 2.days, "4 weeks and 2 days"],
28
- [24.weeks.to_i, "5 months, 2 weeks, and 1 day"]
29
- ]
30
- fragments.each do |number, result|
22
+ describe 'distance of time' do
23
+ [
24
+ [0.5.minutes, '30 seconds'],
25
+ [4.5.minutes, '4 minutes and 30 seconds'],
26
+ [5.minutes, '5 minutes'],
27
+ [10.minutes, '10 minutes'],
28
+ [1.hour, '1 hour'],
29
+ [1.hour + 30.seconds, '1 hour and 30 seconds'],
30
+ [4.weeks, '4 weeks'],
31
+ [4.weeks + 2.days, '4 weeks and 2 days'],
32
+ [24.weeks, '5 months, 2 weeks, and 1 day']
33
+ ].each do |number, result|
31
34
  it "#{number} == #{result}" do
32
35
  expect(distance_of_time(number)).to eq(result)
33
36
  end
34
37
  end
35
38
 
36
- describe "with options" do
37
- it "except:seconds should skip seconds" do
38
- expect(distance_of_time(1.2.minute, except: 'seconds')).to eq("1 minute")
39
- expect(distance_of_time(2.5.hours + 30.seconds, except: 'seconds')).to eq("2 hours and 30 minutes")
39
+ describe 'with options' do
40
+ it 'except:seconds should skip seconds' do
41
+ expect(distance_of_time(1.2.minute, except: 'seconds')).to eq('1 minute')
42
+ expect(distance_of_time(2.5.hours + 30.seconds, except: 'seconds')).to eq('2 hours and 30 minutes')
40
43
  end
41
44
 
42
- it "except:seconds has higher precedence than include_seconds:true" do
45
+ it 'except:seconds has higher precedence than include_seconds:true' do
43
46
  expect(distance_of_time(1.2.minute, include_seconds: true, except: 'seconds')).to eq('1 minute')
44
47
  end
45
48
  end
46
-
47
49
  end
48
50
 
49
- describe "hash version" do
50
- describe "giving correct numbers of" do
51
-
52
- [:years, :months, :weeks, :days, :minutes, :seconds].each do |name|
51
+ describe 'hash version' do
52
+ describe 'giving correct numbers of' do
53
+ %i[years months weeks days minutes seconds].each do |name|
53
54
  describe name do
54
- it "exactly" do
55
+ it 'exactly' do
55
56
  hash = distance_of_time_in_words_hash(START_TIME, START_TIME + 1.send(name))
56
57
  expect(hash[name]).to eq(1)
57
58
  end
58
59
 
59
- it "two" do
60
+ it 'two' do
60
61
  hash = distance_of_time_in_words_hash(START_TIME, START_TIME + 2.send(name))
61
62
  expect(hash[name]).to eq(2)
62
63
  end
63
64
  end
64
65
  end
65
66
 
66
- it "should be happy with lots of measurements" do
67
- hash = distance_of_time_in_words_hash(START_TIME,
68
- START_TIME + 1.year + 2.months + 3.weeks + 4.days + 5.hours + 6.minutes + 7.seconds)
67
+ it 'should be happy with lots of measurements' do
68
+ hash = distance_of_time_in_words_hash(
69
+ START_TIME,
70
+ START_TIME + 1.year + 2.months + 3.weeks + 4.days + 5.hours + 6.minutes + 7.seconds
71
+ )
69
72
  expect(hash[:years]).to eq(1)
70
73
  expect(hash[:months]).to eq(2)
71
74
  expect(hash[:weeks]).to eq(3)
@@ -77,214 +80,253 @@ describe "A better distance_of_time_in_words" do
77
80
  end
78
81
  end
79
82
 
80
- describe "real version" do
81
- it "debe hablar español" do
82
- expect(distance_of_time_in_words(START_TIME, START_TIME + 1.days, :locale => :es)).to eq("un día")
83
- expect(distance_of_time_in_words(START_TIME, START_TIME + 5.days, :locale => :es)).to eq("5 días")
83
+ describe 'real version' do
84
+ it 'debe hablar español' do
85
+ expect(distance_of_time_in_words(START_TIME, START_TIME + 1.days, locale: :es)).to eq('un día')
86
+ expect(distance_of_time_in_words(START_TIME, START_TIME + 5.days, locale: :es)).to eq('5 días')
84
87
  end
85
88
 
86
89
  it "deve parlare l'italiano" do
87
- expect(distance_of_time_in_words(START_TIME, START_TIME + 1.days, true, :locale => :it)).to eq("un giorno")
88
- expect(distance_of_time_in_words(START_TIME, START_TIME + 5.days, true, :locale => :it)).to eq("5 giorni")
90
+ expect(distance_of_time_in_words(START_TIME, START_TIME + 1.days, true, locale: :it)).to eq('un giorno')
91
+ expect(distance_of_time_in_words(START_TIME, START_TIME + 5.days, true, locale: :it)).to eq('5 giorni')
89
92
  end
90
93
 
91
- fragments = [
92
- [START_TIME, START_TIME + 5.days + 3.minutes, "5 days and 3 minutes"],
93
- [START_TIME, START_TIME + 1.minute, "1 minute"],
94
- [START_TIME, START_TIME + 3.years, "3 years"],
95
- [START_TIME, START_TIME + 10.years, "10 years"],
96
- [START_TIME, START_TIME + 8.months, "8 months"],
97
- [START_TIME, START_TIME + 3.hour, "3 hours"],
98
- [START_TIME, START_TIME + 13.months, "1 year and 1 month"],
94
+ [
95
+ [START_TIME, START_TIME + 5.days + 3.minutes, '5 days and 3 minutes'],
96
+ [START_TIME, START_TIME + 1.minute, '1 minute'],
97
+ [START_TIME, START_TIME + 3.years, '3 years'],
98
+ [START_TIME, START_TIME + 10.years, '10 years'],
99
+ [START_TIME, START_TIME + 8.months, '8 months'],
100
+ [START_TIME, START_TIME + 3.hour, '3 hours'],
101
+ [START_TIME, START_TIME + 13.months, '1 year and 1 month'],
99
102
  # Any numeric sequence is merely coincidental.
100
- [START_TIME, START_TIME + 1.year + 2.months + 3.weeks + 4.days + 5.hours + 6.minutes + 7.seconds, "1 year, 2 months, 3 weeks, 4 days, 5 hours, 6 minutes, and 7 seconds"],
101
- ["2009-3-16".to_time, "2008-4-14".to_time, "11 months and 2 days"],
102
- ["2009-3-16".to_time + 1.minute, "2008-4-14".to_time, "11 months, 2 days, and 1 minute"],
103
- ["2009-4-14".to_time, "2008-3-16".to_time, "1 year, 4 weeks, and 1 day"],
104
- ["2009-2-01".to_time, "2009-3-01".to_time, "1 month"],
105
- ["2008-2-01".to_time, "2008-3-01".to_time, "1 month"]
106
- ]
107
- fragments.each do |start, finish, output|
103
+ [START_TIME, START_TIME + 1.year + 2.months + 3.weeks + 4.days + 5.hours + 6.minutes + 7.seconds, '1 year, 2 months, 3 weeks, 4 days, 5 hours, 6 minutes, and 7 seconds'],
104
+ ['2009-3-16'.to_time, '2008-4-14'.to_time, '11 months and 2 days'],
105
+ ['2009-3-16'.to_time + 1.minute, '2008-4-14'.to_time, '11 months, 2 days, and 1 minute'],
106
+ ['2009-4-14'.to_time, '2008-3-16'.to_time, '1 year, 4 weeks, and 1 day'],
107
+ ['2009-2-01'.to_time, '2009-3-01'.to_time, '1 month'],
108
+ ['2008-2-01'.to_time, '2008-3-01'.to_time, '1 month'],
109
+ [Date.parse('31.03.2015').to_time, Time.parse('01.03.2016'), '10 months, 4 weeks, and 2 days'],
110
+ [Date.new(2014, 1, 31), Date.new(2014, 3, 1), '4 weeks and 1 day'],
111
+ ['2008-2-01'.to_time, '2008-3-01'.to_time, '1 month'],
112
+ ['2014-1-31'.to_time, '2014-3-01'.to_time, '4 weeks and 1 day'],
113
+ ['2014-1-31'.to_time, '2014-3-02'.to_time, '4 weeks and 2 days'],
114
+ ['2016-1-31'.to_time, '2016-3-01'.to_time, '4 weeks and 2 days'],
115
+ ['2016-1-31'.to_time, '2016-3-02'.to_time, '1 month']
116
+ ].each do |start, finish, output|
108
117
  it "should be #{output}" do
109
118
  expect(distance_of_time_in_words(start, finish, true)).to eq(output)
119
+ expect(distance_of_time_in_words(finish, start, true)).to eq(output)
120
+ end
121
+ end
122
+
123
+ [
124
+ [Time.zone.now, Time.zone.now + 1.day - 1.minute, '23 hours and 59 minutes'],
125
+ [Time.zone.now, Time.zone.now + 15.days - 1.minute, '14 days, 23 hours, and 59 minutes'],
126
+ [Time.zone.now, Time.zone.now + 29.days - 1.minute, '28 days, 23 hours, and 59 minutes'],
127
+ [Time.zone.now, Time.zone.now + 30.days - 1.minute, '29 days, 23 hours, and 59 minutes'],
128
+ [Time.zone.now, Time.zone.now + 31.days - 1.minute, '30 days, 23 hours, and 59 minutes'],
129
+ [Time.zone.now, Time.zone.now + 32.days - 1.minute, '31 days, 23 hours, and 59 minutes'],
130
+ [Time.zone.now, Time.zone.now + 33.days - 1.minute, '32 days, 23 hours, and 59 minutes']
131
+ ].each do |start, finish, output|
132
+ it "should be #{output}" do
133
+ expect(distance_of_time_in_words(start, finish, accumulate_on: 'days')).to eq(output)
134
+ end
135
+ end
136
+
137
+ [
138
+ [Time.at(1), Time.at(100), '1 minute'],
139
+ [DateTime.now, DateTime.now + 1.minute, '1 minute'],
140
+ [Date.new(2000, 1, 2), Date.new(2000, 1, 3), '1 day'],
141
+ [Time.at(DateTime.now), DateTime.now + 1.minute, '1 minute']
142
+ ].each do |start, finish, output|
143
+ it "should be #{output}" do
144
+ expect(distance_of_time_in_words(start, finish)).to eq(output)
110
145
  end
111
146
  end
112
147
 
113
- describe "accumulate on" do
114
- fragments = [
148
+ describe 'accumulate on' do
149
+ [
115
150
  [START_TIME,
116
151
  START_TIME + 10.minute,
117
152
  :seconds,
118
- "600 seconds"],
153
+ '600 seconds'],
119
154
  [START_TIME,
120
155
  START_TIME + 10.hour + 10.minute + 1.second,
121
156
  :minutes,
122
- "610 minutes and 1 second"],
157
+ '610 minutes and 1 second'],
123
158
  [START_TIME,
124
- START_TIME + 2.day + 10000.hour + 10.second,
159
+ START_TIME + 2.day + 10_000.hour + 10.second,
125
160
  :hours,
126
- "10048 hours and 10 seconds"],
161
+ '10048 hours and 10 seconds'],
127
162
  [START_TIME,
128
- START_TIME + 2.day + 10000.hour + 10.second,
163
+ START_TIME + 2.day + 10_000.hour + 10.second,
129
164
  :days,
130
- "418 days, 16 hours, and 10 seconds"],
165
+ '418 days, 16 hours, and 10 seconds'],
131
166
  [START_TIME,
132
- START_TIME + 2.day + 10000.hour + 10.second,
167
+ START_TIME + 2.day + 10_000.hour + 10.second,
133
168
  :weeks,
134
- "59 weeks, 5 days, 16 hours, and 10 seconds"],
169
+ '59 weeks, 5 days, 16 hours, and 10 seconds'],
135
170
  [START_TIME,
136
- START_TIME + 2.day + 10000.hour + 10.second,
171
+ START_TIME + 2.day + 10_000.hour + 10.second,
137
172
  :months,
138
- "13 months, 3 weeks, 1 day, 16 hours, and 10 seconds"],
139
- ["2015-1-15".to_time, "2016-3-15".to_time, :months, "14 months"]
140
-
141
- ]
142
- fragments.each do |start, finish, accumulator, output|
173
+ '13 months, 3 weeks, 1 day, 16 hours, and 10 seconds'],
174
+ ['2015-1-15'.to_time, '2016-3-15'.to_time, :months, '14 months']
175
+ ].each do |start, finish, accumulator, output|
143
176
  it "should be #{output}" do
144
- expect(distance_of_time_in_words(start, finish, true, :accumulate_on => accumulator)).to eq(output)
177
+ expect(distance_of_time_in_words(start, finish, true, accumulate_on: accumulator)).to eq(output)
145
178
  end
146
179
  end
147
180
  end # :accumulate_on
148
181
 
149
- describe "without finish time" do
182
+ describe 'without finish time' do
150
183
  # A missing finish argument should default to zero, essentially returning
151
184
  # the equivalent of distance_of_time in order to be backwards-compatible
152
185
  # with the original rails distance_of_time_in_words helper.
153
- fragments = [
154
- [5.minutes.to_i, "5 minutes"],
155
- [10.minutes.to_i, "10 minutes"],
156
- [1.hour.to_i, "1 hour"],
157
- [6.days.to_i, "6 days"],
158
- [4.weeks.to_i, "4 weeks"],
159
- [24.weeks.to_i, "5 months, 2 weeks, and 1 day"]
160
- ]
161
- fragments.each do |start, output|
186
+ [
187
+ [5.minutes.to_i, '5 minutes'],
188
+ [10.minutes.to_i, '10 minutes'],
189
+ [1.hour.to_i, '1 hour'],
190
+ [6.days.to_i, '6 days'],
191
+ [4.weeks.to_i, '4 weeks'],
192
+ [24.weeks.to_i, '5 months, 2 weeks, and 1 day']
193
+ ].each do |start, output|
162
194
  it "should be #{output}" do
163
195
  expect(distance_of_time_in_words(start)).to eq(output)
164
196
  end
165
197
  end
166
198
  end
167
-
168
199
  end
169
200
 
170
- describe "with output options" do
171
- fragments = [
201
+ describe 'with output options' do
202
+ [
172
203
  # Any numeric sequence is merely coincidental.
173
204
  [START_TIME,
174
205
  START_TIME + 1.year + 2.months + 3.weeks + 4.days + 5.hours + 6.minutes + 7.seconds,
175
- { :words_connector => " - " },
176
- "1 year - 2 months - 3 weeks - 4 days - 5 hours - 6 minutes, and 7 seconds"],
206
+ { words_connector: ' - ' },
207
+ '1 year - 2 months - 3 weeks - 4 days - 5 hours - 6 minutes, and 7 seconds'],
177
208
  [START_TIME,
178
209
  START_TIME + 5.minutes + 6.seconds,
179
- { :two_words_connector => " - " },
180
- "5 minutes - 6 seconds"],
210
+ { two_words_connector: ' - ' },
211
+ '5 minutes - 6 seconds'],
181
212
  [START_TIME,
182
- START_TIME + 4.hours + 5.minutes + 6.seconds,
183
- { :last_word_connector => " - " },
184
- "4 hours, 5 minutes - 6 seconds"],
213
+ START_TIME + 4.hours + 5.minutes + 6.seconds,
214
+ { last_word_connector: ' - ' },
215
+ '4 hours, 5 minutes - 6 seconds'],
185
216
  [START_TIME,
186
217
  START_TIME + 1.year + 2.months + 3.days + 4.hours + 5.minutes + 6.seconds,
187
- { :except => "minutes" },
188
- "1 year, 2 months, 3 days, 4 hours, and 6 seconds"],
218
+ { except: 'minutes' },
219
+ '1 year, 2 months, 3 days, 4 hours, and 6 seconds'],
189
220
  [START_TIME,
190
221
  START_TIME + 1.hour + 1.minute,
191
- { :except => "minutes"}, "1 hour"],
222
+ { except: 'minutes' }, '1 hour'],
192
223
  [START_TIME,
193
224
  START_TIME + 1.hour + 1.day + 1.minute,
194
- { :except => ["minutes", "hours"]},
195
- "1 day"],
225
+ { except: %w[minutes hours] },
226
+ '1 day'],
196
227
  [START_TIME,
197
228
  START_TIME + 1.hour + 1.day + 1.minute,
198
- { :only => ["minutes", "hours"]},
199
- "1 hour and 1 minute"],
200
- [START_TIME,
201
- START_TIME + 1.year + 2.months + 3.weeks + 4.days + 5.hours + 6.minutes + 7.seconds,
202
- { :vague => true },
203
- "about 1 year"],
204
- [START_TIME,
205
- START_TIME + 1.year + 2.months + 3.weeks + 4.days + 5.hours + 6.minutes + 7.seconds,
206
- { :vague => "Yes please" },
207
- "about 1 year"],
208
- [START_TIME,
209
- START_TIME + 1.year + 2.months + 3.weeks + 4.days + 5.hours + 6.minutes + 7.seconds,
210
- { :vague => false },
211
- "1 year, 2 months, 3 weeks, 4 days, 5 hours, 6 minutes, and 7 seconds"],
212
- [START_TIME,
213
- START_TIME + 1.year + 2.months + 3.weeks + 4.days + 5.hours + 6.minutes + 7.seconds,
214
- { :vague => nil },
215
- "1 year, 2 months, 3 weeks, 4 days, 5 hours, 6 minutes, and 7 seconds"],
229
+ { only: %w[minutes hours] },
230
+ '1 hour and 1 minute'],
216
231
  [START_TIME,
217
232
  START_TIME + 1.year + 2.months + 3.weeks + 4.days + 5.hours + 6.minutes + 7.seconds,
218
- { :except => "minutes" },
219
- "1 year, 2 months, 3 weeks, 4 days, 5 hours, and 7 seconds"],
233
+ { except: 'minutes' },
234
+ '1 year, 2 months, 3 weeks, 4 days, 5 hours, and 7 seconds'],
220
235
  [START_TIME,
221
- START_TIME + 1.hour + 2.minutes + 3.seconds,
222
- { :highest_measure_only => true },
223
- "1 hour"],
236
+ START_TIME + 1.hour + 2.minutes + 3.seconds,
237
+ { highest_measure_only: true },
238
+ '1 hour'],
224
239
  [START_TIME,
225
240
  START_TIME + 1.hours + 2.minutes + 3.seconds,
226
- { :highest_measures => 1 },
227
- "1 hour"],
241
+ { highest_measures: 1 },
242
+ '1 hour'],
228
243
  [START_TIME,
229
244
  START_TIME + 2.year + 3.months + 4.days + 5.hours + 6.minutes + 7.seconds,
230
- { :highest_measures => 3 },
231
- "2 years, 3 months, and 4 days"],
245
+ { highest_measures: 3 },
246
+ '2 years, 3 months, and 4 days'],
232
247
  [START_TIME,
233
248
  START_TIME + 2.year + 3.weeks + 4.days + 5.hours + 6.minutes + 7.seconds,
234
- { :highest_measures => 2 },
235
- "2 years and 3 weeks"],
249
+ { highest_measures: 2 },
250
+ '2 years and 3 weeks'],
236
251
  [START_TIME,
237
252
  START_TIME + 4.days + 6.minutes + 7.seconds,
238
- { :highest_measures => 3 },
239
- "4 days, 6 minutes, and 7 seconds"],
253
+ { highest_measures: 3 },
254
+ '4 days, 6 minutes, and 7 seconds'],
240
255
  [START_TIME,
241
256
  START_TIME + 1.year + 2.weeks,
242
- { :highest_measures => 3 },
243
- "1 year and 2 weeks"],
257
+ { highest_measures: 3 },
258
+ '1 year and 2 weeks'],
244
259
  [START_TIME,
245
260
  START_TIME + 1.days,
246
- { :only => [:years, :months] },
247
- "less than 1 month"],
261
+ { only: %i[years months] },
262
+ 'less than 1 month'],
248
263
  [START_TIME,
249
264
  START_TIME + 5.minutes,
250
- { :except => [:hours, :minutes, :seconds] },
251
- "less than 1 day"],
265
+ { except: %i[hours minutes seconds] },
266
+ 'less than 1 day'],
252
267
  [START_TIME,
253
268
  START_TIME + 1.days,
254
- { :highest_measures => 1, :only => [:years, :months] },
255
- "less than 1 month"]
256
- ]
257
- fragments.each do |start, finish, options, output|
269
+ { highest_measures: 1, only: %i[years months] },
270
+ 'less than 1 month']
271
+ ].each do |start, finish, options, output|
258
272
  it "should be #{output}" do
259
273
  expect(distance_of_time_in_words(start, finish, true, options)).to eq(output)
260
274
  end
261
275
  end
262
276
 
263
- describe "include_seconds" do
264
- it "is ignored if only seconds have passed" do
265
- expect(distance_of_time_in_words(START_TIME, START_TIME + 1.second, false)).to eq("1 second")
277
+ if defined?(ActionView)
278
+ describe 'ActionView' do
279
+ [
280
+ [START_TIME,
281
+ START_TIME + 1.year + 2.months + 3.weeks + 4.days + 5.hours + 6.minutes + 7.seconds,
282
+ { vague: true },
283
+ 'about 1 year'],
284
+ [START_TIME,
285
+ START_TIME + 1.year + 2.months + 3.weeks + 4.days + 5.hours + 6.minutes + 7.seconds,
286
+ { vague: 'Yes please' },
287
+ 'about 1 year'],
288
+ [START_TIME,
289
+ START_TIME + 1.year + 2.months + 3.weeks + 4.days + 5.hours + 6.minutes + 7.seconds,
290
+ { vague: false },
291
+ '1 year, 2 months, 3 weeks, 4 days, 5 hours, 6 minutes, and 7 seconds'],
292
+ [START_TIME,
293
+ START_TIME + 1.year + 2.months + 3.weeks + 4.days + 5.hours + 6.minutes + 7.seconds,
294
+ { vague: nil },
295
+ '1 year, 2 months, 3 weeks, 4 days, 5 hours, 6 minutes, and 7 seconds']
296
+ ].each do |start, finish, options, output|
297
+ it "should be #{output}" do
298
+ expect(distance_of_time_in_words(start, finish, true, options)).to eq(output)
299
+ end
300
+ end
301
+ end
302
+ end
303
+
304
+ describe 'include_seconds' do
305
+ it 'is ignored if only seconds have passed' do
306
+ expect(distance_of_time_in_words(START_TIME, START_TIME + 1.second, false)).to eq('1 second')
266
307
  end
267
308
 
268
- it "removes seconds in all other cases" do
309
+ it 'removes seconds in all other cases' do
269
310
  expect(distance_of_time_in_words(START_TIME,
270
- START_TIME + 1.year + 2.months + 3.weeks + 4.days + 5.hours + 6.minutes + 7.seconds,
271
- false)).to eq("1 year, 2 months, 3 weeks, 4 days, 5 hours, and 6 minutes")
311
+ START_TIME + 1.year + 2.months + 3.weeks + 4.days + 5.hours + 6.minutes + 7.seconds,
312
+ false)).to eq('1 year, 2 months, 3 weeks, 4 days, 5 hours, and 6 minutes')
272
313
  end
273
314
  end # include_seconds
274
315
  end
275
316
 
276
- describe "percentage of time" do
277
- def time_in_percent(options = {})
278
- distance_of_time_in_percent("04-12-2009".to_time, "29-01-2010".to_time, "04-12-2010".to_time, options)
279
- end
317
+ if defined?(ActionView)
318
+ describe 'percentage of time' do
319
+ def time_in_percent(options = {})
320
+ distance_of_time_in_percent('04-12-2009'.to_time, '29-01-2010'.to_time, '04-12-2010'.to_time, options)
321
+ end
280
322
 
281
- it "calculates 15%" do
282
- expect(time_in_percent).to eq("15%")
283
- end
323
+ it 'calculates 15%' do
324
+ expect(time_in_percent).to eq('15%')
325
+ end
284
326
 
285
- it "calculates 15.3%" do
286
- expect(time_in_percent(:precision => 1)).to eq("15.3%")
327
+ it 'calculates 15.3%' do
328
+ expect(time_in_percent(precision: 1)).to eq('15.3%')
329
+ end
287
330
  end
288
331
  end
289
-
290
332
  end