usaidwat 1.1.1 → 1.2.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.
@@ -0,0 +1,52 @@
1
+ require 'spec_helper'
2
+ require 'usaidwat/either'
3
+
4
+ module USaidWat
5
+ describe Either do
6
+ it 'should return the initial value if all operations are successful' do
7
+ e = Right.new("value") >>
8
+ lambda { |res| Right.new(res.value.upcase) }
9
+ expect(e).to be_kind_of(Right)
10
+ expect(e.right?).to be true
11
+ expect(e.value).to eq('VALUE')
12
+ end
13
+
14
+ it 'should return an error value if an operation is not successful' do
15
+ e = Right.new("value") >>
16
+ lambda { |res| Right.new(res.value.count) rescue Left.new('No such method') }
17
+ expect(e).to be_kind_of(Left)
18
+ expect(e.left?).to be true
19
+ expect(e.value).to eq('No such method')
20
+ end
21
+
22
+ it 'should return an error value if any operation in the chain fails' do
23
+ e = Right.new("value") >>
24
+ lambda { |res| Right.new(res.value.upcase) } >>
25
+ lambda { |res| Right.new(res.value.count) rescue Left.new('No such method') } >>
26
+ lambda { |res| Right.new(res.value.capitalize) rescue Left.new('Chain failed') }
27
+ expect(e).to be_kind_of(Left)
28
+ expect(e.left?).to be true
29
+ expect(e.value).to eq('No such method')
30
+ end
31
+
32
+ it 'should say it is left if it is a Left value' do
33
+ e = Left.new('value')
34
+ expect(e.left?).to be true
35
+ end
36
+
37
+ it 'should say it is not right if it is a Left value' do
38
+ e = Left.new('value')
39
+ expect(e.right?).to be false
40
+ end
41
+
42
+ it 'should say it is not left if it is a Right value' do
43
+ e = Right.new('value')
44
+ expect(e.left?).to be false
45
+ end
46
+
47
+ it 'should say it is right if it is a Right value' do
48
+ e = Right.new('value')
49
+ expect(e.right?).to be true
50
+ end
51
+ end
52
+ end
@@ -3,6 +3,91 @@ require 'timecop'
3
3
 
4
4
  module USaidWat
5
5
  module CLI
6
+ describe BaseFormatter do
7
+ describe "options" do
8
+ describe "date formats" do
9
+ describe "#relative_dates?" do
10
+ it "should return true if a relative date formatter" do
11
+ f = BaseFormatter.new(:date_format => :relative)
12
+ expect(f.relative_dates?).to be true
13
+ end
14
+
15
+ it "should return true if relative date option is passed as a string" do
16
+ f = BaseFormatter.new(:date_format => 'relative')
17
+ expect(f.relative_dates?).to be true
18
+ end
19
+
20
+ it "should return false if date format is absolute" do
21
+ f = BaseFormatter.new(:date_format => :absolute)
22
+ expect(f.relative_dates?).to be false
23
+ end
24
+
25
+ it "should return false if date format is absolute and is passed as a string" do
26
+ f = BaseFormatter.new(:date_format => 'absolute')
27
+ expect(f.relative_dates?).to be false
28
+ end
29
+
30
+ it "should use relative dates by default" do
31
+ f = BaseFormatter.new
32
+ expect(f.relative_dates?).to be true
33
+ end
34
+
35
+ it "should use relative dates when a date format is invalid" do
36
+ f = BaseFormatter.new(:date_format => :iso)
37
+ expect(f.relative_dates?).to be true
38
+ end
39
+ end
40
+ end
41
+
42
+ describe "patterns" do
43
+ let (:formatter) { BaseFormatter.new(:pattern => /[0-9]+/) }
44
+ describe "#pattern" do
45
+ it "should return its pattern" do
46
+ expect(formatter.pattern).to eq(/[0-9]+/)
47
+ end
48
+
49
+ it "should return nil if it does not have a pattern" do
50
+ f = BaseFormatter.new
51
+ expect(f.pattern).to be nil
52
+ end
53
+ end
54
+
55
+ describe "#pattern?" do
56
+ it "should return true if it has a pattern" do
57
+ expect(formatter.pattern?).to be true
58
+ end
59
+
60
+ it "should return false if it does not have a pattern" do
61
+ f = BaseFormatter.new
62
+ expect(f.pattern?).to be false
63
+ end
64
+
65
+ it "should return false by default" do
66
+ f = BaseFormatter.new
67
+ expect(f.pattern?).to be false
68
+ end
69
+ end
70
+ end
71
+
72
+ describe "#raw?" do
73
+ it "should return true if it is a raw formatter" do
74
+ f = BaseFormatter.new(:raw => true)
75
+ expect(f.raw?).to be true
76
+ end
77
+
78
+ it "should return false if it is not a raw formatter" do
79
+ f = BaseFormatter.new(:raw => false)
80
+ expect(f.raw?).to be false
81
+ end
82
+
83
+ it "should return false by default" do
84
+ f = BaseFormatter.new
85
+ expect(f.raw?).to be false
86
+ end
87
+ end
88
+ end
89
+ end
90
+
6
91
  describe CommentFormatter do
7
92
  let(:formatter) { CommentFormatter.new }
8
93
 
@@ -22,12 +107,14 @@ module USaidWat
22
107
  expect(comment).to receive(:id).and_return("c73qhxi")
23
108
  expect(comment).to receive(:link_title).and_return("Why Brit Ruby 2013 was cancelled and why this is not ok - Gist")
24
109
  expect(comment).to receive(:created_utc).and_return(1433378314.0)
110
+ expect(comment).to receive(:ups).and_return(12)
111
+ expect(comment).to receive(:downs).and_return(1)
25
112
  expect(comment).to receive(:body).and_return("Welcome to the wonderful world of Python drama!")
26
113
  expected = <<-EXPECTED
27
114
  programming
28
115
  http://www.reddit.com/r/programming/comments/13f783/z/c73qhxi
29
116
  Why Brit Ruby 2013 was cancelled and why this is not ok - Gist
30
- about 2 weeks ago
117
+ about 2 weeks ago \u2022 +11
31
118
 
32
119
  Welcome to the wonderful world of Python drama!
33
120
  EXPECTED
@@ -41,6 +128,8 @@ EXPECTED
41
128
  expect(comment1).to receive(:link_id).and_return("t3_13f783")
42
129
  expect(comment1).to receive(:id).and_return("c73qhxi")
43
130
  expect(comment1).to receive(:created_utc).and_return(1433378314.0)
131
+ expect(comment1).to receive(:ups).and_return(12)
132
+ expect(comment1).to receive(:downs).and_return(1)
44
133
  expect(comment1).to receive(:link_title).and_return("Why Brit Ruby 2013 was cancelled and why this is not ok - Gist")
45
134
  expect(comment1).to receive(:body).and_return("Welcome to the wonderful world of Python drama!")
46
135
  comment2 = double("second comment")
@@ -48,6 +137,8 @@ EXPECTED
48
137
  expect(comment2).to receive(:link_id).and_return("t3_13f783")
49
138
  expect(comment2).to receive(:id).and_return("c73qhxi")
50
139
  expect(comment2).to receive(:created_utc).and_return(1433378314.0)
140
+ expect(comment2).to receive(:ups).and_return(12)
141
+ expect(comment2).to receive(:downs).and_return(1)
51
142
  expect(comment2).to receive(:link_title).and_return("Why Brit Ruby 2013 was cancelled and why this is not ok - Gist")
52
143
  expect(comment2).to receive(:body).and_return("Welcome to the wonderful world of Python drama!")
53
144
  s = formatter.format(comment1)
@@ -64,6 +155,8 @@ EXPECTED
64
155
  expect(comment).to receive(:link_id).and_return("t3_13f783")
65
156
  expect(comment).to receive(:id).and_return("c73qhxi")
66
157
  expect(comment).to receive(:created_utc).and_return(1433378314.0)
158
+ expect(comment).to receive(:ups).and_return(12)
159
+ expect(comment).to receive(:downs).and_return(1)
67
160
  expect(comment).to receive(:link_title).and_return("Why Brit Ruby 2013 was cancelled and why this is not ok - Gist")
68
161
  expect(comment).to receive(:body).and_return("This is a comment.\n\nIt has two lines.\n\n\n")
69
162
  s = formatter.format(comment)
@@ -55,6 +55,144 @@ module USaidWat
55
55
  end
56
56
  end
57
57
 
58
+ describe Float do
59
+ describe "#seconds_ago" do
60
+ it "returns the elapsed seconds between now and then" do
61
+ then_ = 5.0
62
+ expect(then_.seconds_ago).to be_within(0.01).of(5.0)
63
+ end
64
+ end
65
+
66
+ describe "#minutes_ago" do
67
+ it "returns the elapsed minutes between now and then" do
68
+ then_ = 90.0
69
+ expect(then_.minutes_ago).to be_within(0.01).of(1.5)
70
+ end
71
+ end
72
+
73
+ describe "#hours_ago" do
74
+ it "returns the elapsed hours between now and then" do
75
+ then_ = 14976.0
76
+ expect(then_.hours_ago).to be_within(0.01).of(4.16)
77
+ end
78
+ end
79
+
80
+ describe "#days_ago" do
81
+ it "returns the elapsed days between now and then" do
82
+ then_ = 464832.0
83
+ expect(then_.days_ago).to be_within(0.01).of(5.38)
84
+ end
85
+ end
86
+
87
+ describe "#weeks_ago" do
88
+ it "returns the elapsed weeks between now and then" do
89
+ then_ = 2437344.0
90
+ expect(then_.weeks_ago).to be_within(0.01).of(4.03)
91
+ end
92
+ end
93
+
94
+ describe "#months_ago" do
95
+ it "returns the elapsed months between now and then" do
96
+ then_ = 47096640.0
97
+ expect(then_.months_ago).to be_within(0.01).of(18.17)
98
+ end
99
+ end
100
+
101
+ describe "#years_ago" do
102
+ it "returns the elapsed years between now and then" do
103
+ then_ = 859040640.0
104
+ expect(then_.years_ago).to be_within(0.01).of(27.24)
105
+ end
106
+ end
107
+
108
+ describe "#ago" do
109
+ it "should respond when then was a few seconds ago" do
110
+ then_ = 5.0
111
+ expect(then_.ago).to eq("less than 5 seconds ago")
112
+ end
113
+
114
+ it "should respond when then was less than 10 seconds ago" do
115
+ then_ = 10.0
116
+ expect(then_.ago).to eq("less than 10 seconds ago")
117
+ end
118
+
119
+ it "should respond when then was less than 20 seconds ago" do
120
+ then_ = 20.0
121
+ expect(then_.ago).to eq("less than 20 seconds ago")
122
+ end
123
+
124
+ it "should respond when then was less than a half minute ago" do
125
+ then_ = 40.0
126
+ expect(then_.ago).to eq("half a minute ago")
127
+ end
128
+
129
+ it "should respond when then was less than a minute ago" do
130
+ then_ = 59.0
131
+ expect(then_.ago).to eq("less than a minute ago")
132
+ end
133
+
134
+ it "should respond when then was a minute ago" do
135
+ then_ = 1.minute.to_f
136
+ expect(then_.ago).to eq("a minute ago")
137
+ end
138
+
139
+ it "should respond when then was several minutes ago" do
140
+ then_ = 45.minutes.to_f
141
+ expect(then_.ago).to eq("45 minutes ago")
142
+ end
143
+
144
+ it "should respond when then was an hour ago" do
145
+ then_ = 90.minutes.to_f
146
+ expect(then_.ago).to eq("about an hour ago")
147
+ end
148
+
149
+ it "should respond when then was several hours ago" do
150
+ then_ = 1440.minutes.to_f
151
+ expect(then_.ago).to eq("about 24 hours ago")
152
+ end
153
+
154
+ it "should respond when then was a day ago" do
155
+ then_ = 2880.minutes.to_f
156
+ expect(then_.ago).to eq("a day ago")
157
+ end
158
+
159
+ it "should respond when then was several days ago" do
160
+ then_ = 10080.minutes.to_f
161
+ expect(then_.ago).to eq("about 7 days ago")
162
+ end
163
+
164
+ it "should respond when then was a week ago" do
165
+ then_ = (1.week + 1.minute).to_f
166
+ expect(then_.ago).to eq("about 1 week ago")
167
+ end
168
+
169
+ it "should respond when then was several weeks ago" do
170
+ then_ = 43220.minutes.to_f
171
+ expect(then_.ago).to eq("about 4 weeks ago")
172
+ end
173
+
174
+ it "should respond when then was a month ago" do
175
+ then_ = 43221.minutes.to_f
176
+ expect(then_.ago).to eq("about 1 month ago")
177
+ end
178
+
179
+ it "should respond when then was several months ago" do
180
+ then_ = 180.days.to_f
181
+ expect(then_.ago).to eq("about 6 months ago")
182
+ end
183
+
184
+ it "should respond when then was a year ago" do
185
+ then_ = 1051920.minutes.to_f
186
+ expect(then_.ago).to eq("about a year ago")
187
+ end
188
+
189
+ it "should respond when then was several years ago" do
190
+ then_ = 1051921.minutes.to_f
191
+ expect(then_.ago).to eq("over 2 years ago")
192
+ end
193
+ end
194
+ end
195
+
58
196
  describe Time do
59
197
  before do
60
198
  Timecop.freeze(2015, 6, 23, 17, 22, 0)
@@ -195,10 +333,36 @@ module USaidWat
195
333
  end
196
334
 
197
335
  it "should respond when then was several years ago" do
198
- then_ = Time.now - 1051920.minutes - 1
336
+ then_ = Time.now - 1051921.minutes
199
337
  expect(then_.ago).to eq("over 2 years ago")
200
338
  end
201
339
  end
202
340
  end
341
+
342
+ describe "Special Time cases" do
343
+ it "should respond when then was almost but not quite 8 years ago" do
344
+ now = Time.new(2015, 9, 15, 16, 13, 0)
345
+ Timecop.freeze(now)
346
+ then_ = Time.new(2007, 11, 19, 10, 4)
347
+ expect(then_.ago).to eq("over 7 years ago")
348
+ Timecop.return
349
+ end
350
+
351
+ it "should respond when the delta is between 1 and 2 minutes" do
352
+ now = Time.new(2015, 9, 18, 10, 05, 20)
353
+ Timecop.freeze(now)
354
+ then_ = Time.new(2015, 9, 18, 10, 04, 0)
355
+ expect(then_.ago).to eq("a minute ago")
356
+ Timecop.return
357
+ end
358
+
359
+ it "should throw an exception if the delta is negative" do
360
+ now = Time.new(2015, 9, 18, 10, 04, 0)
361
+ Timecop.freeze(now)
362
+ then_ = Time.new(2015, 9, 18, 10, 05, 20)
363
+ expect { then_.ago }.to raise_error(ArgumentError, /negative/)
364
+ Timecop.return
365
+ end
366
+ end
203
367
  end
204
368
  end
data/usaidwat.gemspec CHANGED
@@ -16,7 +16,9 @@ Gem::Specification.new do |gem|
16
16
  gem.summary = %q{Answers the age-old question, "Where does a Redditor comment the most?"}
17
17
 
18
18
  gem.metadata = {
19
- 'build_date' => Time.now.strftime("%Y-%m-%d %H:%M:%S.%L %Z"),
19
+ 'build_date' => Time.now.strftime("%Y-%m-%d %H:%M:%S %Z"),
20
+ 'commit' => `git describe`.chomp,
21
+ 'commit_hash' => `git rev-parse HEAD`.chomp,
20
22
  }
21
23
 
22
24
  gem.files = `git ls-files`.split($/)
@@ -26,12 +28,12 @@ Gem::Specification.new do |gem|
26
28
 
27
29
  gem.required_ruby_version = '>= 1.9.3'
28
30
 
29
- gem.add_runtime_dependency('downterm', '~> 0.1.0')
30
- gem.add_runtime_dependency('highline', '~> 1.7')
31
+ gem.add_runtime_dependency('downterm', '~> 0.1.2')
31
32
  gem.add_runtime_dependency('mercenary', '~> 0.3.5')
32
33
  gem.add_runtime_dependency('rainbow', '~> 2.0')
33
34
  gem.add_runtime_dependency('snooby', '~> 0.1.5')
34
35
  gem.add_runtime_dependency('sysexits', '~> 1.2')
36
+ gem.add_runtime_dependency('tty-screen', '~> 0.4.0')
35
37
 
36
38
  gem.add_development_dependency('aruba', '~> 0.9.0')
37
39
  gem.add_development_dependency('cucumber', '~> 2.0')
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: usaidwat
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Dippery
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-30 00:00:00.000000000 Z
11
+ date: 2015-09-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: downterm
@@ -16,28 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.1.0
19
+ version: 0.1.2
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.1.0
27
- - !ruby/object:Gem::Dependency
28
- name: highline
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '1.7'
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '1.7'
26
+ version: 0.1.2
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: mercenary
43
29
  requirement: !ruby/object:Gem::Requirement
@@ -94,6 +80,20 @@ dependencies:
94
80
  - - "~>"
95
81
  - !ruby/object:Gem::Version
96
82
  version: '1.2'
83
+ - !ruby/object:Gem::Dependency
84
+ name: tty-screen
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.4.0
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.4.0
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: aruba
99
99
  requirement: !ruby/object:Gem::Requirement
@@ -178,19 +178,24 @@ files:
178
178
  - README.textile
179
179
  - Rakefile
180
180
  - bin/usaidwat
181
- - features/browse.feature
182
181
  - features/fixtures/blank.json
183
182
  - features/fixtures/mipadi.json
184
183
  - features/fixtures/testuser.json
184
+ - features/fixtures/user_mipadi.json
185
+ - features/fixtures/user_testuser.json
185
186
  - features/help.feature
187
+ - features/log.feature
186
188
  - features/step_definitions/reddit_steps.rb
187
189
  - features/step_definitions/time_steps.rb
188
190
  - features/support/aruba.rb
189
191
  - features/support/time.rb
192
+ - features/tally.feature
193
+ - features/user.feature
190
194
  - lib/usaidwat.rb
191
195
  - lib/usaidwat/algo.rb
192
196
  - lib/usaidwat/application.rb
193
197
  - lib/usaidwat/client.rb
198
+ - lib/usaidwat/either.rb
194
199
  - lib/usaidwat/ext/string.rb
195
200
  - lib/usaidwat/ext/time.rb
196
201
  - lib/usaidwat/formatter.rb
@@ -200,6 +205,7 @@ files:
200
205
  - spec/spec_helper.rb
201
206
  - spec/usaidwat/algo_spec.rb
202
207
  - spec/usaidwat/client_spec.rb
208
+ - spec/usaidwat/either_spec.rb
203
209
  - spec/usaidwat/formatter_spec.rb
204
210
  - spec/usaidwat/service_spec.rb
205
211
  - spec/usaidwat/string_spec.rb
@@ -209,7 +215,9 @@ homepage: https://github.com/mdippery/usaidwat
209
215
  licenses:
210
216
  - MIT
211
217
  metadata:
212
- build_date: 2015-08-29 22:33:13.367 PDT
218
+ build_date: 2015-09-19 10:09:24 PDT
219
+ commit: v1.2.0
220
+ commit_hash: e869e79b24c70ce12fa06be61f67b3c982da734f
213
221
  post_install_message:
214
222
  rdoc_options: []
215
223
  require_paths:
@@ -231,18 +239,23 @@ signing_key:
231
239
  specification_version: 4
232
240
  summary: Answers the age-old question, "Where does a Redditor comment the most?"
233
241
  test_files:
234
- - features/browse.feature
235
242
  - features/fixtures/blank.json
236
243
  - features/fixtures/mipadi.json
237
244
  - features/fixtures/testuser.json
245
+ - features/fixtures/user_mipadi.json
246
+ - features/fixtures/user_testuser.json
238
247
  - features/help.feature
248
+ - features/log.feature
239
249
  - features/step_definitions/reddit_steps.rb
240
250
  - features/step_definitions/time_steps.rb
241
251
  - features/support/aruba.rb
242
252
  - features/support/time.rb
253
+ - features/tally.feature
254
+ - features/user.feature
243
255
  - spec/spec_helper.rb
244
256
  - spec/usaidwat/algo_spec.rb
245
257
  - spec/usaidwat/client_spec.rb
258
+ - spec/usaidwat/either_spec.rb
246
259
  - spec/usaidwat/formatter_spec.rb
247
260
  - spec/usaidwat/service_spec.rb
248
261
  - spec/usaidwat/string_spec.rb