/
search_spec.rb
819 lines (774 loc) · 33.4 KB
/
search_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
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
# encoding: utf-8
require 'helper'
describe T::Search do
before :all do
Timecop.freeze(Time.utc(2011, 11, 24, 16, 20, 0))
T.utc_offset = 'PST'
end
after :all do
T.utc_offset = nil
Timecop.return
end
before :each do
T::RCFile.instance.path = fixture_path + "/.trc"
@search = T::Search.new
@old_stderr = $stderr
$stderr = StringIO.new
@old_stdout = $stdout
$stdout = StringIO.new
end
after :each do
T::RCFile.instance.reset
$stderr = @old_stderr
$stdout = @old_stdout
end
describe "#all" do
before do
stub_request(:get, "https://api.twitter.com/search.json").
with(:query => {:q => "twitter", :rpp => "20"}).
to_return(:body => fixture("search.json"), :headers => {:content_type => "application/json; charset=utf-8"})
end
it "should request the correct resource" do
@search.all("twitter")
a_request(:get, "https://api.twitter.com/search.json").
with(:query => {:q => "twitter", :rpp => "20"}).
should have_been_made
end
it "should have the correct output" do
@search.all("twitter")
$stdout.string.should == <<-eos
\e[1m\e[33m @Somedude\e[0m
Gotta get right with twitter
\e[1m\e[33m @TestMan\e[0m
Twitter to Facebook test
\e[1m\e[33m @Jena_Jones\e[0m
test my new twitter..... :)
\e[1m\e[33m @misterpic\e[0m
Wallah there should be a test before you can get a twitter account some
people are so dumb... better
\e[1m\e[33m @RRabbit\e[0m
Twitter is kinda fun... Kinda!
\e[1m\e[33m @JessRoveel\e[0m
Pondre lo mas importante de Hamlet en Twitter para recordarlo mejor :D
\e[1m\e[33m @lauravgeest\e[0m
Twitter doet het al 7 uur niet meer
\e[1m\e[33m @Jenny_Bearx333\e[0m
I keep thinking that twitter is @instagram , and therefore double tap all the
pics I like... #NotWorking
\e[1m\e[33m @misspoxtonX\e[0m
RT @jordantaylorhi: twitter friends > twats at school
\e[1m\e[33m @PatrickBrickman\e[0m
RT @zeus30hightower: Too all Bama fans and followers my cousin mark Barron
doesn't have a twitter so please disregard any tweets from that user
\e[1m\e[33m @KolonelX\e[0m
Ik refresh twitter op me telefoon terwijl ik tweetdeck voor me open heb staan
\e[1m\e[33m @VLGPRLG5\e[0m
@mikeyway and you too RT @NimcyGD: @gerardway Get your ass back to twitter,
okay? :3
\e[1m\e[33m @xRhiBabyx\e[0m
Trying to persuade the boyf to get on twitter and failing. Help? @holly_haime
@Ckwarburton @samwarburton_ @chrishaime @rowloboy
\e[1m\e[33m @juliotrv\e[0m
RT @lookinglassbr: Lançamentos outono-inverno 2012...CONFIRA em
http://t.co/YAk8OXp7 http://t.co/fmmrVrbG
\e[1m\e[33m @shanleyaustin27\e[0m
RT @caaammmmi: @shanleyaustin27 .....and this hahahahaa http://t.co/wzCMx6ZU
\e[1m\e[33m @Dame_Valuta\e[0m
RT @Paiser10: Great @chelseafc training at Nou Camp! #cfc
http://t.co/k00TnRyR
\e[1m\e[33m @miss_indyiah\e[0m
smh, @IndianaHustle done turned into a twitter addict..fuck goin on lol ?
\e[1m\e[33m @CAROLINEWOLLER\e[0m
RT @Mark_Ingram28: To all Bama fans and followers, please unfollow and pay no
attention to any user posing to be Mark Barron. My bro doesn't have a
twitter!
\e[1m\e[33m @shelbytrenchdww\e[0m
RT @The90sLife: Admit it, we all have a cabinet that looks like this.
http://t.co/gQEkQw5G
\e[1m\e[33m @kabos84\e[0m
RT @JF_q8: بالله عليكم ،، مو عيب !!!
.. http://t.co/e29GV7Ow
eos
end
context "--csv" do
before do
@search.options = @search.options.merge("csv" => true)
end
it "should output in CSV format" do
@search.all("twitter")
$stdout.string.should == <<-eos
ID,Posted at,Screen name,Text
194521323202624150,2011-04-23 20:20:57 +0000,Somedude,Gotta get right with twitter
194526951936212623,2011-04-23 20:20:57 +0000,TestMan,Twitter to Facebook test
194521346690562622,2011-04-23 20:20:57 +0000,Jena_Jones,test my new twitter..... :)
194521262134160820,2011-04-23 20:20:57 +0000,misterpic,Wallah there should be a test before you can get a twitter account some people are so dumb... better
194521016652621340,2011-04-23 20:20:57 +0000,RRabbit,Twitter is kinda fun... Kinda!
194521262415032320,2011-04-23 20:20:57 +0000,JessRoveel,Pondre lo mas importante de Hamlet en Twitter para recordarlo mejor :D
194521262326951936,2011-04-23 20:20:57 +0000,lauravgeest,Twitter doet het al 7 uur niet meer
194521262234669056,2011-04-23 20:20:57 +0000,Jenny_Bearx333,"I keep thinking that twitter is @instagram , and therefore double tap all the pics I like... #NotWorking"
194521262138204160,2011-04-23 20:20:57 +0000,misspoxtonX,RT @jordantaylorhi: twitter friends > twats at school
194521262134001665,2011-04-23 20:20:57 +0000,PatrickBrickman,RT @zeus30hightower: Too all Bama fans and followers my cousin mark Barron doesn't have a twitter so please disregard any tweets from that user
194521262129811456,2011-04-23 20:20:57 +0000,KolonelX,Ik refresh twitter op me telefoon terwijl ik tweetdeck voor me open heb staan
194521261852995586,2011-04-23 20:20:57 +0000,VLGPRLG5,"@mikeyway and you too RT @NimcyGD: @gerardway Get your ass back to twitter, okay? :3"
194521261756530689,2011-04-23 20:20:57 +0000,xRhiBabyx,Trying to persuade the boyf to get on twitter and failing. Help? @holly_haime @Ckwarburton @samwarburton_ @chrishaime @rowloboy
194521261630697473,2011-04-23 20:20:57 +0000,juliotrv,RT @lookinglassbr: Lançamentos outono-inverno 2012...CONFIRA em http://t.co/YAk8OXp7 http://t.co/fmmrVrbG
194521261571964928,2011-04-23 20:20:57 +0000,shanleyaustin27,RT @caaammmmi: @shanleyaustin27 .....and this hahahahaa http://t.co/wzCMx6ZU
194521261563580416,2011-04-23 20:20:57 +0000,Dame_Valuta,RT @Paiser10: Great @chelseafc training at Nou Camp! #cfc http://t.co/k00TnRyR
194521261488095232,2011-04-23 20:20:57 +0000,miss_indyiah,"smh, @IndianaHustle done turned into a twitter addict..fuck goin on lol ?"
194521261370650625,2011-04-23 20:20:57 +0000,CAROLINEWOLLER,"RT @Mark_Ingram28: To all Bama fans and followers, please unfollow and pay no attention to any user posing to be Mark Barron. My bro doesn't have a twitter!"
194521261370642432,2011-04-23 20:20:57 +0000,shelbytrenchdww,"RT @The90sLife: Admit it, we all have a cabinet that looks like this. http://t.co/gQEkQw5G"
194521261307727872,2011-04-23 20:20:57 +0000,kabos84,"RT @JF_q8: بالله عليكم ،، مو عيب !!!
.. http://t.co/e29GV7Ow"
eos
end
end
context "--long" do
before do
@search.options = @search.options.merge("long" => true)
end
it "should output in long format" do
@search.all("twitter")
$stdout.string.should == <<-eos
ID Posted at Screen name Text
194521323202624150 Apr 23 2011 @Somedude Gotta get right with twitter
194526951936212623 Apr 23 2011 @TestMan Twitter to Facebook test
194521346690562622 Apr 23 2011 @Jena_Jones test my new twitter..... :)
194521262134160820 Apr 23 2011 @misterpic Wallah there should be a ...
194521016652621340 Apr 23 2011 @RRabbit Twitter is kinda fun... K...
194521262415032320 Apr 23 2011 @JessRoveel Pondre lo mas importante ...
194521262326951936 Apr 23 2011 @lauravgeest Twitter doet het al 7 uur...
194521262234669056 Apr 23 2011 @Jenny_Bearx333 I keep thinking that twit...
194521262138204160 Apr 23 2011 @misspoxtonX RT @jordantaylorhi: twitt...
194521262134001665 Apr 23 2011 @PatrickBrickman RT @zeus30hightower: Too ...
194521262129811456 Apr 23 2011 @KolonelX Ik refresh twitter op me ...
194521261852995586 Apr 23 2011 @VLGPRLG5 @mikeyway and you too RT ...
194521261756530689 Apr 23 2011 @xRhiBabyx Trying to persuade the bo...
194521261630697473 Apr 23 2011 @juliotrv RT @lookinglassbr: Lançam...
194521261571964928 Apr 23 2011 @shanleyaustin27 RT @caaammmmi: @shanleyau...
194521261563580416 Apr 23 2011 @Dame_Valuta RT @Paiser10: Great @chel...
194521261488095232 Apr 23 2011 @miss_indyiah smh, @IndianaHustle done ...
194521261370650625 Apr 23 2011 @CAROLINEWOLLER RT @Mark_Ingram28: To all...
194521261370642432 Apr 23 2011 @shelbytrenchdww RT @The90sLife: Admit it,...
194521261307727872 Apr 23 2011 @kabos84 RT @JF_q8: بالله عليكم ،...
eos
end
end
context "--number" do
before do
stub_request(:get, "https://api.twitter.com/search.json").
with(:query => {:q => "twitter", :rpp => "1"}).
to_return(:body => fixture("search.json"), :headers => {:content_type => "application/json; charset=utf-8"})
stub_request(:get, "https://api.twitter.com/search.json").
with(:query => {:q => "twitter", :rpp => "200"}).
to_return(:body => fixture("search.json"), :headers => {:content_type => "application/json; charset=utf-8"})
stub_request(:get, "https://api.twitter.com/search.json").
with(:query => {:q => "twitter", :rpp => "200", :max_id => "194521261307727871"}).
to_return(:body => fixture("search.json"), :headers => {:content_type => "application/json; charset=utf-8"})
(5..185).step(20).to_a.reverse.each do |count|
stub_request(:get, "https://api.twitter.com/search.json").
with(:query => {:q => "twitter", :rpp => count, :max_id => "194521261307727871"}).
to_return(:body => fixture("search.json"), :headers => {:content_type => "application/json; charset=utf-8"})
end
end
it "should limit the number of results to 1" do
@search.options = @search.options.merge("number" => 1)
@search.all("twitter")
a_request(:get, "https://api.twitter.com/search.json").
with(:query => {:q => "twitter", :rpp => "1"}).
should have_been_made
end
it "should limit the number of results to 345" do
@search.options = @search.options.merge("number" => 345)
@search.all("twitter")
a_request(:get, "https://api.twitter.com/search.json").
with(:query => {:q => "twitter", :rpp => "200"}).
should have_been_made
a_request(:get, "https://api.twitter.com/search.json").
with(:query => {:q => "twitter", :rpp => "200", :max_id => "194521261307727871"}).
should have_been_made.times(7)
(5..185).step(20).to_a.reverse.each do |count|
a_request(:get, "https://api.twitter.com/search.json").
with(:query => {:q => "twitter", :rpp => count, :max_id => "194521261307727871"}).
should have_been_made
end
end
end
end
describe "#favorites" do
before do
stub_get("/1/favorites.json").
with(:query => {:count => "200"}).
to_return(:body => fixture("statuses.json"), :headers => {:content_type => "application/json; charset=utf-8"})
stub_get("/1/favorites.json").
with(:query => {:count => "200", :max_id => "194546264212385792"}).
to_return(:body => fixture("empty_array.json"), :headers => {:content_type => "application/json; charset=utf-8"})
end
it "should request the correct resource" do
@search.favorites("twitter")
a_get("/1/favorites.json").
with(:query => {:count => "200"}).
should have_been_made
a_get("/1/favorites.json").
with(:query => {:count => "200", :max_id => "194546264212385792"}).
should have_been_made
end
it "should have the correct output" do
@search.favorites("twitter")
$stdout.string.should == <<-eos
\e[1m\e[33m @bartt\e[0m
@noahlt @gaarf Yup, now owning @twitter -> FB from FE to daemons. Lot’s of
fun. Expect improvements in the weeks to come.
eos
end
context "--csv" do
before do
@search.options = @search.options.merge("csv" => true)
end
it "should output in CSV format" do
@search.favorites("twitter")
$stdout.string.should == <<-eos
ID,Posted at,Screen name,Text
194546727670390784,2011-04-23 22:02:09 +0000,bartt,"@noahlt @gaarf Yup, now owning @twitter -> FB from FE to daemons. Lot’s of fun. Expect improvements in the weeks to come."
eos
end
end
context "--long" do
before do
@search.options = @search.options.merge("long" => true)
end
it "should output in long format" do
@search.favorites("twitter")
$stdout.string.should == <<-eos
ID Posted at Screen name Text
194546727670390784 Apr 23 2011 @bartt @noahlt @gaarf Yup, now owning...
eos
end
end
context "Twitter is down" do
it "should retry 3 times and then raise an error" do
stub_get("/1/favorites.json").
with(:query => {:count => "200"}).
to_return(:status => 502)
lambda do
@search.favorites("twitter")
end.should raise_error("Twitter is down or being upgraded.")
a_get("/1/favorites.json").
with(:query => {:count => "200"}).
should have_been_made.times(3)
end
end
end
describe "#mentions" do
before do
stub_get("/1/statuses/mentions.json").
with(:query => {:count => "200"}).
to_return(:body => fixture("statuses.json"), :headers => {:content_type => "application/json; charset=utf-8"})
stub_get("/1/statuses/mentions.json").
with(:query => {:count => "200", :max_id => "194546264212385792"}).
to_return(:body => fixture("empty_array.json"), :headers => {:content_type => "application/json; charset=utf-8"})
end
it "should request the correct resource" do
@search.mentions("twitter")
a_get("/1/statuses/mentions.json").
with(:query => {:count => "200"}).
should have_been_made
a_get("/1/statuses/mentions.json").
with(:query => {:count => "200", :max_id => "194546264212385792"}).
should have_been_made
end
it "should have the correct output" do
@search.mentions("twitter")
$stdout.string.should == <<-eos
\e[1m\e[33m @bartt\e[0m
@noahlt @gaarf Yup, now owning @twitter -> FB from FE to daemons. Lot’s of
fun. Expect improvements in the weeks to come.
eos
end
context "--csv" do
before do
@search.options = @search.options.merge("csv" => true)
end
it "should output in CSV format" do
@search.mentions("twitter")
$stdout.string.should == <<-eos
ID,Posted at,Screen name,Text
194546727670390784,2011-04-23 22:02:09 +0000,bartt,"@noahlt @gaarf Yup, now owning @twitter -> FB from FE to daemons. Lot’s of fun. Expect improvements in the weeks to come."
eos
end
end
context "--long" do
before do
@search.options = @search.options.merge("long" => true)
end
it "should output in long format" do
@search.mentions("twitter")
$stdout.string.should == <<-eos
ID Posted at Screen name Text
194546727670390784 Apr 23 2011 @bartt @noahlt @gaarf Yup, now owning...
eos
end
end
context "Twitter is down" do
it "should retry 3 times and then raise an error" do
stub_get("/1/statuses/mentions.json").
with(:query => {:count => "200"}).
to_return(:status => 502)
lambda do
@search.mentions("twitter")
end.should raise_error("Twitter is down or being upgraded.")
a_get("/1/statuses/mentions.json").
with(:query => {:count => "200"}).
should have_been_made.times(3)
end
end
end
describe "#list" do
before do
stub_get("/1/lists/statuses.json").
with(:query => {:count => "200", :owner_screen_name => "testcli", :slug => "presidents"}).
to_return(:body => fixture("statuses.json"), :headers => {:content_type => "application/json; charset=utf-8"})
stub_get("/1/lists/statuses.json").
with(:query => {:count => "200", :max_id => "194546264212385792", :owner_screen_name => "testcli", :slug => "presidents"}).
to_return(:body => fixture("empty_array.json"), :headers => {:content_type => "application/json; charset=utf-8"})
end
it "should request the correct resource" do
@search.list("presidents", "twitter")
a_get("/1/lists/statuses.json").
with(:query => {:count => "200", :owner_screen_name => "testcli", :slug => "presidents"}).
should have_been_made
a_get("/1/lists/statuses.json").
with(:query => {:count => "200", :max_id => "194546264212385792", :owner_screen_name => "testcli", :slug => "presidents"}).
should have_been_made
end
it "should have the correct output" do
@search.list("presidents", "twitter")
$stdout.string.should == <<-eos
\e[1m\e[33m @bartt\e[0m
@noahlt @gaarf Yup, now owning @twitter -> FB from FE to daemons. Lot’s of
fun. Expect improvements in the weeks to come.
eos
end
context "--csv" do
before do
@search.options = @search.options.merge("csv" => true)
end
it "should output in CSV format" do
@search.list("presidents", "twitter")
$stdout.string.should == <<-eos
ID,Posted at,Screen name,Text
194546727670390784,2011-04-23 22:02:09 +0000,bartt,"@noahlt @gaarf Yup, now owning @twitter -> FB from FE to daemons. Lot’s of fun. Expect improvements in the weeks to come."
eos
end
end
context "--long" do
before do
@search.options = @search.options.merge("long" => true)
end
it "should output in long format" do
@search.list("presidents", "twitter")
$stdout.string.should == <<-eos
ID Posted at Screen name Text
194546727670390784 Apr 23 2011 @bartt @noahlt @gaarf Yup, now owning...
eos
end
end
context "with a user passed" do
it "should request the correct resource" do
@search.list("testcli/presidents", "twitter")
a_get("/1/lists/statuses.json").
with(:query => {:count => "200", :owner_screen_name => "testcli", :slug => "presidents"}).
should have_been_made
end
context "--id" do
before do
@search.options = @search.options.merge("id" => true)
stub_get("/1/lists/statuses.json").
with(:query => {:count => "200", :owner_id => "7505382", :slug => "presidents"}).
to_return(:body => fixture("statuses.json"), :headers => {:content_type => "application/json; charset=utf-8"})
stub_get("/1/lists/statuses.json").
with(:query => {:count => "200", :max_id => "194546264212385792", :owner_id => "7505382", :slug => "presidents"}).
to_return(:body => fixture("empty_array.json"), :headers => {:content_type => "application/json; charset=utf-8"})
end
it "should request the correct resource" do
@search.list("7505382/presidents", "twitter")
a_get("/1/lists/statuses.json").
with(:query => {:count => "200", :owner_id => "7505382", :slug => "presidents"}).
should have_been_made
a_get("/1/lists/statuses.json").
with(:query => {:count => "200", :max_id => "194546264212385792", :owner_id => "7505382", :slug => "presidents"}).
should have_been_made
end
end
end
context "Twitter is down" do
it "should retry 3 times and then raise an error" do
stub_get("/1/lists/statuses.json").
with(:query => {:count => "200", :owner_screen_name => "testcli", :slug => "presidents"}).
to_return(:status => 502)
lambda do
@search.list("presidents", "twitter")
end.should raise_error("Twitter is down or being upgraded.")
a_get("/1/lists/statuses.json").
with(:query => {:count => "200", :owner_screen_name => "testcli", :slug => "presidents"}).
should have_been_made.times(3)
end
end
end
describe "#retweets" do
before do
stub_get("/1/statuses/retweeted_by_me.json").
with(:query => {:count => "200"}).
to_return(:body => fixture("statuses.json"), :headers => {:content_type => "application/json; charset=utf-8"})
stub_get("/1/statuses/retweeted_by_me.json").
with(:query => {:count => "200", :max_id => "194546264212385792"}).
to_return(:body => fixture("empty_array.json"), :headers => {:content_type => "application/json; charset=utf-8"})
end
it "should request the correct resource" do
@search.retweets("twitter")
a_get("/1/statuses/retweeted_by_me.json").
with(:query => {:count => "200"}).
should have_been_made
a_get("/1/statuses/retweeted_by_me.json").
with(:query => {:count => "200", :max_id => "194546264212385792"}).
should have_been_made
end
it "should have the correct output" do
@search.retweets("twitter")
$stdout.string.should == <<-eos
\e[1m\e[33m @bartt\e[0m
@noahlt @gaarf Yup, now owning @twitter -> FB from FE to daemons. Lot’s of
fun. Expect improvements in the weeks to come.
eos
end
context "--csv" do
before do
@search.options = @search.options.merge("csv" => true)
end
it "should output in CSV format" do
@search.retweets("twitter")
$stdout.string.should == <<-eos
ID,Posted at,Screen name,Text
194546727670390784,2011-04-23 22:02:09 +0000,bartt,"@noahlt @gaarf Yup, now owning @twitter -> FB from FE to daemons. Lot’s of fun. Expect improvements in the weeks to come."
eos
end
end
context "--long" do
before do
@search.options = @search.options.merge("long" => true)
end
it "should output in long format" do
@search.retweets("twitter")
$stdout.string.should == <<-eos
ID Posted at Screen name Text
194546727670390784 Apr 23 2011 @bartt @noahlt @gaarf Yup, now owning...
eos
end
end
context "Twitter is down" do
it "should retry 3 times and then raise an error" do
stub_get("/1/statuses/retweeted_by_me.json").
with(:query => {:count => "200"}).
to_return(:status => 502)
lambda do
@search.retweets("twitter")
end.should raise_error("Twitter is down or being upgraded.")
a_get("/1/statuses/retweeted_by_me.json").
with(:query => {:count => "200"}).
should have_been_made.times(3)
end
end
end
describe "#timeline" do
before do
stub_get("/1/statuses/home_timeline.json").
with(:query => {:count => "200"}).
to_return(:body => fixture("statuses.json"), :headers => {:content_type => "application/json; charset=utf-8"})
stub_get("/1/statuses/home_timeline.json").
with(:query => {:count => "200", :max_id => "194546264212385792"}).
to_return(:body => fixture("empty_array.json"), :headers => {:content_type => "application/json; charset=utf-8"})
end
it "should request the correct resource" do
@search.timeline("twitter")
a_get("/1/statuses/home_timeline.json").
with(:query => {:count => "200"}).
should have_been_made
a_get("/1/statuses/home_timeline.json").
with(:query => {:count => "200", :max_id => "194546264212385792"}).
should have_been_made
end
it "should have the correct output" do
@search.timeline("twitter")
$stdout.string.should == <<-eos
\e[1m\e[33m @bartt\e[0m
@noahlt @gaarf Yup, now owning @twitter -> FB from FE to daemons. Lot’s of
fun. Expect improvements in the weeks to come.
eos
end
context "--csv" do
before do
@search.options = @search.options.merge("csv" => true)
end
it "should output in CSV format" do
@search.timeline("twitter")
$stdout.string.should == <<-eos
ID,Posted at,Screen name,Text
194546727670390784,2011-04-23 22:02:09 +0000,bartt,"@noahlt @gaarf Yup, now owning @twitter -> FB from FE to daemons. Lot’s of fun. Expect improvements in the weeks to come."
eos
end
end
context "--long" do
before do
@search.options = @search.options.merge("long" => true)
end
it "should output in long format" do
@search.timeline("twitter")
$stdout.string.should == <<-eos
ID Posted at Screen name Text
194546727670390784 Apr 23 2011 @bartt @noahlt @gaarf Yup, now owning...
eos
end
end
context "Twitter is down" do
it "should retry 3 times and then raise an error" do
stub_get("/1/statuses/home_timeline.json").
with(:query => {:count => "200"}).
to_return(:status => 502)
lambda do
@search.timeline("twitter")
end.should raise_error("Twitter is down or being upgraded.")
a_get("/1/statuses/home_timeline.json").
with(:query => {:count => "200"}).
should have_been_made.times(3)
end
end
context "with a user passed" do
before do
stub_get("/1/statuses/user_timeline.json").
with(:query => {:count => "200", :screen_name => "sferik"}).
to_return(:body => fixture("statuses.json"), :headers => {:content_type => "application/json; charset=utf-8"})
stub_get("/1/statuses/user_timeline.json").
with(:query => {:count => "200", :max_id => "194546264212385792", :screen_name => "sferik"}).
to_return(:body => fixture("empty_array.json"), :headers => {:content_type => "application/json; charset=utf-8"})
end
it "should request the correct resource" do
@search.timeline("sferik", "twitter")
a_get("/1/statuses/user_timeline.json").
with(:query => {:count => "200", :screen_name => "sferik"}).
should have_been_made
a_get("/1/statuses/user_timeline.json").
with(:query => {:count => "200", :max_id => "194546264212385792", :screen_name => "sferik"}).
should have_been_made
end
it "should have the correct output" do
@search.timeline("sferik", "twitter")
$stdout.string.should == <<-eos
\e[1m\e[33m @bartt\e[0m
@noahlt @gaarf Yup, now owning @twitter -> FB from FE to daemons. Lot’s of
fun. Expect improvements in the weeks to come.
eos
end
context "--csv" do
before do
@search.options = @search.options.merge("csv" => true)
end
it "should output in CSV format" do
@search.timeline("sferik", "twitter")
$stdout.string.should == <<-eos
ID,Posted at,Screen name,Text
194546727670390784,2011-04-23 22:02:09 +0000,bartt,"@noahlt @gaarf Yup, now owning @twitter -> FB from FE to daemons. Lot’s of fun. Expect improvements in the weeks to come."
eos
end
end
context "--id" do
before do
@search.options = @search.options.merge("id" => true)
stub_get("/1/statuses/user_timeline.json").
with(:query => {:count => "200", :user_id => "7505382"}).
to_return(:body => fixture("statuses.json"), :headers => {:content_type => "application/json; charset=utf-8"})
stub_get("/1/statuses/user_timeline.json").
with(:query => {:count => "200", :max_id => "194546264212385792", :user_id => "7505382"}).
to_return(:body => fixture("empty_array.json"), :headers => {:content_type => "application/json; charset=utf-8"})
end
it "should request the correct resource" do
@search.timeline("7505382", "twitter")
a_get("/1/statuses/user_timeline.json").
with(:query => {:count => "200", :user_id => "7505382"}).
should have_been_made
a_get("/1/statuses/user_timeline.json").
with(:query => {:count => "200", :max_id => "194546264212385792", :user_id => "7505382"}).
should have_been_made
end
end
context "--long" do
before do
@search.options = @search.options.merge("long" => true)
end
it "should output in long format" do
@search.timeline("sferik", "twitter")
$stdout.string.should == <<-eos
ID Posted at Screen name Text
194546727670390784 Apr 23 2011 @bartt @noahlt @gaarf Yup, now owning...
eos
end
end
context "Twitter is down" do
it "should retry 3 times and then raise an error" do
stub_get("/1/statuses/user_timeline.json").
with(:query => {:screen_name => "sferik", :count => "200"}).
to_return(:status => 502)
lambda do
@search.timeline("sferik", "twitter")
end.should raise_error("Twitter is down or being upgraded.")
a_get("/1/statuses/user_timeline.json").
with(:query => {:screen_name => "sferik", :count => "200"}).
should have_been_made.times(3)
end
end
end
end
describe "#users" do
before do
stub_get("/1/users/search.json").
with(:query => {:page => "1", :q => "Erik"}).
to_return(:body => fixture("users.json"), :headers => {:content_type => "application/json; charset=utf-8"})
stub_get("/1/users/search.json").
with(:query => {:page => "2", :q => "Erik"}).
to_return(:body => fixture("empty_array.json"), :headers => {:content_type => "application/json; charset=utf-8"})
end
it "should request the correct resource" do
@search.users("Erik")
1.upto(50).each do |page|
a_get("/1/users/search.json").
with(:query => {:page => "1", :q => "Erik"}).
should have_been_made
a_get("/1/users/search.json").
with(:query => {:page => "2", :q => "Erik"}).
should have_been_made
end
end
it "should have the correct output" do
@search.users("Erik")
$stdout.string.chomp.should == "pengwynn sferik"
end
context "--csv" do
before do
@search.options = @search.options.merge("csv" => true)
end
it "should output in CSV format" do
@search.users("Erik")
$stdout.string.should == <<-eos
ID,Since,Last tweeted at,Tweets,Favorites,Listed,Following,Followers,Screen name,Name
14100886,2008-03-08 16:34:22 +0000,2010-10-21 10:33:15 +0000,3913,32,185,1871,2767,pengwynn,Wynn Netherland
7505382,2007-07-16 12:59:01 +0000,2011-01-16 21:38:25 +0000,2962,727,29,88,898,sferik,Erik Michaels-Ober
eos
end
end
context "--favorites" do
before do
@search.options = @search.options.merge("favorites" => true)
end
it "should sort by number of favorites" do
@search.users("Erik")
$stdout.string.chomp.should == "pengwynn sferik"
end
end
context "--followers" do
before do
@search.options = @search.options.merge("followers" => true)
end
it "should sort by number of followers" do
@search.users("Erik")
$stdout.string.chomp.should == "sferik pengwynn"
end
end
context "--friends" do
before do
@search.options = @search.options.merge("friends" => true)
end
it "should sort by number of friends" do
@search.users("Erik")
$stdout.string.chomp.should == "sferik pengwynn"
end
end
context "--listed" do
before do
@search.options = @search.options.merge("listed" => true)
end
it "should sort by number of list memberships" do
@search.users("Erik")
$stdout.string.chomp.should == "sferik pengwynn"
end
end
context "--long" do
before do
@search.options = @search.options.merge("long" => true)
end
it "should output in long format" do
@search.users("Erik")
$stdout.string.should == <<-eos
ID Since Last tweeted at Tweets Favorites Listed Following...
14100886 Mar 8 2008 Oct 21 2010 3913 32 185 1871...
7505382 Jul 16 2007 Jan 16 2011 2962 727 29 88...
eos
end
end
context "--posted" do
before do
@search.options = @search.options.merge("posted" => true)
end
it "should sort by the time wshen Twitter account was created" do
@search.users("Erik")
$stdout.string.chomp.should == "sferik pengwynn"
end
end
context "--reverse" do
before do
@search.options = @search.options.merge("reverse" => true)
end
it "should reverse the order of the sort" do
@search.users("Erik")
$stdout.string.chomp.should == "sferik pengwynn"
end
end
context "--tweets" do
before do
@search.options = @search.options.merge("tweets" => true)
end
it "should sort by number of Tweets" do
@search.users("Erik")
$stdout.string.chomp.should == "sferik pengwynn"
end
end
context "--tweeted" do
before do
@search.options = @search.options.merge("tweeted" => true)
end
it "should sort by the time of the last Tweet" do
@search.users("Erik")
$stdout.string.chomp.should == "pengwynn sferik"
end
end
context "--unsorted" do
before do
@search.options = @search.options.merge("unsorted" => true)
end
it "should not be sorted" do
@search.users("Erik")
$stdout.string.chomp.should == "sferik pengwynn"
end
end
context "Twitter is down" do
it "should retry 3 times and then raise an error" do
stub_get("/1/users/search.json").
with(:query => {:page => "2", :q => "Erik", }).
to_return(:status => 502)
lambda do
@search.users("Erik")
end.should raise_error("Twitter is down or being upgraded.")
a_get("/1/users/search.json").
with(:query => {:page => "2", :q => "Erik", }).
should have_been_made.times(3)
end
end
end
end