forked from sferik/t-ruby
/
list_spec.rb
437 lines (428 loc) · 22.8 KB
/
list_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
# encoding: utf-8
require 'helper'
describe T::List do
before do
rcfile = RCFile.instance
rcfile.path = fixture_path + "/.trc"
@list = T::List.new
@old_stderr = $stderr
$stderr = StringIO.new
@old_stdout = $stdout
$stdout = StringIO.new
Timecop.freeze(Time.utc(2011, 11, 24, 16, 20, 0))
end
after do
Timecop.return
$stderr = @old_stderr
$stdout = @old_stdout
end
describe "#add" do
before do
@list.options = @list.options.merge(:profile => fixture_path + "/.trc")
stub_get("/1/account/verify_credentials.json").
to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
stub_post("/1/lists/members/create_all.json").
with(:body => {:screen_name => "BarackObama", :slug => "presidents", :owner_screen_name => "sferik"}).
to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
end
it "should request the correct resource" do
@list.add("presidents", "BarackObama")
a_get("/1/account/verify_credentials.json").
should have_been_made
a_post("/1/lists/members/create_all.json").
with(:body => {:screen_name => "BarackObama", :slug => "presidents", :owner_screen_name => "sferik"}).
should have_been_made
end
it "should have the correct output" do
@list.add("presidents", "BarackObama")
$stdout.string.should =~ /@testcli added 1 member to the list "presidents"\./
end
context "--id" do
before do
@list.options = @list.options.merge(:id => true)
stub_post("/1/lists/members/create_all.json").
with(:body => {:user_id => "7505382", :slug => "presidents", :owner_screen_name => "sferik"}).
to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
end
it "should request the correct resource" do
@list.add("presidents", "7505382")
a_get("/1/account/verify_credentials.json").
should have_been_made
a_post("/1/lists/members/create_all.json").
with(:body => {:user_id => "7505382", :slug => "presidents", :owner_screen_name => "sferik"}).
should have_been_made
end
end
context "Twitter is down" do
it "should retry 3 times and then raise an error" do
stub_post("/1/lists/members/create_all.json").
with(:body => {:screen_name => "BarackObama", :slug => "presidents", :owner_screen_name => "sferik"}).
to_return(:status => 502)
lambda do
@list.add("presidents", "BarackObama")
end.should raise_error("Twitter is down or being upgraded.")
a_post("/1/lists/members/create_all.json").
with(:body => {:screen_name => "BarackObama", :slug => "presidents", :owner_screen_name => "sferik"}).
should have_been_made.times(3)
end
end
end
describe "#create" do
before do
@list.options = @list.options.merge(:profile => fixture_path + "/.trc")
stub_post("/1/lists/create.json").
with(:body => {:name => "presidents"}).
to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
end
it "should request the correct resource" do
@list.create("presidents")
a_post("/1/lists/create.json").
with(:body => {:name => "presidents"}).
should have_been_made
end
it "should have the correct output" do
@list.create("presidents")
$stdout.string.chomp.should == "@testcli created the list \"presidents\"."
end
end
describe "#members" do
before do
stub_get("/1/lists/members.json").
with(:query => {:cursor => "-1", :include_entities => "false", :owner_screen_name => "testcli", :skip_status => "true", :slug => "presidents"}).
to_return(:body => fixture("users_list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
end
it "should request the correct resource" do
@list.members("presidents")
a_get("/1/lists/members.json").
with(:query => {:cursor => "-1", :include_entities => "false", :owner_screen_name => "testcli", :skip_status => "true", :slug => "presidents"}).
should have_been_made
end
it "should have the correct output" do
@list.members("presidents")
$stdout.string.rstrip.should == "@pengwynn @sferik"
end
context "--created" do
before do
@list.options = @list.options.merge(:created => true)
end
it "should sort by the time wshen Twitter account was created" do
@list.members("presidents")
$stdout.string.rstrip.should == "@sferik @pengwynn"
end
end
context "--favorites" do
before do
@list.options = @list.options.merge(:favorites => true)
end
it "should sort by number of favorites" do
@list.members("presidents")
$stdout.string.rstrip.should == "@pengwynn @sferik"
end
end
context "--followers" do
before do
@list.options = @list.options.merge(:followers => true)
end
it "should sort by number of followers" do
@list.members("presidents")
$stdout.string.rstrip.should == "@sferik @pengwynn"
end
end
context "--friends" do
before do
@list.options = @list.options.merge(:friends => true)
end
it "should sort by number of friends" do
@list.members("presidents")
$stdout.string.rstrip.should == "@sferik @pengwynn"
end
end
context "--listed" do
before do
@list.options = @list.options.merge(:listed => true)
end
it "should sort by number of list memberships" do
@list.members("presidents")
$stdout.string.rstrip.should == "@sferik @pengwynn"
end
end
context "--long" do
before do
@list.options = @list.options.merge(:long => true)
end
it "should list in long format" do
@list.members("presidents")
$stdout.string.should == <<-eos
ID Since Tweets Favorites Listed Following Followers Screen name Name
14100886 Mar 8 2008 3,913 32 185 1,871 2,767 @pengwynn Wynn Netherland
7505382 Jul 16 2007 2,962 727 29 88 898 @sferik Erik Michaels-Ober
eos
end
end
context "--reverse" do
before do
@list.options = @list.options.merge(:reverse => true)
end
it "should reverse the order of the sort" do
@list.members("presidents")
$stdout.string.rstrip.should == "@sferik @pengwynn"
end
end
context "--tweets" do
before do
@list.options = @list.options.merge(:tweets => true)
end
it "should sort by number of Tweets" do
@list.members("presidents")
$stdout.string.rstrip.should == "@sferik @pengwynn"
end
end
context "--unsorted" do
before do
@list.options = @list.options.merge(:unsorted => true)
end
it "should not be sorted" do
@list.members("presidents")
$stdout.string.rstrip.should == "@sferik @pengwynn"
end
end
context "with a user passed" do
before do
stub_get("/1/lists/members.json").
with(:query => {:cursor => "-1", :include_entities => "false", :owner_screen_name => "sferik", :skip_status => "true", :slug => "presidents"}).
to_return(:body => fixture("users_list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
end
it "should request the correct resource" do
@list.members("sferik/presidents")
a_get("/1/lists/members.json").
with(:query => {:cursor => "-1", :include_entities => "false", :owner_screen_name => "sferik", :skip_status => "true", :slug => "presidents"}).
should have_been_made
end
it "should have the correct output" do
@list.members("sferik/presidents")
$stdout.string.rstrip.should == "@pengwynn @sferik"
end
context "--id" do
before do
@list.options = @list.options.merge(:id => true)
stub_get("/1/lists/members.json").
with(:query => {:cursor => "-1", :include_entities => "false", :owner_id => "7505382", :skip_status => "true", :slug => "presidents"}).
to_return(:body => fixture("users_list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
end
it "should request the correct resource" do
@list.members("7505382/presidents")
a_get("/1/lists/members.json").
with(:query => {:cursor => "-1", :include_entities => "false", :owner_id => "7505382", :skip_status => "true", :slug => "presidents"}).
should have_been_made
end
end
end
end
describe "#remove" do
before do
@list.options = @list.options.merge(:profile => fixture_path + "/.trc")
stub_get("/1/account/verify_credentials.json").
to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
end
it "should request the correct resource" do
stub_post("/1/lists/members/destroy_all.json").
with(:body => {:screen_name => "BarackObama", :slug => "presidents", :owner_screen_name => "sferik"}).
to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
@list.remove("presidents", "BarackObama")
a_get("/1/account/verify_credentials.json").
should have_been_made
a_post("/1/lists/members/destroy_all.json").
with(:body => {:screen_name => "BarackObama", :slug => "presidents", :owner_screen_name => "sferik"}).
should have_been_made
end
it "should have the correct output" do
stub_post("/1/lists/members/destroy_all.json").
with(:body => {:screen_name => "BarackObama", :slug => "presidents", :owner_screen_name => "sferik"}).
to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
@list.remove("presidents", "BarackObama")
$stdout.string.should =~ /@testcli removed 1 member from the list "presidents"\./
end
context "--id" do
before do
@list.options = @list.options.merge(:id => true)
stub_post("/1/lists/members/destroy_all.json").
with(:body => {:user_id => "7505382", :slug => "presidents", :owner_screen_name => "sferik"}).
to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
end
it "should request the correct resource" do
@list.remove("presidents", "7505382")
a_get("/1/account/verify_credentials.json").
should have_been_made
a_post("/1/lists/members/destroy_all.json").
with(:body => {:user_id => "7505382", :slug => "presidents", :owner_screen_name => "sferik"}).
should have_been_made
end
end
context "Twitter is down" do
it "should retry 3 times and then raise an error" do
stub_post("/1/lists/members/destroy_all.json").
with(:body => {:screen_name => "BarackObama", :slug => "presidents", :owner_screen_name => "sferik"}).
to_return(:status => 502)
lambda do
@list.remove("presidents", "BarackObama")
end.should raise_error("Twitter is down or being upgraded.")
a_post("/1/lists/members/destroy_all.json").
with(:body => {:screen_name => "BarackObama", :slug => "presidents", :owner_screen_name => "sferik"}).
should have_been_made.times(3)
end
end
end
describe "#timeline" do
before do
stub_get("/1/lists/statuses.json").
with(:query => {:owner_screen_name => "testcli", :per_page => "20", :slug => "presidents", :include_entities => "false"}).
to_return(:body => fixture("statuses.json"), :headers => {:content_type => "application/json; charset=utf-8"})
end
it "should request the correct resource" do
@list.timeline("presidents")
a_get("/1/lists/statuses.json").
with(:query => {:owner_screen_name => "testcli", :per_page => "20", :slug => "presidents", :include_entities => "false"}).
should have_been_made
end
it "should have the correct output" do
@list.timeline("presidents")
$stdout.string.should == <<-eos
natevillegas: RT @gelobautista #riordan RT @WilI_Smith: Yesterday is history. Tomorrow is a mystery. Today is a gift. That's why it's called the present. (7 months ago)
TD: @kelseysilver how long will you be in town? (7 months ago)
rusashka: @maciej hahaha :) @gpena together we're going to cover all core 28 languages! (7 months ago)
fat: @stevej @xc i'm going to picket when i get back. (7 months ago)
wil: @0x9900 @paulnivin http://t.co/bwVdtAPe (7 months ago)
wangtian: @tianhonghe @xiangxin72 oh, you can even order specific items? (7 months ago)
shinypb: @kpk Pfft, I think you're forgetting mechanical television, which depended on a clever German. http://t.co/JvLNQCDm @skilldrick @hoverbird (7 months ago)
0x9900: @wil @paulnivin if you want to take you seriously don't say daemontools! (7 months ago)
kpk: @shinypb @skilldrick @hoverbird invented it (7 months ago)
skilldrick: @shinypb Well played :) @hoverbird (7 months ago)
sam: Can someone project the date that I'll get a 27" retina display? (7 months ago)
shinypb: @skilldrick @hoverbird Wow, I didn't even know they *had* TV in Britain. (7 months ago)
bartt: @noahlt @gaarf Yup, now owning @twitter -> FB from FE to daemons. Lot’s of fun. Expect improvements in the weeks to come. (7 months ago)
skilldrick: @hoverbird @shinypb You guys must be soooo old, I don't remember the words to the duck tales intro at all. (7 months ago)
sean: @mep Thanks for coming by. Was great to have you. (7 months ago)
hoverbird: @shinypb @trammell it's all suck a "duck blur" sometimes. (7 months ago)
kelseysilver: San Francisco here I come! (@ Newark Liberty International Airport (EWR) w/ 92 others) http://t.co/eoLANJZw (7 months ago)
eos
end
context "--long" do
before do
@list.options = @list.options.merge(:long => true)
end
it "should list in long format" do
@list.timeline("presidents")
$stdout.string.should == <<-eos
ID Posted at Screen name Text
194548121416630272 Apr 23 2011 @natevillegas RT @gelobautista #riordan RT @WilI_Smith: Yesterday is history. Tomorrow is a mystery. Today is a gift. That's why it's called the present.
194547993607806976 Apr 23 2011 @TD @kelseysilver how long will you be in town?
194547987593183233 Apr 23 2011 @rusashka @maciej hahaha :) @gpena together we're going to cover all core 28 languages!
194547824690597888 Apr 23 2011 @fat @stevej @xc i'm going to picket when i get back.
194547658562605057 Apr 23 2011 @wil @0x9900 @paulnivin http://t.co/bwVdtAPe
194547528430137344 Apr 23 2011 @wangtian @tianhonghe @xiangxin72 oh, you can even order specific items?
194547402550689793 Apr 23 2011 @shinypb @kpk Pfft, I think you're forgetting mechanical television, which depended on a clever German. http://t.co/JvLNQCDm @skilldrick @hoverbird
194547260233760768 Apr 23 2011 @0x9900 @wil @paulnivin if you want to take you seriously don't say daemontools!
194547084349804544 Apr 23 2011 @kpk @shinypb @skilldrick @hoverbird invented it
194546876782092291 Apr 23 2011 @skilldrick @shinypb Well played :) @hoverbird
194546811480969217 Apr 23 2011 @sam Can someone project the date that I'll get a 27" retina display?
194546738810458112 Apr 23 2011 @shinypb @skilldrick @hoverbird Wow, I didn't even know they *had* TV in Britain.
194546727670390784 Apr 23 2011 @bartt @noahlt @gaarf Yup, now owning @twitter -> FB from FE to daemons. Lot’s of fun. Expect improvements in the weeks to come.
194546649203347456 Apr 23 2011 @skilldrick @hoverbird @shinypb You guys must be soooo old, I don't remember the words to the duck tales intro at all.
194546583608639488 Apr 23 2011 @sean @mep Thanks for coming by. Was great to have you.
194546388707717120 Apr 23 2011 @hoverbird @shinypb @trammell it's all suck a "duck blur" sometimes.
194546264212385793 Apr 23 2011 @kelseysilver San Francisco here I come! (@ Newark Liberty International Airport (EWR) w/ 92 others) http://t.co/eoLANJZw
eos
end
end
context "--number" do
before do
@list.options = @list.options.merge(:number => 1)
stub_get("/1/lists/statuses.json").
with(:query => {:owner_screen_name => "testcli", :per_page => "1", :slug => "presidents", :include_entities => "false"}).
to_return(:body => fixture("statuses.json"), :headers => {:content_type => "application/json; charset=utf-8"})
end
it "should limit the number of results" do
@list.timeline("presidents")
a_get("/1/lists/statuses.json").
with(:query => {:owner_screen_name => "testcli", :per_page => "1", :slug => "presidents", :include_entities => "false"}).
should have_been_made
end
end
context "--reverse" do
before do
@list.options = @list.options.merge(:reverse => true)
end
it "should reverse the order of the sort" do
@list.timeline("presidents")
$stdout.string.should == <<-eos
kelseysilver: San Francisco here I come! (@ Newark Liberty International Airport (EWR) w/ 92 others) http://t.co/eoLANJZw (7 months ago)
hoverbird: @shinypb @trammell it's all suck a "duck blur" sometimes. (7 months ago)
sean: @mep Thanks for coming by. Was great to have you. (7 months ago)
skilldrick: @hoverbird @shinypb You guys must be soooo old, I don't remember the words to the duck tales intro at all. (7 months ago)
bartt: @noahlt @gaarf Yup, now owning @twitter -> FB from FE to daemons. Lot’s of fun. Expect improvements in the weeks to come. (7 months ago)
shinypb: @skilldrick @hoverbird Wow, I didn't even know they *had* TV in Britain. (7 months ago)
sam: Can someone project the date that I'll get a 27" retina display? (7 months ago)
skilldrick: @shinypb Well played :) @hoverbird (7 months ago)
kpk: @shinypb @skilldrick @hoverbird invented it (7 months ago)
0x9900: @wil @paulnivin if you want to take you seriously don't say daemontools! (7 months ago)
shinypb: @kpk Pfft, I think you're forgetting mechanical television, which depended on a clever German. http://t.co/JvLNQCDm @skilldrick @hoverbird (7 months ago)
wangtian: @tianhonghe @xiangxin72 oh, you can even order specific items? (7 months ago)
wil: @0x9900 @paulnivin http://t.co/bwVdtAPe (7 months ago)
fat: @stevej @xc i'm going to picket when i get back. (7 months ago)
rusashka: @maciej hahaha :) @gpena together we're going to cover all core 28 languages! (7 months ago)
TD: @kelseysilver how long will you be in town? (7 months ago)
natevillegas: RT @gelobautista #riordan RT @WilI_Smith: Yesterday is history. Tomorrow is a mystery. Today is a gift. That's why it's called the present. (7 months ago)
eos
end
end
context "with a user passed" do
before do
stub_get("/1/lists/statuses.json").
with(:query => {:owner_screen_name => "sferik", :per_page => "20", :slug => "presidents", :include_entities => "false"}).
to_return(:body => fixture("statuses.json"), :headers => {:content_type => "application/json; charset=utf-8"})
end
it "should request the correct resource" do
@list.timeline("sferik/presidents")
a_get("/1/lists/statuses.json").
with(:query => {:owner_screen_name => "sferik", :per_page => "20", :slug => "presidents", :include_entities => "false"}).
should have_been_made
end
it "should have the correct output" do
@list.timeline("sferik/presidents")
$stdout.string.should == <<-eos
natevillegas: RT @gelobautista #riordan RT @WilI_Smith: Yesterday is history. Tomorrow is a mystery. Today is a gift. That's why it's called the present. (7 months ago)
TD: @kelseysilver how long will you be in town? (7 months ago)
rusashka: @maciej hahaha :) @gpena together we're going to cover all core 28 languages! (7 months ago)
fat: @stevej @xc i'm going to picket when i get back. (7 months ago)
wil: @0x9900 @paulnivin http://t.co/bwVdtAPe (7 months ago)
wangtian: @tianhonghe @xiangxin72 oh, you can even order specific items? (7 months ago)
shinypb: @kpk Pfft, I think you're forgetting mechanical television, which depended on a clever German. http://t.co/JvLNQCDm @skilldrick @hoverbird (7 months ago)
0x9900: @wil @paulnivin if you want to take you seriously don't say daemontools! (7 months ago)
kpk: @shinypb @skilldrick @hoverbird invented it (7 months ago)
skilldrick: @shinypb Well played :) @hoverbird (7 months ago)
sam: Can someone project the date that I'll get a 27" retina display? (7 months ago)
shinypb: @skilldrick @hoverbird Wow, I didn't even know they *had* TV in Britain. (7 months ago)
bartt: @noahlt @gaarf Yup, now owning @twitter -> FB from FE to daemons. Lot’s of fun. Expect improvements in the weeks to come. (7 months ago)
skilldrick: @hoverbird @shinypb You guys must be soooo old, I don't remember the words to the duck tales intro at all. (7 months ago)
sean: @mep Thanks for coming by. Was great to have you. (7 months ago)
hoverbird: @shinypb @trammell it's all suck a "duck blur" sometimes. (7 months ago)
kelseysilver: San Francisco here I come! (@ Newark Liberty International Airport (EWR) w/ 92 others) http://t.co/eoLANJZw (7 months ago)
eos
end
context "--id" do
before do
@list.options = @list.options.merge(:id => true)
stub_get("/1/lists/statuses.json").
with(:query => {:owner_id => "7505382", :per_page => "20", :slug => "presidents", :include_entities => "false"}).
to_return(:body => fixture("statuses.json"), :headers => {:content_type => "application/json; charset=utf-8"})
end
it "should request the correct resource" do
@list.timeline("7505382/presidents")
a_get("/1/lists/statuses.json").
with(:query => {:owner_id => "7505382", :per_page => "20", :slug => "presidents", :include_entities => "false"}).
should have_been_made
end
end
end
end
end