t 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,205 @@
1
+ # encoding: utf-8
2
+ require 'helper'
3
+
4
+ describe T::CLI::Search do
5
+
6
+ before do
7
+ @t = T::CLI.new
8
+ @old_stderr = $stderr
9
+ $stderr = StringIO.new
10
+ @old_stdout = $stdout
11
+ $stdout = StringIO.new
12
+ end
13
+
14
+ after do
15
+ $stderr = @old_stderr
16
+ $stdout = @old_stdout
17
+ end
18
+
19
+ describe "#all" do
20
+ before do
21
+ stub_request(:get, "https://search.twitter.com/search.json").
22
+ with(:query => {:q => "twitter", :include_entities => "false", :rpp => "20"}).
23
+ to_return(:body => fixture("search.json"), :headers => {:content_type => "application/json; charset=utf-8"})
24
+ end
25
+ it "should request the correct resource" do
26
+ @t.search("all", "twitter")
27
+ a_request(:get, "https://search.twitter.com/search.json").
28
+ with(:query => {:q => "twitter", :include_entities => "false", :rpp => "20"}).
29
+ should have_been_made
30
+ end
31
+ it "should have the correct output" do
32
+ @t.search("all", "twitter")
33
+ $stdout.string.should == <<-eos.gsub(/^/, ' ' * 6)
34
+ killermelons: @KaiserKuo from not too far away your new twitter icon looks like Vader. (about 1 year ago)
35
+ FelipeNoMore: RT @nicoMaiden: RT @golden254: Quien habra sido el habil en decirle al negro piñera que era cantante?/el mismo que le dijo a @copano que la lleva en twitter (about 1 year ago)
36
+ Je_eF: é cada louco que tem nesse twitter que o vicio nao me deixa largar isso jamé (about 1 year ago)
37
+ TriceyTrice2U: @Jae_Savage same name as twitter (about 1 year ago)
38
+ eternity4: @enishi39 Its awesome huh? Its ALL Spn anime epicness!! I had a tough time getting twitter to put it up.xD (about 1 year ago)
39
+ twittag: [Twitter*feed] 船井総研発!一番店の法則~実費型治療院(整骨院・接骨院)・サロン経営コンサルティングブログ~ http://bit.ly/cxoSGL (about 1 year ago)
40
+ twittag: [Twitter*feed] ニフティクラウド、明日より「サーバーコピー」、「カスタマイズイメージ」、「オートスケール」、「基本監視・パフォーマンスチャート」を公開 | P2P today ダブルスラッシュ http://wslash.com/?p=2959 (about 1 year ago)
41
+ twittag: [Twitter*feed] ニフティクラウド、明日より「サーバーコピー」、「カスタマイズイメージ」、「オートスケール」、「基本監視・パフォーマンスチャート」を公開 | P2P today ダブルスラッシュ http://bit.ly/aziQQo (about 1 year ago)
42
+ ArcangelHak: Bueno pues me desconectó de twitter al tatto le falta todavía un rato y ya casi tengo sueño (about 1 year ago)
43
+ recycledhumor: Just in case you are wondering, Weird Al (@alyankovic) has 1,862,789 followers on Twitter. Correction: 1,862,790 followers on Twitter. (about 1 year ago)
44
+ junitaaa: Lama&quot; chat di twitter nih..hahaha RT @buntutbabi: Lo yg mulai juga,siiietRT @Junitaaa: Kelakuan @buntutbabi (cont) http://tl.gd/6m1dcv (about 1 year ago)
45
+ twittag: [Twitter*feed] 『かちびと.net』 の人気エントリー - はてなブックマーク http://bit.ly/9Yx6xS (about 1 year ago)
46
+ avexnews: @ICONIQ_NEWS opened!She gain attention by collaboration song「I'm lovin' you」wif EXILE・ATSUSHI.Get her newest info here! http://bit.ly/dymm8v (about 1 year ago)
47
+ WildIvory92: RT @FiercePrinceJ: People on Twitter Gossip about other People, Hate others? This Is Twitter Nothing More, Nothing Less. (about 1 year ago)
48
+ twittag: [Twitter*feed] Now Playing Friends - リニューアル式 : R49 http://bit.ly/bmlA5g (about 1 year ago)
49
+ eos
50
+ end
51
+ end
52
+
53
+ describe "#timeline" do
54
+ it "should request the correct resource" do
55
+ 1.upto(16).each do |page|
56
+ stub_get("/1/statuses/home_timeline.json").
57
+ with(:query => {:count => "200", :page => "#{page}"}).
58
+ to_return(:body => fixture("statuses.json"), :headers => {:content_type => "application/json; charset=utf-8"})
59
+ end
60
+ @t.search("timeline", "twitter")
61
+ 1.upto(16).each do |page|
62
+ a_get("/1/statuses/home_timeline.json").
63
+ with(:query => {:count => "200", :page => "#{page}"}).
64
+ should have_been_made
65
+ end
66
+ end
67
+ it "should have the correct output" do
68
+ 1.upto(16).each do |page|
69
+ stub_get("/1/statuses/home_timeline.json").
70
+ with(:query => {:count => "200", :page => "#{page}"}).
71
+ to_return(:body => fixture("statuses.json"), :headers => {:content_type => "application/json; charset=utf-8"})
72
+ end
73
+ @t.search("timeline", "twitter")
74
+ $stdout.string.should == <<-eos.gsub(/^/, ' ' * 6)
75
+ sferik: 140 Proof Provides A Piece Of The Twitter Advertising Puzzle http://t.co/R2cUSDe via @techcrunch (about 1 year ago)
76
+ sferik: I know @SarahPalinUSA has a right to use Twitter, but should she? (over 1 year ago)
77
+ sferik: 140 Proof Provides A Piece Of The Twitter Advertising Puzzle http://t.co/R2cUSDe via @techcrunch (about 1 year ago)
78
+ sferik: I know @SarahPalinUSA has a right to use Twitter, but should she? (over 1 year ago)
79
+ sferik: 140 Proof Provides A Piece Of The Twitter Advertising Puzzle http://t.co/R2cUSDe via @techcrunch (about 1 year ago)
80
+ sferik: I know @SarahPalinUSA has a right to use Twitter, but should she? (over 1 year ago)
81
+ sferik: 140 Proof Provides A Piece Of The Twitter Advertising Puzzle http://t.co/R2cUSDe via @techcrunch (about 1 year ago)
82
+ sferik: I know @SarahPalinUSA has a right to use Twitter, but should she? (over 1 year ago)
83
+ sferik: 140 Proof Provides A Piece Of The Twitter Advertising Puzzle http://t.co/R2cUSDe via @techcrunch (about 1 year ago)
84
+ sferik: I know @SarahPalinUSA has a right to use Twitter, but should she? (over 1 year ago)
85
+ sferik: 140 Proof Provides A Piece Of The Twitter Advertising Puzzle http://t.co/R2cUSDe via @techcrunch (about 1 year ago)
86
+ sferik: I know @SarahPalinUSA has a right to use Twitter, but should she? (over 1 year ago)
87
+ sferik: 140 Proof Provides A Piece Of The Twitter Advertising Puzzle http://t.co/R2cUSDe via @techcrunch (about 1 year ago)
88
+ sferik: I know @SarahPalinUSA has a right to use Twitter, but should she? (over 1 year ago)
89
+ sferik: 140 Proof Provides A Piece Of The Twitter Advertising Puzzle http://t.co/R2cUSDe via @techcrunch (about 1 year ago)
90
+ sferik: I know @SarahPalinUSA has a right to use Twitter, but should she? (over 1 year ago)
91
+ sferik: 140 Proof Provides A Piece Of The Twitter Advertising Puzzle http://t.co/R2cUSDe via @techcrunch (about 1 year ago)
92
+ sferik: I know @SarahPalinUSA has a right to use Twitter, but should she? (over 1 year ago)
93
+ sferik: 140 Proof Provides A Piece Of The Twitter Advertising Puzzle http://t.co/R2cUSDe via @techcrunch (about 1 year ago)
94
+ sferik: I know @SarahPalinUSA has a right to use Twitter, but should she? (over 1 year ago)
95
+ sferik: 140 Proof Provides A Piece Of The Twitter Advertising Puzzle http://t.co/R2cUSDe via @techcrunch (about 1 year ago)
96
+ sferik: I know @SarahPalinUSA has a right to use Twitter, but should she? (over 1 year ago)
97
+ sferik: 140 Proof Provides A Piece Of The Twitter Advertising Puzzle http://t.co/R2cUSDe via @techcrunch (about 1 year ago)
98
+ sferik: I know @SarahPalinUSA has a right to use Twitter, but should she? (over 1 year ago)
99
+ sferik: 140 Proof Provides A Piece Of The Twitter Advertising Puzzle http://t.co/R2cUSDe via @techcrunch (about 1 year ago)
100
+ sferik: I know @SarahPalinUSA has a right to use Twitter, but should she? (over 1 year ago)
101
+ sferik: 140 Proof Provides A Piece Of The Twitter Advertising Puzzle http://t.co/R2cUSDe via @techcrunch (about 1 year ago)
102
+ sferik: I know @SarahPalinUSA has a right to use Twitter, but should she? (over 1 year ago)
103
+ sferik: 140 Proof Provides A Piece Of The Twitter Advertising Puzzle http://t.co/R2cUSDe via @techcrunch (about 1 year ago)
104
+ sferik: I know @SarahPalinUSA has a right to use Twitter, but should she? (over 1 year ago)
105
+ sferik: 140 Proof Provides A Piece Of The Twitter Advertising Puzzle http://t.co/R2cUSDe via @techcrunch (about 1 year ago)
106
+ sferik: I know @SarahPalinUSA has a right to use Twitter, but should she? (over 1 year ago)
107
+ eos
108
+ end
109
+ context "Twitter is down" do
110
+ it "should retry 3 times and then raise an error" do
111
+ 1.upto(15).each do |page|
112
+ stub_get("/1/statuses/home_timeline.json").
113
+ with(:query => {:count => "200", :page => "#{page}"}).
114
+ to_return(:body => fixture("statuses.json"), :headers => {:content_type => "application/json; charset=utf-8"})
115
+ end
116
+ stub_get("/1/statuses/home_timeline.json").
117
+ with(:query => {:count => "200", :page => "16"}).
118
+ to_return(:status => 502)
119
+ lambda do
120
+ @t.search("timeline", "twitter")
121
+ end.should raise_error("Twitter is down or being upgraded.")
122
+ a_get("/1/statuses/home_timeline.json").
123
+ with(:query => {:count => "200", :page => "16"}).
124
+ should have_been_made.times(3)
125
+ end
126
+ end
127
+ end
128
+
129
+ describe "#user" do
130
+ it "should request the correct resource" do
131
+ 1.upto(16).each do |page|
132
+ stub_get("/1/statuses/user_timeline.json").
133
+ with(:query => {:screen_name => "sferik", :count => "200", :page => "#{page}"}).
134
+ to_return(:body => fixture("statuses.json"), :headers => {:content_type => "application/json; charset=utf-8"})
135
+ end
136
+ @t.search("user", "sferik", "twitter")
137
+ 1.upto(16).each do |page|
138
+ a_get("/1/statuses/user_timeline.json").
139
+ with(:query => {:screen_name => "sferik", :count => "200", :page => "#{page}"}).
140
+ should have_been_made
141
+ end
142
+ end
143
+ it "should have the correct output" do
144
+ 1.upto(16).each do |page|
145
+ stub_get("/1/statuses/user_timeline.json").
146
+ with(:query => {:screen_name => "sferik", :count => "200", :page => "#{page}"}).
147
+ to_return(:body => fixture("statuses.json"), :headers => {:content_type => "application/json; charset=utf-8"})
148
+ end
149
+ @t.search("user", "sferik", "twitter")
150
+ $stdout.string.should == <<-eos.gsub(/^/, ' ' * 6)
151
+ sferik: 140 Proof Provides A Piece Of The Twitter Advertising Puzzle http://t.co/R2cUSDe via @techcrunch (about 1 year ago)
152
+ sferik: I know @SarahPalinUSA has a right to use Twitter, but should she? (over 1 year ago)
153
+ sferik: 140 Proof Provides A Piece Of The Twitter Advertising Puzzle http://t.co/R2cUSDe via @techcrunch (about 1 year ago)
154
+ sferik: I know @SarahPalinUSA has a right to use Twitter, but should she? (over 1 year ago)
155
+ sferik: 140 Proof Provides A Piece Of The Twitter Advertising Puzzle http://t.co/R2cUSDe via @techcrunch (about 1 year ago)
156
+ sferik: I know @SarahPalinUSA has a right to use Twitter, but should she? (over 1 year ago)
157
+ sferik: 140 Proof Provides A Piece Of The Twitter Advertising Puzzle http://t.co/R2cUSDe via @techcrunch (about 1 year ago)
158
+ sferik: I know @SarahPalinUSA has a right to use Twitter, but should she? (over 1 year ago)
159
+ sferik: 140 Proof Provides A Piece Of The Twitter Advertising Puzzle http://t.co/R2cUSDe via @techcrunch (about 1 year ago)
160
+ sferik: I know @SarahPalinUSA has a right to use Twitter, but should she? (over 1 year ago)
161
+ sferik: 140 Proof Provides A Piece Of The Twitter Advertising Puzzle http://t.co/R2cUSDe via @techcrunch (about 1 year ago)
162
+ sferik: I know @SarahPalinUSA has a right to use Twitter, but should she? (over 1 year ago)
163
+ sferik: 140 Proof Provides A Piece Of The Twitter Advertising Puzzle http://t.co/R2cUSDe via @techcrunch (about 1 year ago)
164
+ sferik: I know @SarahPalinUSA has a right to use Twitter, but should she? (over 1 year ago)
165
+ sferik: 140 Proof Provides A Piece Of The Twitter Advertising Puzzle http://t.co/R2cUSDe via @techcrunch (about 1 year ago)
166
+ sferik: I know @SarahPalinUSA has a right to use Twitter, but should she? (over 1 year ago)
167
+ sferik: 140 Proof Provides A Piece Of The Twitter Advertising Puzzle http://t.co/R2cUSDe via @techcrunch (about 1 year ago)
168
+ sferik: I know @SarahPalinUSA has a right to use Twitter, but should she? (over 1 year ago)
169
+ sferik: 140 Proof Provides A Piece Of The Twitter Advertising Puzzle http://t.co/R2cUSDe via @techcrunch (about 1 year ago)
170
+ sferik: I know @SarahPalinUSA has a right to use Twitter, but should she? (over 1 year ago)
171
+ sferik: 140 Proof Provides A Piece Of The Twitter Advertising Puzzle http://t.co/R2cUSDe via @techcrunch (about 1 year ago)
172
+ sferik: I know @SarahPalinUSA has a right to use Twitter, but should she? (over 1 year ago)
173
+ sferik: 140 Proof Provides A Piece Of The Twitter Advertising Puzzle http://t.co/R2cUSDe via @techcrunch (about 1 year ago)
174
+ sferik: I know @SarahPalinUSA has a right to use Twitter, but should she? (over 1 year ago)
175
+ sferik: 140 Proof Provides A Piece Of The Twitter Advertising Puzzle http://t.co/R2cUSDe via @techcrunch (about 1 year ago)
176
+ sferik: I know @SarahPalinUSA has a right to use Twitter, but should she? (over 1 year ago)
177
+ sferik: 140 Proof Provides A Piece Of The Twitter Advertising Puzzle http://t.co/R2cUSDe via @techcrunch (about 1 year ago)
178
+ sferik: I know @SarahPalinUSA has a right to use Twitter, but should she? (over 1 year ago)
179
+ sferik: 140 Proof Provides A Piece Of The Twitter Advertising Puzzle http://t.co/R2cUSDe via @techcrunch (about 1 year ago)
180
+ sferik: I know @SarahPalinUSA has a right to use Twitter, but should she? (over 1 year ago)
181
+ sferik: 140 Proof Provides A Piece Of The Twitter Advertising Puzzle http://t.co/R2cUSDe via @techcrunch (about 1 year ago)
182
+ sferik: I know @SarahPalinUSA has a right to use Twitter, but should she? (over 1 year ago)
183
+ eos
184
+ end
185
+ context "Twitter is down" do
186
+ it "should retry 3 times and then raise an error" do
187
+ 1.upto(15).each do |page|
188
+ stub_get("/1/statuses/user_timeline.json").
189
+ with(:query => {:screen_name => "sferik", :count => "200", :page => "#{page}"}).
190
+ to_return(:body => fixture("statuses.json"), :headers => {:content_type => "application/json; charset=utf-8"})
191
+ end
192
+ stub_get("/1/statuses/user_timeline.json").
193
+ with(:query => {:screen_name => "sferik", :count => "200", :page => "16"}).
194
+ to_return(:status => 502)
195
+ lambda do
196
+ @t.search("user", "sferik", "twitter")
197
+ end.should raise_error("Twitter is down or being upgraded.")
198
+ a_get("/1/statuses/user_timeline.json").
199
+ with(:query => {:screen_name => "sferik", :count => "200", :page => "16"}).
200
+ should have_been_made.times(3)
201
+ end
202
+ end
203
+ end
204
+
205
+ end
@@ -16,6 +16,351 @@ describe T::CLI::Unfollow do
16
16
  $stdout = @old_stdout
17
17
  end
18
18
 
19
+ describe "#listed" do
20
+ before do
21
+ @t.options = @t.options.merge(:profile => fixture_path + "/.trc")
22
+ stub_get("/1/account/verify_credentials.json").
23
+ to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
24
+ end
25
+ context "no users" do
26
+ before do
27
+ stub_get("/1/lists/members.json").
28
+ with(:query => {:cursor => "-1", :include_entities => "false", :owner_screen_name => "sferik", :skip_status => "true", :slug => "presidents"}).
29
+ to_return(:body => fixture("empty_cursor.json"), :headers => {:content_type => "application/json; charset=utf-8"})
30
+ end
31
+ it "should request the correct resource" do
32
+ @t.unfollow("listed", "presidents")
33
+ a_get("/1/account/verify_credentials.json").
34
+ should have_been_made
35
+ a_get("/1/lists/members.json").
36
+ with(:query => {:cursor => "-1", :include_entities => "false", :owner_screen_name => "sferik", :skip_status => "true", :slug => "presidents"}).
37
+ should have_been_made
38
+ end
39
+ it "should have the correct output" do
40
+ @t.unfollow("listed", "presidents")
41
+ $stdout.string.chomp.should == "@testcli is already not following any list members."
42
+ end
43
+ end
44
+ context "one user" do
45
+ before do
46
+ @t.options = @t.options.merge(:profile => fixture_path + "/.trc")
47
+ stub_get("/1/lists/members.json").
48
+ with(:query => {:cursor => "-1", :include_entities => "false", :owner_screen_name => "sferik", :skip_status => "true", :slug => "presidents"}).
49
+ to_return(:body => fixture("users_list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
50
+ end
51
+ it "should request the correct resource" do
52
+ stub_delete("/1/friendships/destroy.json").
53
+ with(:query => {:user_id => "7505382", :include_entities => "false"}).
54
+ to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
55
+ $stdout.should_receive(:print).with("Are you sure you want to unfollow 1 user? ")
56
+ $stdin.should_receive(:gets).and_return("yes")
57
+ @t.unfollow("listed", "presidents")
58
+ a_get("/1/account/verify_credentials.json").
59
+ should have_been_made
60
+ a_get("/1/lists/members.json").
61
+ with(:query => {:cursor => "-1", :include_entities => "false", :owner_screen_name => "sferik", :skip_status => "true", :slug => "presidents"}).
62
+ should have_been_made
63
+ a_delete("/1/friendships/destroy.json").
64
+ with(:query => {:user_id => "7505382", :include_entities => "false"}).
65
+ should have_been_made
66
+ end
67
+ context "yes" do
68
+ it "should have the correct output" do
69
+ stub_delete("/1/friendships/destroy.json").
70
+ with(:query => {:user_id => "7505382", :include_entities => "false"}).
71
+ to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
72
+ $stdout.should_receive(:print).with("Are you sure you want to unfollow 1 user? ")
73
+ $stdin.should_receive(:gets).and_return("yes")
74
+ @t.unfollow("listed", "presidents")
75
+ $stdout.string.should =~ /^@testcli is no longer following 1 user\.$/
76
+ end
77
+ end
78
+ context "no" do
79
+ it "should have the correct output" do
80
+ $stdout.should_receive(:print).with("Are you sure you want to unfollow 1 user? ")
81
+ $stdin.should_receive(:gets).and_return("no")
82
+ @t.unfollow("listed", "presidents")
83
+ $stdout.string.chomp.should == ""
84
+ end
85
+ end
86
+ context "Twitter is down" do
87
+ it "should retry 3 times and then raise an error" do
88
+ stub_delete("/1/friendships/destroy.json").
89
+ with(:query => {:user_id => "7505382", :include_entities => "false"}).
90
+ to_return(:status => 502)
91
+ $stdout.should_receive(:print).with("Are you sure you want to unfollow 1 user? ")
92
+ $stdin.should_receive(:gets).and_return("yes")
93
+ lambda do
94
+ @t.unfollow("listed", "presidents")
95
+ end.should raise_error("Twitter is down or being upgraded.")
96
+ a_delete("/1/friendships/destroy.json").
97
+ with(:query => {:user_id => "7505382", :include_entities => "false"}).
98
+ should have_been_made.times(3)
99
+ end
100
+ end
101
+ end
102
+ end
103
+
104
+ describe "#followers" do
105
+ before do
106
+ @t.options = @t.options.merge(:profile => fixture_path + "/.trc")
107
+ end
108
+ context "no followers" do
109
+ before do
110
+ stub_get("/1/followers/ids.json").
111
+ with(:query => {:cursor => "-1"}).
112
+ to_return(:body => fixture("friends_ids.json"), :headers => {:content_type => "application/json; charset=utf-8"})
113
+ stub_get("/1/friends/ids.json").
114
+ with(:query => {:cursor => "-1"}).
115
+ to_return(:body => fixture("friends_ids.json"), :headers => {:content_type => "application/json; charset=utf-8"})
116
+ end
117
+ it "should request the correct resource" do
118
+ @t.unfollow("followers")
119
+ a_get("/1/followers/ids.json").
120
+ with(:query => {:cursor => "-1"}).
121
+ should have_been_made
122
+ a_get("/1/friends/ids.json").
123
+ with(:query => {:cursor => "-1"}).
124
+ should have_been_made
125
+ end
126
+ it "should have the correct output" do
127
+ @t.unfollow("followers")
128
+ $stdout.string.chomp.should == "@testcli is already not following any followers."
129
+ end
130
+ end
131
+ context "one follower" do
132
+ before do
133
+ stub_get("/1/followers/ids.json").
134
+ with(:query => {:cursor => "-1"}).
135
+ to_return(:body => fixture("friends_ids.json"), :headers => {:content_type => "application/json; charset=utf-8"})
136
+ stub_get("/1/friends/ids.json").
137
+ with(:query => {:cursor => "-1"}).
138
+ to_return(:body => fixture("followers_ids.json"), :headers => {:content_type => "application/json; charset=utf-8"})
139
+ end
140
+ it "should request the correct resource" do
141
+ stub_delete("/1/friendships/destroy.json").
142
+ with(:query => {:user_id => "7505382", :include_entities => "false"}).
143
+ to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
144
+ $stdout.should_receive(:print).with("Are you sure you want to unfollow 1 user? ")
145
+ $stdin.should_receive(:gets).and_return("yes")
146
+ @t.unfollow("followers")
147
+ a_get("/1/followers/ids.json").
148
+ with(:query => {:cursor => "-1"}).
149
+ should have_been_made
150
+ a_get("/1/friends/ids.json").
151
+ with(:query => {:cursor => "-1"}).
152
+ should have_been_made
153
+ a_delete("/1/friendships/destroy.json").
154
+ with(:query => {:user_id => "7505382", :include_entities => "false"}).
155
+ should have_been_made
156
+ end
157
+ context "yes" do
158
+ it "should have the correct output" do
159
+ stub_delete("/1/friendships/destroy.json").
160
+ with(:query => {:user_id => "7505382", :include_entities => "false"}).
161
+ to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
162
+ $stdout.should_receive(:print).with("Are you sure you want to unfollow 1 user? ")
163
+ $stdin.should_receive(:gets).and_return("yes")
164
+ @t.unfollow("followers")
165
+ $stdout.string.should =~ /^@testcli is no longer following 1 user\.$/
166
+ end
167
+ end
168
+ context "no" do
169
+ it "should have the correct output" do
170
+ $stdout.should_receive(:print).with("Are you sure you want to unfollow 1 user? ")
171
+ $stdin.should_receive(:gets).and_return("no")
172
+ @t.unfollow("followers")
173
+ $stdout.string.chomp.should == ""
174
+ end
175
+ end
176
+ context "Twitter is down" do
177
+ it "should retry 3 times and then raise an error" do
178
+ stub_delete("/1/friendships/destroy.json").
179
+ with(:query => {:user_id => "7505382", :include_entities => "false"}).
180
+ to_return(:status => 502)
181
+ $stdout.should_receive(:print).with("Are you sure you want to unfollow 1 user? ")
182
+ $stdin.should_receive(:gets).and_return("yes")
183
+ lambda do
184
+ @t.unfollow("followers")
185
+ end.should raise_error("Twitter is down or being upgraded.")
186
+ a_delete("/1/friendships/destroy.json").
187
+ with(:query => {:user_id => "7505382", :include_entities => "false"}).
188
+ should have_been_made.times(3)
189
+ end
190
+ end
191
+ end
192
+ end
193
+
194
+ describe "#friends" do
195
+ before do
196
+ @t.options = @t.options.merge(:profile => fixture_path + "/.trc")
197
+ end
198
+ context "no friends" do
199
+ before do
200
+ stub_get("/1/friends/ids.json").
201
+ with(:query => {:cursor => "-1"}).
202
+ to_return(:body => fixture("empty_cursor.json"), :headers => {:content_type => "application/json; charset=utf-8"})
203
+ end
204
+ it "should request the correct resource" do
205
+ @t.unfollow("friends")
206
+ a_get("/1/friends/ids.json").
207
+ with(:query => {:cursor => "-1"}).
208
+ should have_been_made
209
+ end
210
+ it "should have the correct output" do
211
+ @t.unfollow("friends")
212
+ $stdout.string.chomp.should == "@testcli is already not following anyone."
213
+ end
214
+ end
215
+ context "four friends" do
216
+ before do
217
+ @t.options = @t.options.merge(:profile => fixture_path + "/.trc")
218
+ stub_get("/1/friends/ids.json").
219
+ with(:query => {:cursor => "-1"}).
220
+ to_return(:body => fixture("friends_ids.json"), :headers => {:content_type => "application/json; charset=utf-8"})
221
+ end
222
+ it "should request the correct resource" do
223
+ stub_delete("/1/friendships/destroy.json").
224
+ with(:query => {:user_id => "7505382", :include_entities => "false"}).
225
+ to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
226
+ $stdout.should_receive(:print).with("Are you sure you want to unfollow 1 user? ")
227
+ $stdin.should_receive(:gets).and_return("yes")
228
+ @t.unfollow("friends")
229
+ a_get("/1/friends/ids.json").
230
+ with(:query => {:cursor => "-1"}).
231
+ should have_been_made
232
+ a_delete("/1/friendships/destroy.json").
233
+ with(:query => {:user_id => "7505382", :include_entities => "false"}).
234
+ should have_been_made
235
+ end
236
+ context "yes" do
237
+ it "should have the correct output" do
238
+ stub_delete("/1/friendships/destroy.json").
239
+ with(:query => {:user_id => "7505382", :include_entities => "false"}).
240
+ to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
241
+ $stdout.should_receive(:print).with("Are you sure you want to unfollow 1 user? ")
242
+ $stdin.should_receive(:gets).and_return("yes")
243
+ @t.unfollow("friends")
244
+ $stdout.string.should =~ /^@testcli is no longer following 1 user\.$/
245
+ end
246
+ end
247
+ context "no" do
248
+ it "should have the correct output" do
249
+ $stdout.should_receive(:print).with("Are you sure you want to unfollow 1 user? ")
250
+ $stdin.should_receive(:gets).and_return("no")
251
+ @t.unfollow("friends")
252
+ $stdout.string.chomp.should == ""
253
+ end
254
+ end
255
+ context "Twitter is down" do
256
+ it "should retry 3 times and then raise an error" do
257
+ stub_delete("/1/friendships/destroy.json").
258
+ with(:query => {:user_id => "7505382", :include_entities => "false"}).
259
+ to_return(:status => 502)
260
+ $stdout.should_receive(:print).with("Are you sure you want to unfollow 1 user? ")
261
+ $stdin.should_receive(:gets).and_return("yes")
262
+ lambda do
263
+ @t.unfollow("friends")
264
+ end.should raise_error("Twitter is down or being upgraded.")
265
+ a_delete("/1/friendships/destroy.json").
266
+ with(:query => {:user_id => "7505382", :include_entities => "false"}).
267
+ should have_been_made.times(3)
268
+ end
269
+ end
270
+ end
271
+ end
272
+
273
+ describe "#nonfollowers" do
274
+ before do
275
+ @t.options = @t.options.merge(:profile => fixture_path + "/.trc")
276
+ end
277
+ context "no users" do
278
+ before do
279
+ stub_get("/1/friends/ids.json").
280
+ with(:query => {:cursor => "-1"}).
281
+ to_return(:body => fixture("friends_ids.json"), :headers => {:content_type => "application/json; charset=utf-8"})
282
+ stub_get("/1/followers/ids.json").
283
+ with(:query => {:cursor => "-1"}).
284
+ to_return(:body => fixture("friends_ids.json"), :headers => {:content_type => "application/json; charset=utf-8"})
285
+ end
286
+ it "should request the correct resource" do
287
+ @t.unfollow("nonfollowers")
288
+ a_get("/1/friends/ids.json").
289
+ with(:query => {:cursor => "-1"}).
290
+ should have_been_made
291
+ a_get("/1/followers/ids.json").
292
+ with(:query => {:cursor => "-1"}).
293
+ should have_been_made
294
+ end
295
+ it "should have the correct output" do
296
+ @t.unfollow("nonfollowers")
297
+ $stdout.string.chomp.should == "@testcli is already not following any non-followers."
298
+ end
299
+ end
300
+ context "one user" do
301
+ before do
302
+ @t.options = @t.options.merge(:profile => fixture_path + "/.trc")
303
+ stub_get("/1/friends/ids.json").
304
+ with(:query => {:cursor => "-1"}).
305
+ to_return(:body => fixture("friends_ids.json"), :headers => {:content_type => "application/json; charset=utf-8"})
306
+ stub_get("/1/followers/ids.json").
307
+ with(:query => {:cursor => "-1"}).
308
+ to_return(:body => fixture("followers_ids.json"), :headers => {:content_type => "application/json; charset=utf-8"})
309
+ end
310
+ it "should request the correct resource" do
311
+ stub_delete("/1/friendships/destroy.json").
312
+ with(:query => {:user_id => "7505382", :include_entities => "false"}).
313
+ to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
314
+ $stdout.should_receive(:print).with("Are you sure you want to unfollow 1 user? ")
315
+ $stdin.should_receive(:gets).and_return("yes")
316
+ @t.unfollow("nonfollowers")
317
+ a_get("/1/friends/ids.json").
318
+ with(:query => {:cursor => "-1"}).
319
+ should have_been_made
320
+ a_get("/1/followers/ids.json").
321
+ with(:query => {:cursor => "-1"}).
322
+ should have_been_made
323
+ a_delete("/1/friendships/destroy.json").
324
+ with(:query => {:user_id => "7505382", :include_entities => "false"}).
325
+ should have_been_made
326
+ end
327
+ context "yes" do
328
+ it "should have the correct output" do
329
+ stub_delete("/1/friendships/destroy.json").
330
+ with(:query => {:user_id => "7505382", :include_entities => "false"}).
331
+ to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
332
+ $stdout.should_receive(:print).with("Are you sure you want to unfollow 1 user? ")
333
+ $stdin.should_receive(:gets).and_return("yes")
334
+ @t.unfollow("nonfollowers")
335
+ $stdout.string.should =~ /^@testcli is no longer following 1 user\.$/
336
+ end
337
+ end
338
+ context "no" do
339
+ it "should have the correct output" do
340
+ $stdout.should_receive(:print).with("Are you sure you want to unfollow 1 user? ")
341
+ $stdin.should_receive(:gets).and_return("no")
342
+ @t.unfollow("nonfollowers")
343
+ $stdout.string.chomp.should == ""
344
+ end
345
+ end
346
+ context "Twitter is down" do
347
+ it "should retry 3 times and then raise an error" do
348
+ stub_delete("/1/friendships/destroy.json").
349
+ with(:query => {:user_id => "7505382", :include_entities => "false"}).
350
+ to_return(:status => 502)
351
+ $stdout.should_receive(:print).with("Are you sure you want to unfollow 1 user? ")
352
+ $stdin.should_receive(:gets).and_return("yes")
353
+ lambda do
354
+ @t.unfollow("nonfollowers")
355
+ end.should raise_error("Twitter is down or being upgraded.")
356
+ a_delete("/1/friendships/destroy.json").
357
+ with(:query => {:user_id => "7505382", :include_entities => "false"}).
358
+ should have_been_made.times(3)
359
+ end
360
+ end
361
+ end
362
+ end
363
+
19
364
  describe "#users" do
20
365
  before do
21
366
  @t.options = @t.options.merge(:profile => fixture_path + "/.trc")
@@ -28,21 +373,35 @@ describe T::CLI::Unfollow do
28
373
  end
29
374
  end
30
375
  context "one user" do
31
- before do
376
+ it "should request the correct resource" do
32
377
  stub_delete("/1/friendships/destroy.json").
33
378
  with(:query => {:screen_name => "sferik", :include_entities => "false"}).
34
379
  to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
35
- end
36
- it "should request the correct resource" do
37
380
  @t.unfollow("users", "sferik")
38
381
  a_delete("/1/friendships/destroy.json").
39
382
  with(:query => {:screen_name => "sferik", :include_entities => "false"}).
40
383
  should have_been_made
41
384
  end
42
385
  it "should have the correct output" do
386
+ stub_delete("/1/friendships/destroy.json").
387
+ with(:query => {:screen_name => "sferik", :include_entities => "false"}).
388
+ to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
43
389
  @t.unfollow("users", "sferik")
44
390
  $stdout.string.should =~ /^@testcli is no longer following 1 user\.$/
45
391
  end
392
+ context "Twitter is down" do
393
+ it "should retry 3 times and then raise an error" do
394
+ stub_delete("/1/friendships/destroy.json").
395
+ with(:query => {:screen_name => "sferik", :include_entities => "false"}).
396
+ to_return(:status => 502)
397
+ lambda do
398
+ @t.unfollow("users", "sferik")
399
+ end.should raise_error("Twitter is down or being upgraded.")
400
+ a_delete("/1/friendships/destroy.json").
401
+ with(:query => {:screen_name => "sferik", :include_entities => "false"}).
402
+ should have_been_made.times(3)
403
+ end
404
+ end
46
405
  end
47
406
  end
48
407