t 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,422 +0,0 @@
1
- # encoding: utf-8
2
- require 'helper'
3
-
4
- describe T::CLI::List::Remove do
5
-
6
- before do
7
- rcfile = RCFile.instance
8
- rcfile.path = fixture_path + "/.trc"
9
- @t = T::CLI.new
10
- @old_stderr = $stderr
11
- $stderr = StringIO.new
12
- @old_stdout = $stdout
13
- $stdout = StringIO.new
14
- end
15
-
16
- after do
17
- $stderr = @old_stderr
18
- $stdout = @old_stdout
19
- end
20
-
21
- describe "#friends" do
22
- before do
23
- @t.options = @t.options.merge(:profile => fixture_path + "/.trc")
24
- stub_get("/1/account/verify_credentials.json").
25
- to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
26
- end
27
- context "no friends" do
28
- before do
29
- stub_get("/1/lists/members.json").
30
- with(:query => {:cursor => "-1", :include_entities => "false", :owner_screen_name => "sferik", :skip_status => "true", :slug => "presidents"}).
31
- to_return(:body => fixture("empty_cursor.json"), :headers => {:content_type => "application/json; charset=utf-8"})
32
- stub_get("/1/friends/ids.json").
33
- with(:query => {:cursor => "-1"}).
34
- to_return(:body => fixture("empty_cursor.json"), :headers => {:content_type => "application/json; charset=utf-8"})
35
- end
36
- it "should request the correct resource" do
37
- @t.list("remove", "friends", "presidents")
38
- a_get("/1/friends/ids.json").
39
- with(:query => {:cursor => "-1"}).
40
- should have_been_made
41
- end
42
- it "should have the correct output" do
43
- @t.list("remove", "friends", "presidents")
44
- $stdout.string.chomp.should == "None of @testcli's friends are members of the list \"presidents\"."
45
- end
46
- end
47
- context "one friend" do
48
- before do
49
- stub_get("/1/lists/members.json").
50
- with(:query => {:cursor => "-1", :include_entities => "false", :owner_screen_name => "sferik", :skip_status => "true", :slug => "presidents"}).
51
- to_return(:body => fixture("empty_cursor.json"), :headers => {:content_type => "application/json; charset=utf-8"})
52
- stub_get("/1/friends/ids.json").
53
- with(:query => {:cursor => "-1"}).
54
- to_return(:body => fixture("friends_ids.json"), :headers => {:content_type => "application/json; charset=utf-8"})
55
- end
56
- it "should request the correct resource" do
57
- stub_post("/1/lists/members/destroy_all.json").
58
- with(:body => {:user_id => "7505382", :slug => "presidents", :owner_screen_name => "sferik"}).
59
- to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
60
- $stdout.should_receive(:print).with("Are you sure you want to remove 1 friend from the list \"presidents\"? ")
61
- $stdin.should_receive(:gets).and_return("yes")
62
- @t.list("remove", "friends", "presidents")
63
- a_get("/1/account/verify_credentials.json").
64
- should have_been_made
65
- a_get("/1/lists/members.json").
66
- with(:query => {:cursor => "-1", :include_entities => "false", :owner_screen_name => "sferik", :skip_status => "true", :slug => "presidents"}).
67
- should have_been_made
68
- a_get("/1/friends/ids.json").
69
- with(:query => {:cursor => "-1"}).
70
- should have_been_made
71
- a_post("/1/lists/members/destroy_all.json").
72
- with(:body => {:user_id => "7505382", :slug => "presidents", :owner_screen_name => "sferik"}).
73
- should have_been_made
74
- end
75
- context "yes" do
76
- it "should have the correct output" do
77
- stub_post("/1/lists/members/destroy_all.json").
78
- with(:body => {:user_id => "7505382", :slug => "presidents", :owner_screen_name => "sferik"}).
79
- to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
80
- $stdout.should_receive(:print).with("Are you sure you want to remove 1 friend from the list \"presidents\"? ")
81
- $stdin.should_receive(:gets).and_return("yes")
82
- @t.list("remove", "friends", "presidents")
83
- $stdout.string.should =~ /@testcli removed 1 friend from the list "presidents"\./
84
- end
85
- context "Twitter is down" do
86
- it "should retry 3 times and then raise an error" do
87
- stub_post("/1/lists/members/destroy_all.json").
88
- with(:body => {:user_id => "7505382", :slug => "presidents", :owner_screen_name => "sferik"}).
89
- to_return(:status => 502)
90
- $stdout.should_receive(:print).with("Are you sure you want to remove 1 friend from the list \"presidents\"? ")
91
- $stdin.should_receive(:gets).and_return("yes")
92
- lambda do
93
- @t.list("remove", "friends", "presidents")
94
- end.should raise_error("Twitter is down or being upgraded.")
95
- a_post("/1/lists/members/destroy_all.json").
96
- with(:body => {:user_id => "7505382", :slug => "presidents", :owner_screen_name => "sferik"}).
97
- should have_been_made.times(3)
98
- end
99
- end
100
- end
101
- context "no" do
102
- it "should have the correct output" do
103
- $stdout.should_receive(:print).with("Are you sure you want to remove 1 friend from the list \"presidents\"? ")
104
- $stdin.should_receive(:gets).and_return("no")
105
- @t.list("remove", "friends", "presidents")
106
- $stdout.string.chomp.should == ""
107
- end
108
- end
109
- end
110
- end
111
-
112
- describe "#followers" do
113
- before do
114
- @t.options = @t.options.merge(:profile => fixture_path + "/.trc")
115
- stub_get("/1/account/verify_credentials.json").
116
- to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
117
- end
118
- context "no followers" do
119
- before do
120
- stub_get("/1/lists/members.json").
121
- with(:query => {:cursor => "-1", :include_entities => "false", :owner_screen_name => "sferik", :skip_status => "true", :slug => "presidents"}).
122
- to_return(:body => fixture("empty_cursor.json"), :headers => {:content_type => "application/json; charset=utf-8"})
123
- stub_get("/1/followers/ids.json").
124
- with(:query => {:cursor => "-1"}).
125
- to_return(:body => fixture("empty_cursor.json"), :headers => {:content_type => "application/json; charset=utf-8"})
126
- end
127
- it "should request the correct resource" do
128
- @t.list("remove", "followers", "presidents")
129
- a_get("/1/followers/ids.json").
130
- with(:query => {:cursor => "-1"}).
131
- should have_been_made
132
- end
133
- it "should have the correct output" do
134
- @t.list("remove", "followers", "presidents")
135
- $stdout.string.chomp.should == "None of @testcli's followers are members of the list \"presidents\"."
136
- end
137
- end
138
- context "two followers" do
139
- before do
140
- stub_get("/1/lists/members.json").
141
- with(:query => {:cursor => "-1", :include_entities => "false", :owner_screen_name => "sferik", :skip_status => "true", :slug => "presidents"}).
142
- to_return(:body => fixture("empty_cursor.json"), :headers => {:content_type => "application/json; charset=utf-8"})
143
- stub_get("/1/followers/ids.json").
144
- with(:query => {:cursor => "-1"}).
145
- to_return(:body => fixture("followers_ids.json"), :headers => {:content_type => "application/json; charset=utf-8"})
146
- end
147
- it "should request the correct resource" do
148
- stub_post("/1/lists/members/destroy_all.json").
149
- with(:body => {:user_id => "213747670,428004849", :slug => "presidents", :owner_screen_name => "sferik"}).
150
- to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
151
- $stdout.should_receive(:print).with("Are you sure you want to remove 2 followers from the list \"presidents\"? ")
152
- $stdin.should_receive(:gets).and_return("yes")
153
- @t.list("remove", "followers", "presidents")
154
- a_get("/1/account/verify_credentials.json").
155
- should have_been_made
156
- a_get("/1/lists/members.json").
157
- with(:query => {:cursor => "-1", :include_entities => "false", :owner_screen_name => "sferik", :skip_status => "true", :slug => "presidents"}).
158
- should have_been_made
159
- a_get("/1/followers/ids.json").
160
- with(:query => {:cursor => "-1"}).
161
- should have_been_made
162
- a_post("/1/lists/members/destroy_all.json").
163
- with(:body => {:user_id => "213747670,428004849", :slug => "presidents", :owner_screen_name => "sferik"}).
164
- should have_been_made
165
- end
166
- context "yes" do
167
- it "should have the correct output" do
168
- stub_post("/1/lists/members/destroy_all.json").
169
- with(:body => {:user_id => "213747670,428004849", :slug => "presidents", :owner_screen_name => "sferik"}).
170
- to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
171
- $stdout.should_receive(:print).with("Are you sure you want to remove 2 followers from the list \"presidents\"? ")
172
- $stdin.should_receive(:gets).and_return("yes")
173
- @t.list("remove", "followers", "presidents")
174
- $stdout.string.should =~ /@testcli removed 2 followers from the list "presidents"\./
175
- end
176
- context "Twitter is down" do
177
- it "should retry 3 times and then raise an error" do
178
- stub_post("/1/lists/members/destroy_all.json").
179
- with(:body => {:user_id => "213747670,428004849", :slug => "presidents", :owner_screen_name => "sferik"}).
180
- to_return(:status => 502)
181
- $stdout.should_receive(:print).with("Are you sure you want to remove 2 followers from the list \"presidents\"? ")
182
- $stdin.should_receive(:gets).and_return("yes")
183
- lambda do
184
- @t.list("remove", "followers", "presidents")
185
- end.should raise_error("Twitter is down or being upgraded.")
186
- a_post("/1/lists/members/destroy_all.json").
187
- with(:body => {:user_id => "213747670,428004849", :slug => "presidents", :owner_screen_name => "sferik"}).
188
- should have_been_made.times(3)
189
- end
190
- end
191
- end
192
- context "no" do
193
- it "should have the correct output" do
194
- $stdout.should_receive(:print).with("Are you sure you want to remove 2 followers from the list \"presidents\"? ")
195
- $stdin.should_receive(:gets).and_return("no")
196
- @t.list("remove", "followers", "presidents")
197
- $stdout.string.chomp.should == ""
198
- end
199
- end
200
- end
201
- end
202
-
203
- describe "#listed" do
204
- before do
205
- @t.options = @t.options.merge(:profile => fixture_path + "/.trc")
206
- stub_get("/1/account/verify_credentials.json").
207
- to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
208
- end
209
- context "no users" do
210
- before do
211
- stub_get("/1/lists/members.json").
212
- with(:query => {:cursor => "-1", :include_entities => "false", :owner_screen_name => "sferik", :skip_status => "true", :slug => "presidents"}).
213
- to_return(:body => fixture("empty_cursor.json"), :headers => {:content_type => "application/json; charset=utf-8"})
214
- stub_get("/1/lists/members.json").
215
- with(:query => {:cursor => "-1", :include_entities => "false", :owner_screen_name => "sferik", :skip_status => "true", :slug => "democrats"}).
216
- to_return(:body => fixture("empty_cursor.json"), :headers => {:content_type => "application/json; charset=utf-8"})
217
- end
218
- it "should request the correct resource" do
219
- @t.list("remove", "listed", "democrats", "presidents")
220
- a_get("/1/account/verify_credentials.json").
221
- should have_been_made
222
- a_get("/1/lists/members.json").
223
- with(:query => {:cursor => "-1", :include_entities => "false", :owner_screen_name => "sferik", :skip_status => "true", :slug => "presidents"}).
224
- should have_been_made
225
- a_get("/1/lists/members.json").
226
- with(:query => {:cursor => "-1", :include_entities => "false", :owner_screen_name => "sferik", :skip_status => "true", :slug => "democrats"}).
227
- should have_been_made
228
- end
229
- it "should have the correct output" do
230
- @t.list("remove", "listed", "democrats", "presidents")
231
- $stdout.string.chomp.should == "None of the members of the list \"democrats\" are members of the list \"presidents\"."
232
- end
233
- end
234
- context "one user" do
235
- before do
236
- stub_get("/1/lists/members.json").
237
- with(:query => {:cursor => "-1", :include_entities => "false", :owner_screen_name => "sferik", :skip_status => "true", :slug => "presidents"}).
238
- to_return(:body => fixture("empty_cursor.json"), :headers => {:content_type => "application/json; charset=utf-8"})
239
- stub_get("/1/lists/members.json").
240
- with(:query => {:cursor => "-1", :include_entities => "false", :owner_screen_name => "sferik", :skip_status => "true", :slug => "democrats"}).
241
- to_return(:body => fixture("users_list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
242
- end
243
- it "should request the correct resource" do
244
- stub_post("/1/lists/members/destroy_all.json").
245
- with(:body => {:user_id => "7505382", :slug => "presidents", :owner_screen_name => "sferik"}).
246
- to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
247
- $stdout.should_receive(:print).with("Are you sure you want to remove 1 member from the list \"presidents\"? ")
248
- $stdin.should_receive(:gets).and_return("yes")
249
- @t.list("remove", "listed", "democrats", "presidents")
250
- a_get("/1/account/verify_credentials.json").
251
- should have_been_made
252
- a_get("/1/lists/members.json").
253
- with(:query => {:cursor => "-1", :include_entities => "false", :owner_screen_name => "sferik", :skip_status => "true", :slug => "presidents"}).
254
- should have_been_made
255
- a_get("/1/lists/members.json").
256
- with(:query => {:cursor => "-1", :include_entities => "false", :owner_screen_name => "sferik", :skip_status => "true", :slug => "democrats"}).
257
- should have_been_made
258
- a_post("/1/lists/members/destroy_all.json").
259
- with(:body => {:user_id => "7505382", :slug => "presidents", :owner_screen_name => "sferik"}).
260
- should have_been_made
261
- end
262
- context "yes" do
263
- it "should have the correct output" do
264
- stub_post("/1/lists/members/destroy_all.json").
265
- with(:body => {:user_id => "7505382", :slug => "presidents", :owner_screen_name => "sferik"}).
266
- to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
267
- $stdout.should_receive(:print).with("Are you sure you want to remove 1 member from the list \"presidents\"? ")
268
- $stdin.should_receive(:gets).and_return("yes")
269
- @t.list("remove", "listed", "democrats", "presidents")
270
- $stdout.string.should =~ /@testcli removed 1 member from the list "presidents"\./
271
- end
272
- context "Twitter is down" do
273
- it "should retry 3 times and then raise an error" do
274
- stub_post("/1/lists/members/destroy_all.json").
275
- with(:body => {:user_id => "7505382", :slug => "presidents", :owner_screen_name => "sferik"}).
276
- to_return(:status => 502)
277
- $stdout.should_receive(:print).with("Are you sure you want to remove 1 member from the list \"presidents\"? ")
278
- $stdin.should_receive(:gets).and_return("yes")
279
- lambda do
280
- @t.list("remove", "listed", "democrats", "presidents")
281
- end.should raise_error("Twitter is down or being upgraded.")
282
- a_post("/1/lists/members/destroy_all.json").
283
- with(:body => {:user_id => "7505382", :slug => "presidents", :owner_screen_name => "sferik"}).
284
- should have_been_made.times(3)
285
- end
286
- end
287
- end
288
- context "no" do
289
- it "should have the correct output" do
290
- $stdout.should_receive(:print).with("Are you sure you want to remove 1 member from the list \"presidents\"? ")
291
- $stdin.should_receive(:gets).and_return("no")
292
- @t.list("remove", "listed", "democrats", "presidents")
293
- $stdout.string.chomp.should == ""
294
- end
295
- end
296
- end
297
- end
298
-
299
- describe "#members" do
300
- before do
301
- @t.options = @t.options.merge(:profile => fixture_path + "/.trc")
302
- stub_get("/1/account/verify_credentials.json").
303
- to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
304
- end
305
- context "no users" do
306
- before do
307
- stub_get("/1/lists/members.json").
308
- with(:query => {:cursor => "-1", :include_entities => "false", :owner_screen_name => "sferik", :skip_status => "true", :slug => "presidents"}).
309
- to_return(:body => fixture("empty_cursor.json"), :headers => {:content_type => "application/json; charset=utf-8"})
310
- end
311
- it "should request the correct resource" do
312
- @t.list("remove", "members", "presidents")
313
- a_get("/1/account/verify_credentials.json").
314
- should have_been_made
315
- a_get("/1/lists/members.json").
316
- with(:query => {:cursor => "-1", :include_entities => "false", :owner_screen_name => "sferik", :skip_status => "true", :slug => "presidents"}).
317
- should have_been_made
318
- end
319
- it "should have the correct output" do
320
- @t.list("remove", "members", "presidents")
321
- $stdout.string.chomp.should == "The list \"presidents\" doesn't have any members."
322
- end
323
- end
324
- context "one user" do
325
- before do
326
- stub_get("/1/lists/members.json").
327
- with(:query => {:cursor => "-1", :include_entities => "false", :owner_screen_name => "sferik", :skip_status => "true", :slug => "presidents"}).
328
- to_return(:body => fixture("users_list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
329
- end
330
- it "should request the correct resource" do
331
- stub_post("/1/lists/members/destroy_all.json").
332
- with(:body => {:user_id => "7505382", :slug => "presidents", :owner_screen_name => "sferik"}).
333
- to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
334
- $stdout.should_receive(:print).with("Are you sure you want to remove 1 member from the list \"presidents\"? ")
335
- $stdin.should_receive(:gets).and_return("yes")
336
- @t.list("remove", "members", "presidents")
337
- a_get("/1/account/verify_credentials.json").
338
- should have_been_made
339
- a_get("/1/lists/members.json").
340
- with(:query => {:cursor => "-1", :include_entities => "false", :owner_screen_name => "sferik", :skip_status => "true", :slug => "presidents"}).
341
- should have_been_made
342
- a_post("/1/lists/members/destroy_all.json").
343
- with(:body => {:user_id => "7505382", :slug => "presidents", :owner_screen_name => "sferik"}).
344
- should have_been_made
345
- end
346
- context "yes" do
347
- it "should have the correct output" do
348
- stub_post("/1/lists/members/destroy_all.json").
349
- with(:body => {:user_id => "7505382", :slug => "presidents", :owner_screen_name => "sferik"}).
350
- to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
351
- $stdout.should_receive(:print).with("Are you sure you want to remove 1 member from the list \"presidents\"? ")
352
- $stdin.should_receive(:gets).and_return("yes")
353
- @t.list("remove", "members", "presidents")
354
- $stdout.string.should =~ /@testcli removed 1 member from the list "presidents"\./
355
- end
356
- context "Twitter is down" do
357
- it "should retry 3 times and then raise an error" do
358
- stub_post("/1/lists/members/destroy_all.json").
359
- with(:body => {:user_id => "7505382", :slug => "presidents", :owner_screen_name => "sferik"}).
360
- to_return(:status => 502)
361
- $stdout.should_receive(:print).with("Are you sure you want to remove 1 member from the list \"presidents\"? ")
362
- $stdin.should_receive(:gets).and_return("yes")
363
- lambda do
364
- @t.list("remove", "members", "presidents")
365
- end.should raise_error("Twitter is down or being upgraded.")
366
- a_post("/1/lists/members/destroy_all.json").
367
- with(:body => {:user_id => "7505382", :slug => "presidents", :owner_screen_name => "sferik"}).
368
- should have_been_made.times(3)
369
- end
370
- end
371
- end
372
- context "no" do
373
- it "should have the correct output" do
374
- $stdout.should_receive(:print).with("Are you sure you want to remove 1 member from the list \"presidents\"? ")
375
- $stdin.should_receive(:gets).and_return("no")
376
- @t.list("remove", "members", "presidents")
377
- $stdout.string.chomp.should == ""
378
- end
379
- end
380
- end
381
- end
382
-
383
- describe "#users" do
384
- before do
385
- @t.options = @t.options.merge(:profile => fixture_path + "/.trc")
386
- stub_get("/1/account/verify_credentials.json").
387
- to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
388
- end
389
- it "should request the correct resource" do
390
- stub_post("/1/lists/members/destroy_all.json").
391
- with(:body => {:screen_name => "sferik", :slug => "presidents", :owner_screen_name => "sferik"}).
392
- to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
393
- @t.list("remove", "users", "presidents", "sferik")
394
- a_get("/1/account/verify_credentials.json").
395
- should have_been_made
396
- a_post("/1/lists/members/destroy_all.json").
397
- with(:body => {:screen_name => "sferik", :slug => "presidents", :owner_screen_name => "sferik"}).
398
- should have_been_made
399
- end
400
- it "should have the correct output" do
401
- stub_post("/1/lists/members/destroy_all.json").
402
- with(:body => {:screen_name => "sferik", :slug => "presidents", :owner_screen_name => "sferik"}).
403
- to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
404
- @t.list("remove", "users", "presidents", "sferik")
405
- $stdout.string.should =~ /@testcli removed 1 user from the list "presidents"\./
406
- end
407
- context "Twitter is down" do
408
- it "should retry 3 times and then raise an error" do
409
- stub_post("/1/lists/members/destroy_all.json").
410
- with(:body => {:screen_name => "sferik", :slug => "presidents", :owner_screen_name => "sferik"}).
411
- to_return(:status => 502)
412
- lambda do
413
- @t.list("remove", "users", "presidents", "sferik")
414
- end.should raise_error("Twitter is down or being upgraded.")
415
- a_post("/1/lists/members/destroy_all.json").
416
- with(:body => {:screen_name => "sferik", :slug => "presidents", :owner_screen_name => "sferik"}).
417
- should have_been_made.times(3)
418
- end
419
- end
420
- end
421
-
422
- end
@@ -1,410 +0,0 @@
1
- # encoding: utf-8
2
- require 'helper'
3
-
4
- describe T::CLI::Unfollow do
5
-
6
- before do
7
- rcfile = RCFile.instance
8
- rcfile.path = fixture_path + "/.trc"
9
- @t = T::CLI.new
10
- @old_stderr = $stderr
11
- $stderr = StringIO.new
12
- @old_stdout = $stdout
13
- $stdout = StringIO.new
14
- end
15
-
16
- after do
17
- $stderr = @old_stderr
18
- $stdout = @old_stdout
19
- end
20
-
21
- describe "#listed" do
22
- before do
23
- @t.options = @t.options.merge(:profile => fixture_path + "/.trc")
24
- stub_get("/1/account/verify_credentials.json").
25
- to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
26
- end
27
- context "no users" do
28
- before do
29
- stub_get("/1/lists/members.json").
30
- with(:query => {:cursor => "-1", :include_entities => "false", :owner_screen_name => "sferik", :skip_status => "true", :slug => "presidents"}).
31
- to_return(:body => fixture("empty_cursor.json"), :headers => {:content_type => "application/json; charset=utf-8"})
32
- end
33
- it "should request the correct resource" do
34
- @t.unfollow("listed", "presidents")
35
- a_get("/1/account/verify_credentials.json").
36
- should have_been_made
37
- a_get("/1/lists/members.json").
38
- with(:query => {:cursor => "-1", :include_entities => "false", :owner_screen_name => "sferik", :skip_status => "true", :slug => "presidents"}).
39
- should have_been_made
40
- end
41
- it "should have the correct output" do
42
- @t.unfollow("listed", "presidents")
43
- $stdout.string.chomp.should == "@testcli is already not following any list members."
44
- end
45
- end
46
- context "one user" do
47
- before do
48
- @t.options = @t.options.merge(:profile => fixture_path + "/.trc")
49
- stub_get("/1/lists/members.json").
50
- with(:query => {:cursor => "-1", :include_entities => "false", :owner_screen_name => "sferik", :skip_status => "true", :slug => "presidents"}).
51
- to_return(:body => fixture("users_list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
52
- end
53
- it "should request the correct resource" do
54
- stub_delete("/1/friendships/destroy.json").
55
- with(:query => {:user_id => "7505382", :include_entities => "false"}).
56
- to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
57
- $stdout.should_receive(:print).with("Are you sure you want to unfollow 1 user? ")
58
- $stdin.should_receive(:gets).and_return("yes")
59
- @t.unfollow("listed", "presidents")
60
- a_get("/1/account/verify_credentials.json").
61
- should have_been_made
62
- a_get("/1/lists/members.json").
63
- with(:query => {:cursor => "-1", :include_entities => "false", :owner_screen_name => "sferik", :skip_status => "true", :slug => "presidents"}).
64
- should have_been_made
65
- a_delete("/1/friendships/destroy.json").
66
- with(:query => {:user_id => "7505382", :include_entities => "false"}).
67
- should have_been_made
68
- end
69
- context "yes" do
70
- it "should have the correct output" do
71
- stub_delete("/1/friendships/destroy.json").
72
- with(:query => {:user_id => "7505382", :include_entities => "false"}).
73
- to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
74
- $stdout.should_receive(:print).with("Are you sure you want to unfollow 1 user? ")
75
- $stdin.should_receive(:gets).and_return("yes")
76
- @t.unfollow("listed", "presidents")
77
- $stdout.string.should =~ /^@testcli is no longer following 1 user\.$/
78
- end
79
- end
80
- context "no" do
81
- it "should have the correct output" do
82
- $stdout.should_receive(:print).with("Are you sure you want to unfollow 1 user? ")
83
- $stdin.should_receive(:gets).and_return("no")
84
- @t.unfollow("listed", "presidents")
85
- $stdout.string.chomp.should == ""
86
- end
87
- end
88
- context "Twitter is down" do
89
- it "should retry 3 times and then raise an error" do
90
- stub_delete("/1/friendships/destroy.json").
91
- with(:query => {:user_id => "7505382", :include_entities => "false"}).
92
- to_return(:status => 502)
93
- $stdout.should_receive(:print).with("Are you sure you want to unfollow 1 user? ")
94
- $stdin.should_receive(:gets).and_return("yes")
95
- lambda do
96
- @t.unfollow("listed", "presidents")
97
- end.should raise_error("Twitter is down or being upgraded.")
98
- a_delete("/1/friendships/destroy.json").
99
- with(:query => {:user_id => "7505382", :include_entities => "false"}).
100
- should have_been_made.times(3)
101
- end
102
- end
103
- end
104
- end
105
-
106
- describe "#followers" do
107
- before do
108
- @t.options = @t.options.merge(:profile => fixture_path + "/.trc")
109
- end
110
- context "no followers" do
111
- before do
112
- stub_get("/1/followers/ids.json").
113
- with(:query => {:cursor => "-1"}).
114
- to_return(:body => fixture("friends_ids.json"), :headers => {:content_type => "application/json; charset=utf-8"})
115
- stub_get("/1/friends/ids.json").
116
- with(:query => {:cursor => "-1"}).
117
- to_return(:body => fixture("friends_ids.json"), :headers => {:content_type => "application/json; charset=utf-8"})
118
- end
119
- it "should request the correct resource" do
120
- @t.unfollow("followers")
121
- a_get("/1/followers/ids.json").
122
- with(:query => {:cursor => "-1"}).
123
- should have_been_made
124
- a_get("/1/friends/ids.json").
125
- with(:query => {:cursor => "-1"}).
126
- should have_been_made
127
- end
128
- it "should have the correct output" do
129
- @t.unfollow("followers")
130
- $stdout.string.chomp.should == "@testcli is already not following any followers."
131
- end
132
- end
133
- context "one follower" do
134
- before do
135
- stub_get("/1/followers/ids.json").
136
- with(:query => {:cursor => "-1"}).
137
- to_return(:body => fixture("friends_ids.json"), :headers => {:content_type => "application/json; charset=utf-8"})
138
- stub_get("/1/friends/ids.json").
139
- with(:query => {:cursor => "-1"}).
140
- to_return(:body => fixture("followers_ids.json"), :headers => {:content_type => "application/json; charset=utf-8"})
141
- end
142
- it "should request the correct resource" do
143
- stub_delete("/1/friendships/destroy.json").
144
- with(:query => {:user_id => "7505382", :include_entities => "false"}).
145
- to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
146
- $stdout.should_receive(:print).with("Are you sure you want to unfollow 1 user? ")
147
- $stdin.should_receive(:gets).and_return("yes")
148
- @t.unfollow("followers")
149
- a_get("/1/followers/ids.json").
150
- with(:query => {:cursor => "-1"}).
151
- should have_been_made
152
- a_get("/1/friends/ids.json").
153
- with(:query => {:cursor => "-1"}).
154
- should have_been_made
155
- a_delete("/1/friendships/destroy.json").
156
- with(:query => {:user_id => "7505382", :include_entities => "false"}).
157
- should have_been_made
158
- end
159
- context "yes" do
160
- it "should have the correct output" do
161
- stub_delete("/1/friendships/destroy.json").
162
- with(:query => {:user_id => "7505382", :include_entities => "false"}).
163
- to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
164
- $stdout.should_receive(:print).with("Are you sure you want to unfollow 1 user? ")
165
- $stdin.should_receive(:gets).and_return("yes")
166
- @t.unfollow("followers")
167
- $stdout.string.should =~ /^@testcli is no longer following 1 user\.$/
168
- end
169
- end
170
- context "no" do
171
- it "should have the correct output" do
172
- $stdout.should_receive(:print).with("Are you sure you want to unfollow 1 user? ")
173
- $stdin.should_receive(:gets).and_return("no")
174
- @t.unfollow("followers")
175
- $stdout.string.chomp.should == ""
176
- end
177
- end
178
- context "Twitter is down" do
179
- it "should retry 3 times and then raise an error" do
180
- stub_delete("/1/friendships/destroy.json").
181
- with(:query => {:user_id => "7505382", :include_entities => "false"}).
182
- to_return(:status => 502)
183
- $stdout.should_receive(:print).with("Are you sure you want to unfollow 1 user? ")
184
- $stdin.should_receive(:gets).and_return("yes")
185
- lambda do
186
- @t.unfollow("followers")
187
- end.should raise_error("Twitter is down or being upgraded.")
188
- a_delete("/1/friendships/destroy.json").
189
- with(:query => {:user_id => "7505382", :include_entities => "false"}).
190
- should have_been_made.times(3)
191
- end
192
- end
193
- end
194
- end
195
-
196
- describe "#friends" do
197
- before do
198
- @t.options = @t.options.merge(:profile => fixture_path + "/.trc")
199
- end
200
- context "no friends" do
201
- before do
202
- stub_get("/1/friends/ids.json").
203
- with(:query => {:cursor => "-1"}).
204
- to_return(:body => fixture("empty_cursor.json"), :headers => {:content_type => "application/json; charset=utf-8"})
205
- end
206
- it "should request the correct resource" do
207
- @t.unfollow("friends")
208
- a_get("/1/friends/ids.json").
209
- with(:query => {:cursor => "-1"}).
210
- should have_been_made
211
- end
212
- it "should have the correct output" do
213
- @t.unfollow("friends")
214
- $stdout.string.chomp.should == "@testcli is already not following anyone."
215
- end
216
- end
217
- context "four friends" do
218
- before do
219
- @t.options = @t.options.merge(:profile => fixture_path + "/.trc")
220
- stub_get("/1/friends/ids.json").
221
- with(:query => {:cursor => "-1"}).
222
- to_return(:body => fixture("friends_ids.json"), :headers => {:content_type => "application/json; charset=utf-8"})
223
- end
224
- it "should request the correct resource" do
225
- stub_delete("/1/friendships/destroy.json").
226
- with(:query => {:user_id => "7505382", :include_entities => "false"}).
227
- to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
228
- $stdout.should_receive(:print).with("Are you sure you want to unfollow 1 user? ")
229
- $stdin.should_receive(:gets).and_return("yes")
230
- @t.unfollow("friends")
231
- a_get("/1/friends/ids.json").
232
- with(:query => {:cursor => "-1"}).
233
- should have_been_made
234
- a_delete("/1/friendships/destroy.json").
235
- with(:query => {:user_id => "7505382", :include_entities => "false"}).
236
- should have_been_made
237
- end
238
- context "yes" do
239
- it "should have the correct output" do
240
- stub_delete("/1/friendships/destroy.json").
241
- with(:query => {:user_id => "7505382", :include_entities => "false"}).
242
- to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
243
- $stdout.should_receive(:print).with("Are you sure you want to unfollow 1 user? ")
244
- $stdin.should_receive(:gets).and_return("yes")
245
- @t.unfollow("friends")
246
- $stdout.string.should =~ /^@testcli is no longer following 1 user\.$/
247
- end
248
- end
249
- context "no" do
250
- it "should have the correct output" do
251
- $stdout.should_receive(:print).with("Are you sure you want to unfollow 1 user? ")
252
- $stdin.should_receive(:gets).and_return("no")
253
- @t.unfollow("friends")
254
- $stdout.string.chomp.should == ""
255
- end
256
- end
257
- context "Twitter is down" do
258
- it "should retry 3 times and then raise an error" do
259
- stub_delete("/1/friendships/destroy.json").
260
- with(:query => {:user_id => "7505382", :include_entities => "false"}).
261
- to_return(:status => 502)
262
- $stdout.should_receive(:print).with("Are you sure you want to unfollow 1 user? ")
263
- $stdin.should_receive(:gets).and_return("yes")
264
- lambda do
265
- @t.unfollow("friends")
266
- end.should raise_error("Twitter is down or being upgraded.")
267
- a_delete("/1/friendships/destroy.json").
268
- with(:query => {:user_id => "7505382", :include_entities => "false"}).
269
- should have_been_made.times(3)
270
- end
271
- end
272
- end
273
- end
274
-
275
- describe "#nonfollowers" do
276
- before do
277
- @t.options = @t.options.merge(:profile => fixture_path + "/.trc")
278
- end
279
- context "no users" do
280
- before do
281
- stub_get("/1/friends/ids.json").
282
- with(:query => {:cursor => "-1"}).
283
- to_return(:body => fixture("friends_ids.json"), :headers => {:content_type => "application/json; charset=utf-8"})
284
- stub_get("/1/followers/ids.json").
285
- with(:query => {:cursor => "-1"}).
286
- to_return(:body => fixture("friends_ids.json"), :headers => {:content_type => "application/json; charset=utf-8"})
287
- end
288
- it "should request the correct resource" do
289
- @t.unfollow("nonfollowers")
290
- a_get("/1/friends/ids.json").
291
- with(:query => {:cursor => "-1"}).
292
- should have_been_made
293
- a_get("/1/followers/ids.json").
294
- with(:query => {:cursor => "-1"}).
295
- should have_been_made
296
- end
297
- it "should have the correct output" do
298
- @t.unfollow("nonfollowers")
299
- $stdout.string.chomp.should == "@testcli is already not following any non-followers."
300
- end
301
- end
302
- context "one user" do
303
- before do
304
- @t.options = @t.options.merge(:profile => fixture_path + "/.trc")
305
- stub_get("/1/friends/ids.json").
306
- with(:query => {:cursor => "-1"}).
307
- to_return(:body => fixture("friends_ids.json"), :headers => {:content_type => "application/json; charset=utf-8"})
308
- stub_get("/1/followers/ids.json").
309
- with(:query => {:cursor => "-1"}).
310
- to_return(:body => fixture("followers_ids.json"), :headers => {:content_type => "application/json; charset=utf-8"})
311
- end
312
- it "should request the correct resource" do
313
- stub_delete("/1/friendships/destroy.json").
314
- with(:query => {:user_id => "7505382", :include_entities => "false"}).
315
- to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
316
- $stdout.should_receive(:print).with("Are you sure you want to unfollow 1 user? ")
317
- $stdin.should_receive(:gets).and_return("yes")
318
- @t.unfollow("nonfollowers")
319
- a_get("/1/friends/ids.json").
320
- with(:query => {:cursor => "-1"}).
321
- should have_been_made
322
- a_get("/1/followers/ids.json").
323
- with(:query => {:cursor => "-1"}).
324
- should have_been_made
325
- a_delete("/1/friendships/destroy.json").
326
- with(:query => {:user_id => "7505382", :include_entities => "false"}).
327
- should have_been_made
328
- end
329
- context "yes" do
330
- it "should have the correct output" do
331
- stub_delete("/1/friendships/destroy.json").
332
- with(:query => {:user_id => "7505382", :include_entities => "false"}).
333
- to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
334
- $stdout.should_receive(:print).with("Are you sure you want to unfollow 1 user? ")
335
- $stdin.should_receive(:gets).and_return("yes")
336
- @t.unfollow("nonfollowers")
337
- $stdout.string.should =~ /^@testcli is no longer following 1 user\.$/
338
- end
339
- end
340
- context "no" do
341
- it "should have the correct output" do
342
- $stdout.should_receive(:print).with("Are you sure you want to unfollow 1 user? ")
343
- $stdin.should_receive(:gets).and_return("no")
344
- @t.unfollow("nonfollowers")
345
- $stdout.string.chomp.should == ""
346
- end
347
- end
348
- context "Twitter is down" do
349
- it "should retry 3 times and then raise an error" do
350
- stub_delete("/1/friendships/destroy.json").
351
- with(:query => {:user_id => "7505382", :include_entities => "false"}).
352
- to_return(:status => 502)
353
- $stdout.should_receive(:print).with("Are you sure you want to unfollow 1 user? ")
354
- $stdin.should_receive(:gets).and_return("yes")
355
- lambda do
356
- @t.unfollow("nonfollowers")
357
- end.should raise_error("Twitter is down or being upgraded.")
358
- a_delete("/1/friendships/destroy.json").
359
- with(:query => {:user_id => "7505382", :include_entities => "false"}).
360
- should have_been_made.times(3)
361
- end
362
- end
363
- end
364
- end
365
-
366
- describe "#users" do
367
- before do
368
- @t.options = @t.options.merge(:profile => fixture_path + "/.trc")
369
- end
370
- context "no users" do
371
- it "should exit" do
372
- lambda do
373
- @t.follow("users")
374
- end.should raise_error
375
- end
376
- end
377
- context "one user" do
378
- it "should request the correct resource" do
379
- stub_delete("/1/friendships/destroy.json").
380
- with(:query => {:screen_name => "sferik", :include_entities => "false"}).
381
- to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
382
- @t.unfollow("users", "sferik")
383
- a_delete("/1/friendships/destroy.json").
384
- with(:query => {:screen_name => "sferik", :include_entities => "false"}).
385
- should have_been_made
386
- end
387
- it "should have the correct output" do
388
- stub_delete("/1/friendships/destroy.json").
389
- with(:query => {:screen_name => "sferik", :include_entities => "false"}).
390
- to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
391
- @t.unfollow("users", "sferik")
392
- $stdout.string.should =~ /^@testcli is no longer following 1 user\.$/
393
- end
394
- context "Twitter is down" do
395
- it "should retry 3 times and then raise an error" do
396
- stub_delete("/1/friendships/destroy.json").
397
- with(:query => {:screen_name => "sferik", :include_entities => "false"}).
398
- to_return(:status => 502)
399
- lambda do
400
- @t.unfollow("users", "sferik")
401
- end.should raise_error("Twitter is down or being upgraded.")
402
- a_delete("/1/friendships/destroy.json").
403
- with(:query => {:screen_name => "sferik", :include_entities => "false"}).
404
- should have_been_made.times(3)
405
- end
406
- end
407
- end
408
- end
409
-
410
- end