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,518 +0,0 @@
1
- # encoding: utf-8
2
- require 'helper'
3
-
4
- describe T::CLI::List::Add 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("add", "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("add", "friends", "presidents")
44
- $stdout.string.chomp.should == "All of @testcli's friends are already 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
- stub_post("/1/lists/members/create_all.json").
56
- with(:body => {:user_id => "7505382", :slug => "presidents", :owner_screen_name => "sferik"}).
57
- to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
58
- end
59
- it "should request the correct resource" do
60
- $stdout.should_receive(:print).with("Are you sure you want to add 1 friend to the list \"presidents\"? ")
61
- $stdin.should_receive(:gets).and_return("yes")
62
- @t.list("add", "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/create_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
- $stdout.should_receive(:print).with("Are you sure you want to add 1 friend to the list \"presidents\"? ")
78
- $stdin.should_receive(:gets).and_return("yes")
79
- @t.list("add", "friends", "presidents")
80
- $stdout.string.should =~ /@testcli added 1 friend to the list "presidents"\./
81
- end
82
- context "Twitter is down" do
83
- it "should retry 3 times and then raise an error" do
84
- stub_post("/1/lists/members/create_all.json").
85
- with(:body => {:user_id => "7505382", :slug => "presidents", :owner_screen_name => "sferik"}).
86
- to_return(:status => 502)
87
- $stdout.should_receive(:print).with("Are you sure you want to add 1 friend to the list \"presidents\"? ")
88
- $stdin.should_receive(:gets).and_return("yes")
89
- lambda do
90
- @t.list("add", "friends", "presidents")
91
- end.should raise_error("Twitter is down or being upgraded.")
92
- a_post("/1/lists/members/create_all.json").
93
- with(:body => {:user_id => "7505382", :slug => "presidents", :owner_screen_name => "sferik"}).
94
- should have_been_made.times(3)
95
- end
96
- end
97
- end
98
- context "no" do
99
- it "should have the correct output" do
100
- $stdout.should_receive(:print).with("Are you sure you want to add 1 friend to the list \"presidents\"? ")
101
- $stdin.should_receive(:gets).and_return("no")
102
- @t.list("add", "friends", "presidents")
103
- $stdout.string.chomp.should == ""
104
- end
105
- end
106
- end
107
- context "501 users" do
108
- before do
109
- stub_get("/1/lists/members.json").
110
- with(:query => {:cursor => "-1", :include_entities => "false", :owner_screen_name => "sferik", :skip_status => "true", :slug => "presidents"}).
111
- to_return(:body => fixture("empty_cursor.json"), :headers => {:content_type => "application/json; charset=utf-8"})
112
- stub_get("/1/friends/ids.json").
113
- with(:query => {:cursor => "-1"}).
114
- to_return(:body => fixture("501_ids.json"), :headers => {:content_type => "application/json; charset=utf-8"})
115
- stub_post("/1/lists/members/create_all.json").
116
- with(:body => {:user_id => "7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382", :slug => "presidents", :owner_screen_name => "sferik"}).
117
- to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
118
- end
119
- it "should request the correct resource" do
120
- $stdout.should_receive(:print).with("Lists can't have more than 500 members. Do you want to add up to 500 friends to the list \"presidents\"? ")
121
- $stdin.should_receive(:gets).and_return("yes")
122
- @t.list("add", "friends", "presidents")
123
- a_get("/1/account/verify_credentials.json").
124
- should have_been_made
125
- a_get("/1/lists/members.json").
126
- with(:query => {:cursor => "-1", :include_entities => "false", :owner_screen_name => "sferik", :skip_status => "true", :slug => "presidents"}).
127
- should have_been_made
128
- a_get("/1/friends/ids.json").
129
- with(:query => {:cursor => "-1"}).
130
- should have_been_made
131
- a_post("/1/lists/members/create_all.json").
132
- with(:body => {:user_id => "7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382", :slug => "presidents", :owner_screen_name => "sferik"}).
133
- should have_been_made.times(5)
134
- end
135
- context "yes" do
136
- it "should have the correct output" do
137
- $stdout.should_receive(:print).with("Lists can't have more than 500 members. Do you want to add up to 500 friends to the list \"presidents\"? ")
138
- $stdin.should_receive(:gets).and_return("yes")
139
- @t.list("add", "friends", "presidents")
140
- $stdout.string.should =~ /@testcli added 500 friends to the list "presidents"\./
141
- end
142
- end
143
- context "no" do
144
- it "should have the correct output" do
145
- $stdout.should_receive(:print).with("Lists can't have more than 500 members. Do you want to add up to 500 friends to the list \"presidents\"? ")
146
- $stdin.should_receive(:gets).and_return("no")
147
- @t.list("add", "friends", "presidents")
148
- $stdout.string.chomp.should == ""
149
- end
150
- end
151
- end
152
- context "500 list members" do
153
- before do
154
- stub_get("/1/lists/members.json").
155
- with(:query => {:cursor => "-1", :include_entities => "false", :owner_screen_name => "sferik", :skip_status => "true", :slug => "presidents"}).
156
- to_return(:body => fixture("501_users_list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
157
- end
158
- it "should request the correct resource" do
159
- @t.list("add", "friends", "presidents")
160
- a_get("/1/account/verify_credentials.json").
161
- should have_been_made
162
- a_get("/1/lists/members.json").
163
- with(:query => {:cursor => "-1", :include_entities => "false", :owner_screen_name => "sferik", :skip_status => "true", :slug => "presidents"}).
164
- should have_been_made
165
- end
166
- it "should have the correct output" do
167
- @t.list("add", "friends", "presidents")
168
- $stdout.string.chomp.should == "The list \"presidents\" are already contains the maximum of 500 members."
169
- end
170
- end
171
- end
172
-
173
- describe "#followers" do
174
- before do
175
- @t.options = @t.options.merge(:profile => fixture_path + "/.trc")
176
- stub_get("/1/account/verify_credentials.json").
177
- to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
178
- end
179
- context "no followers" do
180
- before do
181
- stub_get("/1/lists/members.json").
182
- with(:query => {:cursor => "-1", :include_entities => "false", :owner_screen_name => "sferik", :skip_status => "true", :slug => "presidents"}).
183
- to_return(:body => fixture("empty_cursor.json"), :headers => {:content_type => "application/json; charset=utf-8"})
184
- stub_get("/1/followers/ids.json").
185
- with(:query => {:cursor => "-1"}).
186
- to_return(:body => fixture("empty_cursor.json"), :headers => {:content_type => "application/json; charset=utf-8"})
187
- end
188
- it "should request the correct resource" do
189
- @t.list("add", "followers", "presidents")
190
- a_get("/1/followers/ids.json").
191
- with(:query => {:cursor => "-1"}).
192
- should have_been_made
193
- end
194
- it "should have the correct output" do
195
- @t.list("add", "followers", "presidents")
196
- $stdout.string.chomp.should == "All of @testcli's followers are already members of the list \"presidents\"."
197
- end
198
- end
199
- context "two followers" do
200
- before do
201
- stub_get("/1/lists/members.json").
202
- with(:query => {:cursor => "-1", :include_entities => "false", :owner_screen_name => "sferik", :skip_status => "true", :slug => "presidents"}).
203
- to_return(:body => fixture("empty_cursor.json"), :headers => {:content_type => "application/json; charset=utf-8"})
204
- stub_get("/1/followers/ids.json").
205
- with(:query => {:cursor => "-1"}).
206
- to_return(:body => fixture("followers_ids.json"), :headers => {:content_type => "application/json; charset=utf-8"})
207
- stub_post("/1/lists/members/create_all.json").
208
- with(:body => {:user_id => "213747670,428004849", :slug => "presidents", :owner_screen_name => "sferik"}).
209
- to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
210
- end
211
- it "should request the correct resource" do
212
- $stdout.should_receive(:print).with("Are you sure you want to add 2 followers to the list \"presidents\"? ")
213
- $stdin.should_receive(:gets).and_return("yes")
214
- @t.list("add", "followers", "presidents")
215
- a_get("/1/account/verify_credentials.json").
216
- should have_been_made
217
- a_get("/1/lists/members.json").
218
- with(:query => {:cursor => "-1", :include_entities => "false", :owner_screen_name => "sferik", :skip_status => "true", :slug => "presidents"}).
219
- should have_been_made
220
- a_get("/1/followers/ids.json").
221
- with(:query => {:cursor => "-1"}).
222
- should have_been_made
223
- a_post("/1/lists/members/create_all.json").
224
- with(:body => {:user_id => "213747670,428004849", :slug => "presidents", :owner_screen_name => "sferik"}).
225
- should have_been_made
226
- end
227
- context "yes" do
228
- it "should have the correct output" do
229
- $stdout.should_receive(:print).with("Are you sure you want to add 2 followers to the list \"presidents\"? ")
230
- $stdin.should_receive(:gets).and_return("yes")
231
- @t.list("add", "followers", "presidents")
232
- $stdout.string.should =~ /@testcli added 2 followers to the list "presidents"\./
233
- end
234
- context "Twitter is down" do
235
- it "should retry 3 times and then raise an error" do
236
- stub_post("/1/lists/members/create_all.json").
237
- with(:body => {:user_id => "213747670,428004849", :slug => "presidents", :owner_screen_name => "sferik"}).
238
- to_return(:status => 502)
239
- $stdout.should_receive(:print).with("Are you sure you want to add 2 followers to the list \"presidents\"? ")
240
- $stdin.should_receive(:gets).and_return("yes")
241
- lambda do
242
- @t.list("add", "followers", "presidents")
243
- end.should raise_error("Twitter is down or being upgraded.")
244
- a_post("/1/lists/members/create_all.json").
245
- with(:body => {:user_id => "213747670,428004849", :slug => "presidents", :owner_screen_name => "sferik"}).
246
- should have_been_made.times(3)
247
- end
248
- end
249
- end
250
- context "no" do
251
- it "should have the correct output" do
252
- $stdout.should_receive(:print).with("Are you sure you want to add 2 followers to the list \"presidents\"? ")
253
- $stdin.should_receive(:gets).and_return("no")
254
- @t.list("add", "followers", "presidents")
255
- $stdout.string.chomp.should == ""
256
- end
257
- end
258
- end
259
- context "501 users" do
260
- before do
261
- stub_get("/1/lists/members.json").
262
- with(:query => {:cursor => "-1", :include_entities => "false", :owner_screen_name => "sferik", :skip_status => "true", :slug => "presidents"}).
263
- to_return(:body => fixture("empty_cursor.json"), :headers => {:content_type => "application/json; charset=utf-8"})
264
- stub_get("/1/followers/ids.json").
265
- with(:query => {:cursor => "-1"}).
266
- to_return(:body => fixture("501_ids.json"), :headers => {:content_type => "application/json; charset=utf-8"})
267
- stub_post("/1/lists/members/create_all.json").
268
- with(:body => {:user_id => "7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382", :slug => "presidents", :owner_screen_name => "sferik"}).
269
- to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
270
- end
271
- it "should request the correct resource" do
272
- $stdout.should_receive(:print).with("Lists can't have more than 500 members. Do you want to add up to 500 followers to the list \"presidents\"? ")
273
- $stdin.should_receive(:gets).and_return("yes")
274
- @t.list("add", "followers", "presidents")
275
- a_get("/1/account/verify_credentials.json").
276
- should have_been_made
277
- a_get("/1/lists/members.json").
278
- with(:query => {:cursor => "-1", :include_entities => "false", :owner_screen_name => "sferik", :skip_status => "true", :slug => "presidents"}).
279
- should have_been_made
280
- a_get("/1/followers/ids.json").
281
- with(:query => {:cursor => "-1"}).
282
- should have_been_made
283
- a_post("/1/lists/members/create_all.json").
284
- with(:body => {:user_id => "7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382", :slug => "presidents", :owner_screen_name => "sferik"}).
285
- should have_been_made.times(5)
286
- end
287
- context "yes" do
288
- it "should have the correct output" do
289
- $stdout.should_receive(:print).with("Lists can't have more than 500 members. Do you want to add up to 500 followers to the list \"presidents\"? ")
290
- $stdin.should_receive(:gets).and_return("yes")
291
- @t.list("add", "followers", "presidents")
292
- $stdout.string.should =~ /@testcli added 500 followers to the list "presidents"\./
293
- end
294
- end
295
- context "no" do
296
- it "should have the correct output" do
297
- $stdout.should_receive(:print).with("Lists can't have more than 500 members. Do you want to add up to 500 followers to the list \"presidents\"? ")
298
- $stdin.should_receive(:gets).and_return("no")
299
- @t.list("add", "followers", "presidents")
300
- $stdout.string.chomp.should == ""
301
- end
302
- end
303
- end
304
- context "500 list members" do
305
- before do
306
- stub_get("/1/lists/members.json").
307
- with(:query => {:cursor => "-1", :include_entities => "false", :owner_screen_name => "sferik", :skip_status => "true", :slug => "presidents"}).
308
- to_return(:body => fixture("501_users_list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
309
- end
310
- it "should request the correct resource" do
311
- @t.list("add", "followers", "presidents")
312
- a_get("/1/account/verify_credentials.json").
313
- should have_been_made
314
- a_get("/1/lists/members.json").
315
- with(:query => {:cursor => "-1", :include_entities => "false", :owner_screen_name => "sferik", :skip_status => "true", :slug => "presidents"}).
316
- should have_been_made
317
- end
318
- it "should have the correct output" do
319
- @t.list("add", "followers", "presidents")
320
- $stdout.string.chomp.should == "The list \"presidents\" are already contains the maximum of 500 members."
321
- end
322
- end
323
- end
324
-
325
- describe "#listed" do
326
- before do
327
- @t.options = @t.options.merge(:profile => fixture_path + "/.trc")
328
- stub_get("/1/account/verify_credentials.json").
329
- to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
330
- end
331
- context "no users" do
332
- before do
333
- stub_get("/1/lists/members.json").
334
- with(:query => {:cursor => "-1", :include_entities => "false", :owner_screen_name => "sferik", :skip_status => "true", :slug => "presidents"}).
335
- to_return(:body => fixture("empty_cursor.json"), :headers => {:content_type => "application/json; charset=utf-8"})
336
- stub_get("/1/lists/members.json").
337
- with(:query => {:cursor => "-1", :include_entities => "false", :owner_screen_name => "sferik", :skip_status => "true", :slug => "democrats"}).
338
- to_return(:body => fixture("empty_cursor.json"), :headers => {:content_type => "application/json; charset=utf-8"})
339
- end
340
- it "should request the correct resource" do
341
- @t.list("add", "listed", "democrats", "presidents")
342
- a_get("/1/account/verify_credentials.json").
343
- should have_been_made
344
- a_get("/1/lists/members.json").
345
- with(:query => {:cursor => "-1", :include_entities => "false", :owner_screen_name => "sferik", :skip_status => "true", :slug => "presidents"}).
346
- should have_been_made
347
- a_get("/1/lists/members.json").
348
- with(:query => {:cursor => "-1", :include_entities => "false", :owner_screen_name => "sferik", :skip_status => "true", :slug => "democrats"}).
349
- should have_been_made
350
- end
351
- it "should have the correct output" do
352
- @t.list("add", "listed", "democrats", "presidents")
353
- $stdout.string.chomp.should == "All of the members of the list \"democrats\" are already members of the list \"presidents\"."
354
- end
355
- end
356
- context "one user" do
357
- before do
358
- stub_get("/1/lists/members.json").
359
- with(:query => {:cursor => "-1", :include_entities => "false", :owner_screen_name => "sferik", :skip_status => "true", :slug => "presidents"}).
360
- to_return(:body => fixture("empty_cursor.json"), :headers => {:content_type => "application/json; charset=utf-8"})
361
- stub_get("/1/lists/members.json").
362
- with(:query => {:cursor => "-1", :include_entities => "false", :owner_screen_name => "sferik", :skip_status => "true", :slug => "democrats"}).
363
- to_return(:body => fixture("users_list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
364
- stub_post("/1/lists/members/create_all.json").
365
- with(:body => {:user_id => "7505382", :slug => "presidents", :owner_screen_name => "sferik"}).
366
- to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
367
- end
368
- it "should request the correct resource" do
369
- $stdout.should_receive(:print).with("Are you sure you want to add 1 member to the list \"presidents\"? ")
370
- $stdin.should_receive(:gets).and_return("yes")
371
- @t.list("add", "listed", "democrats", "presidents")
372
- a_get("/1/account/verify_credentials.json").
373
- should have_been_made
374
- a_get("/1/lists/members.json").
375
- with(:query => {:cursor => "-1", :include_entities => "false", :owner_screen_name => "sferik", :skip_status => "true", :slug => "presidents"}).
376
- should have_been_made
377
- a_get("/1/lists/members.json").
378
- with(:query => {:cursor => "-1", :include_entities => "false", :owner_screen_name => "sferik", :skip_status => "true", :slug => "democrats"}).
379
- should have_been_made
380
- a_post("/1/lists/members/create_all.json").
381
- with(:body => {:user_id => "7505382", :slug => "presidents", :owner_screen_name => "sferik"}).
382
- should have_been_made
383
- end
384
- context "yes" do
385
- it "should have the correct output" do
386
- $stdout.should_receive(:print).with("Are you sure you want to add 1 member to the list \"presidents\"? ")
387
- $stdin.should_receive(:gets).and_return("yes")
388
- @t.list("add", "listed", "democrats", "presidents")
389
- $stdout.string.should =~ /@testcli added 1 member to the list "presidents"\./
390
- end
391
- context "Twitter is down" do
392
- it "should retry 3 times and then raise an error" do
393
- stub_post("/1/lists/members/create_all.json").
394
- with(:body => {:user_id => "7505382", :slug => "presidents", :owner_screen_name => "sferik"}).
395
- to_return(:status => 502)
396
- $stdout.should_receive(:print).with("Are you sure you want to add 1 member to the list \"presidents\"? ")
397
- $stdin.should_receive(:gets).and_return("yes")
398
- lambda do
399
- @t.list("add", "listed", "democrats", "presidents")
400
- end.should raise_error("Twitter is down or being upgraded.")
401
- a_post("/1/lists/members/create_all.json").
402
- with(:body => {:user_id => "7505382", :slug => "presidents", :owner_screen_name => "sferik"}).
403
- should have_been_made.times(3)
404
- end
405
- end
406
- end
407
- context "no" do
408
- it "should have the correct output" do
409
- $stdout.should_receive(:print).with("Are you sure you want to add 1 member to the list \"presidents\"? ")
410
- $stdin.should_receive(:gets).and_return("no")
411
- @t.list("add", "listed", "democrats", "presidents")
412
- $stdout.string.chomp.should == ""
413
- end
414
- end
415
- end
416
- context "501 users" do
417
- before do
418
- stub_get("/1/lists/members.json").
419
- with(:query => {:cursor => "-1", :include_entities => "false", :owner_screen_name => "sferik", :skip_status => "true", :slug => "presidents"}).
420
- to_return(:body => fixture("empty_cursor.json"), :headers => {:content_type => "application/json; charset=utf-8"})
421
- stub_get("/1/lists/members.json").
422
- with(:query => {:cursor => "-1", :include_entities => "false", :owner_screen_name => "sferik", :skip_status => "true", :slug => "democrats"}).
423
- to_return(:body => fixture("501_users_list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
424
- stub_post("/1/lists/members/create_all.json").
425
- with(:body => {:user_id => "7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382", :slug => "presidents", :owner_screen_name => "sferik"}).
426
- to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
427
- end
428
- it "should request the correct resource" do
429
- $stdout.should_receive(:print).with("Lists can't have more than 500 members. Do you want to add up to 500 members to the list \"presidents\"? ")
430
- $stdin.should_receive(:gets).and_return("yes")
431
- @t.list("add", "listed", "democrats", "presidents")
432
- a_get("/1/account/verify_credentials.json").
433
- should have_been_made
434
- a_get("/1/lists/members.json").
435
- with(:query => {:cursor => "-1", :include_entities => "false", :owner_screen_name => "sferik", :skip_status => "true", :slug => "presidents"}).
436
- should have_been_made
437
- a_get("/1/lists/members.json").
438
- with(:query => {:cursor => "-1", :include_entities => "false", :owner_screen_name => "sferik", :skip_status => "true", :slug => "democrats"}).
439
- should have_been_made
440
- a_post("/1/lists/members/create_all.json").
441
- with(:body => {:user_id => "7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382,7505382", :slug => "presidents", :owner_screen_name => "sferik"}).
442
- should have_been_made.times(5)
443
- end
444
- context "yes" do
445
- it "should have the correct output" do
446
- $stdout.should_receive(:print).with("Lists can't have more than 500 members. Do you want to add up to 500 members to the list \"presidents\"? ")
447
- $stdin.should_receive(:gets).and_return("yes")
448
- @t.list("add", "listed", "democrats", "presidents")
449
- $stdout.string.should =~ /@testcli added 500 members to the list "presidents"\./
450
- end
451
- end
452
- context "no" do
453
- it "should have the correct output" do
454
- $stdout.should_receive(:print).with("Lists can't have more than 500 members. Do you want to add up to 500 members to the list \"presidents\"? ")
455
- $stdin.should_receive(:gets).and_return("no")
456
- @t.list("add", "listed", "democrats", "presidents")
457
- $stdout.string.chomp.should == ""
458
- end
459
- end
460
- end
461
- context "500 list members" do
462
- before do
463
- stub_get("/1/lists/members.json").
464
- with(:query => {:cursor => "-1", :include_entities => "false", :owner_screen_name => "sferik", :skip_status => "true", :slug => "presidents"}).
465
- to_return(:body => fixture("501_users_list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
466
- end
467
- it "should request the correct resource" do
468
- @t.list("add", "listed", "democrats", "presidents")
469
- a_get("/1/account/verify_credentials.json").
470
- should have_been_made
471
- a_get("/1/lists/members.json").
472
- with(:query => {:cursor => "-1", :include_entities => "false", :owner_screen_name => "sferik", :skip_status => "true", :slug => "presidents"}).
473
- should have_been_made
474
- end
475
- it "should have the correct output" do
476
- @t.list("add", "listed", "democrats", "presidents")
477
- $stdout.string.chomp.should == "The list \"presidents\" are already contains the maximum of 500 members."
478
- end
479
- end
480
- end
481
-
482
- describe "#users" do
483
- before do
484
- @t.options = @t.options.merge(:profile => fixture_path + "/.trc")
485
- stub_get("/1/account/verify_credentials.json").
486
- to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
487
- stub_post("/1/lists/members/create_all.json").
488
- with(:body => {:screen_name => "sferik", :slug => "presidents", :owner_screen_name => "sferik"}).
489
- to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
490
- end
491
- it "should request the correct resource" do
492
- @t.list("add", "users", "presidents", "sferik")
493
- a_get("/1/account/verify_credentials.json").
494
- should have_been_made
495
- a_post("/1/lists/members/create_all.json").
496
- with(:body => {:screen_name => "sferik", :slug => "presidents", :owner_screen_name => "sferik"}).
497
- should have_been_made
498
- end
499
- it "should have the correct output" do
500
- @t.list("add", "users", "presidents", "sferik")
501
- $stdout.string.should =~ /@testcli added 1 user to the list "presidents"\./
502
- end
503
- context "Twitter is down" do
504
- it "should retry 3 times and then raise an error" do
505
- stub_post("/1/lists/members/create_all.json").
506
- with(:body => {:screen_name => "sferik", :slug => "presidents", :owner_screen_name => "sferik"}).
507
- to_return(:status => 502)
508
- lambda do
509
- @t.list("add", "users", "presidents", "sferik")
510
- end.should raise_error("Twitter is down or being upgraded.")
511
- a_post("/1/lists/members/create_all.json").
512
- with(:body => {:screen_name => "sferik", :slug => "presidents", :owner_screen_name => "sferik"}).
513
- should have_been_made.times(3)
514
- end
515
- end
516
- end
517
-
518
- end