tweetwine 0.2.12 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +7 -0
- data/Gemfile +17 -0
- data/README.md +57 -47
- data/Rakefile +17 -26
- data/bin/tweetwine +11 -12
- data/contrib/tweetwine-completion.bash +2 -3
- data/example/application_behavior_example.rb +173 -0
- data/example/example_helper.rb +44 -28
- data/example/fixture/config.yaml +8 -0
- data/example/fixture/shorten_rubygems.html +5 -0
- data/example/fixture/shorten_rubylang.html +5 -0
- data/example/fixture/update_utf8.json +1 -0
- data/example/fixture/update_with_urls.json +1 -0
- data/example/fixture/{update.json → update_without_urls.json} +0 -0
- data/example/search_statuses_example.rb +49 -16
- data/example/show_followers_example.rb +7 -8
- data/example/show_friends_example.rb +7 -8
- data/example/show_home_example.rb +19 -16
- data/example/show_mentions_example.rb +8 -9
- data/example/show_user_example.rb +16 -13
- data/example/update_status_example.rb +143 -26
- data/example/use_http_proxy_example.rb +40 -20
- data/lib/tweetwine/basic_object.rb +19 -0
- data/lib/tweetwine/character_encoding.rb +59 -0
- data/lib/tweetwine/cli.rb +354 -230
- data/lib/tweetwine/config.rb +65 -0
- data/lib/tweetwine/http.rb +120 -0
- data/lib/tweetwine/oauth.rb +104 -0
- data/lib/tweetwine/obfuscate.rb +21 -0
- data/lib/tweetwine/option_parser.rb +31 -0
- data/lib/tweetwine/promise.rb +39 -0
- data/lib/tweetwine/twitter.rb +211 -0
- data/lib/tweetwine/{io.rb → ui.rb} +30 -21
- data/lib/tweetwine/url_shortener.rb +15 -9
- data/lib/tweetwine/util.rb +30 -15
- data/lib/tweetwine.rb +72 -12
- data/man/tweetwine.7 +43 -69
- data/man/tweetwine.7.ronn +57 -47
- data/test/character_encoding_test.rb +87 -0
- data/test/cli_test.rb +19 -6
- data/test/config_test.rb +244 -0
- data/test/fixture/oauth.rb +21 -0
- data/test/fixture/test_config.yaml +4 -4
- data/test/http_test.rb +199 -0
- data/test/oauth_test.rb +77 -0
- data/test/obfuscate_test.rb +16 -0
- data/test/option_parser_test.rb +60 -0
- data/test/promise_test.rb +56 -0
- data/test/test_helper.rb +76 -8
- data/test/twitter_test.rb +625 -0
- data/test/{io_test.rb → ui_test.rb} +92 -74
- data/test/url_shortener_test.rb +115 -135
- data/test/util_test.rb +136 -85
- data/tweetwine.gemspec +53 -0
- metadata +112 -56
- data/example/show_metadata_example.rb +0 -86
- data/lib/tweetwine/client.rb +0 -187
- data/lib/tweetwine/meta.rb +0 -5
- data/lib/tweetwine/options.rb +0 -24
- data/lib/tweetwine/retrying_http.rb +0 -99
- data/lib/tweetwine/startup_config.rb +0 -50
- data/man/tweetwine.1 +0 -109
- data/man/tweetwine.1.ronn +0 -69
- data/test/client_test.rb +0 -544
- data/test/options_test.rb +0 -45
- data/test/retrying_http_test.rb +0 -147
- data/test/startup_config_test.rb +0 -162
data/test/client_test.rb
DELETED
@@ -1,544 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
|
-
require "test_helper"
|
4
|
-
require "json"
|
5
|
-
|
6
|
-
module Tweetwine
|
7
|
-
|
8
|
-
class ClientTest < TweetwineTestCase
|
9
|
-
context "A client instance" do
|
10
|
-
setup do
|
11
|
-
@io = mock()
|
12
|
-
@http_resource = mock()
|
13
|
-
@http_client = stub({ :as_resource => @http_resource })
|
14
|
-
@url_shortener = mock()
|
15
|
-
@url_shortener_block = lambda { |options| @url_shortener }
|
16
|
-
@deps = Client::Dependencies.new @io, @http_client, @url_shortener_block
|
17
|
-
end
|
18
|
-
|
19
|
-
context "upon initialization" do
|
20
|
-
should "raise exception when no authentication data is given" do
|
21
|
-
assert_raise(ArgumentError) { Client.new(@deps, {}) }
|
22
|
-
assert_raise(ArgumentError) { Client.new(@deps, { :password => "bar" }) }
|
23
|
-
assert_raise(ArgumentError) { Client.new(@deps, { :username => "", :password => "bar" }) }
|
24
|
-
assert_nothing_raised { Client.new(@deps, { :username => "foo", :password => "bar" }) }
|
25
|
-
end
|
26
|
-
|
27
|
-
should "use default number of statuses if not configured otherwise" do
|
28
|
-
@client = Client.new(@deps, { :username => "foo", :password => "bar" })
|
29
|
-
assert_equal Client::DEFAULT_NUM_STATUSES, @client.num_statuses
|
30
|
-
end
|
31
|
-
|
32
|
-
should "use configured number of statuses if in allowed range" do
|
33
|
-
@client = Client.new(@deps, { :username => "foo", :password => "bar", :num_statuses => 12 })
|
34
|
-
assert_equal 12, @client.num_statuses
|
35
|
-
end
|
36
|
-
|
37
|
-
should "raise an exception for configured number of statuses if not in allowed range" do
|
38
|
-
assert_raise(ArgumentError) { Client.new(@deps, { :username => "foo", :password => "bar", :num_statuses => 0 }) }
|
39
|
-
end
|
40
|
-
|
41
|
-
should "use default page number if not configured otherwise" do
|
42
|
-
@client = Client.new(@deps, { :username => "foo", :password => "bar" })
|
43
|
-
assert_equal Client::DEFAULT_PAGE_NUM, @client.page_num
|
44
|
-
end
|
45
|
-
|
46
|
-
should "use configured page number if in allowed range" do
|
47
|
-
@client = Client.new(@deps, { :username => "foo", :password => "bar", :page_num => 12 })
|
48
|
-
assert_equal 12, @client.page_num
|
49
|
-
end
|
50
|
-
|
51
|
-
should "raise an exception for configured page number if not in allowed range" do
|
52
|
-
assert_raise(ArgumentError) { Client.new(@deps, { :username => "foo", :password => "bar", :page_num => 0 }) }
|
53
|
-
end
|
54
|
-
|
55
|
-
should "user proper base URL and authentication information for HTTP requests" do
|
56
|
-
http_client = mock()
|
57
|
-
http_client.expects(:as_resource).with("https://twitter.com", :user => "foo", :password => "bar")
|
58
|
-
deps = Client::Dependencies.new @io, http_client, @url_shortener_block
|
59
|
-
Client.new(deps, { :username => "foo", :password => "bar" })
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
context "at runtime" do
|
64
|
-
setup do
|
65
|
-
@username = "spiky"
|
66
|
-
@password = "lullaby"
|
67
|
-
@client = Client.new(@deps, { :username => @username, :password => @password })
|
68
|
-
@rest_api_status_query_str = "count=#{Client::DEFAULT_NUM_STATUSES}&page=#{Client::DEFAULT_PAGE_NUM}"
|
69
|
-
@search_api_base_url = "http://search.twitter.com/search.json"
|
70
|
-
@search_api_query_str = "rpp=#{Client::DEFAULT_NUM_STATUSES}&page=#{Client::DEFAULT_PAGE_NUM}"
|
71
|
-
end
|
72
|
-
|
73
|
-
should "fetch friends' statuses (home view)" do
|
74
|
-
twitter_records, internal_records = create_test_twitter_status_records_from_rest_api(
|
75
|
-
{
|
76
|
-
:from_user => "zanzibar",
|
77
|
-
:status => "wassup?",
|
78
|
-
:created_at => Time.at(1).to_s,
|
79
|
-
:to_user => nil
|
80
|
-
},
|
81
|
-
{
|
82
|
-
:from_user => "lulzwoo",
|
83
|
-
:status => "nuttin'",
|
84
|
-
:created_at => Time.at(1).to_s,
|
85
|
-
:to_user => nil
|
86
|
-
}
|
87
|
-
)
|
88
|
-
@http_resource.expects(:[]) \
|
89
|
-
.with("statuses/home_timeline.json?#{@rest_api_status_query_str}") \
|
90
|
-
.returns(stub(:get => twitter_records.to_json))
|
91
|
-
@io.expects(:show_record).with(internal_records[0])
|
92
|
-
@io.expects(:show_record).with(internal_records[1])
|
93
|
-
@client.home
|
94
|
-
end
|
95
|
-
|
96
|
-
should "fetch mentions" do
|
97
|
-
twitter_records, internal_records = create_test_twitter_status_records_from_rest_api(
|
98
|
-
{
|
99
|
-
:from_user => "zanzibar",
|
100
|
-
:status => "wassup, @#{@username}?",
|
101
|
-
:created_at => Time.at(1).to_s,
|
102
|
-
:to_user => @username
|
103
|
-
},
|
104
|
-
{
|
105
|
-
:from_user => "lulzwoo",
|
106
|
-
:status => "@#{@username}, doing nuttin'",
|
107
|
-
:created_at => Time.at(1).to_s,
|
108
|
-
:to_user => @username
|
109
|
-
}
|
110
|
-
)
|
111
|
-
@http_resource.expects(:[]) \
|
112
|
-
.with("statuses/mentions.json?#{@rest_api_status_query_str}") \
|
113
|
-
.returns(stub(:get => twitter_records.to_json))
|
114
|
-
@io.expects(:show_record).with(internal_records[0])
|
115
|
-
@io.expects(:show_record).with(internal_records[1])
|
116
|
-
@client.mentions
|
117
|
-
end
|
118
|
-
|
119
|
-
should "fetch a specific user's statuses, when the user identified by given argument" do
|
120
|
-
user = "spoonman"
|
121
|
-
twitter_records, internal_records = create_test_twitter_status_records_from_rest_api(
|
122
|
-
{
|
123
|
-
:from_user => user,
|
124
|
-
:status => "wassup?",
|
125
|
-
:created_at => Time.at(1).to_s,
|
126
|
-
:to_user => nil
|
127
|
-
}
|
128
|
-
)
|
129
|
-
@http_resource.expects(:[]) \
|
130
|
-
.with("statuses/user_timeline/#{user}.json?#{@rest_api_status_query_str}") \
|
131
|
-
.returns(stub(:get => twitter_records.to_json))
|
132
|
-
@io.expects(:show_record).with(internal_records[0])
|
133
|
-
@client.user([user])
|
134
|
-
end
|
135
|
-
|
136
|
-
should "fetch a specific user's statuses, with the user being the authenticated user itself when given no argument" do
|
137
|
-
twitter_records, internal_records = create_test_twitter_status_records_from_rest_api(
|
138
|
-
{
|
139
|
-
:from_user => @username,
|
140
|
-
:status => "wassup?",
|
141
|
-
:created_at => Time.at(1).to_s,
|
142
|
-
:to_user => nil
|
143
|
-
}
|
144
|
-
)
|
145
|
-
@http_resource.expects(:[]) \
|
146
|
-
.with("statuses/user_timeline/#{@username}.json?#{@rest_api_status_query_str}") \
|
147
|
-
.returns(stub(:get => twitter_records.to_json))
|
148
|
-
@io.expects(:show_record).with(internal_records[0])
|
149
|
-
@client.user
|
150
|
-
end
|
151
|
-
|
152
|
-
context "for posting status updates" do
|
153
|
-
should "post a status update via argument, when positive confirmation" do
|
154
|
-
status = "wondering around"
|
155
|
-
twitter_records, internal_records = create_test_twitter_status_records_from_rest_api(
|
156
|
-
{
|
157
|
-
:from_user => @username,
|
158
|
-
:status => status,
|
159
|
-
:created_at => Time.at(1).to_s,
|
160
|
-
:to_user => nil
|
161
|
-
}
|
162
|
-
)
|
163
|
-
http_subresource = mock()
|
164
|
-
http_subresource.expects(:post) \
|
165
|
-
.with({ :status => status }) \
|
166
|
-
.returns(twitter_records[0].to_json)
|
167
|
-
@http_resource.expects(:[]) \
|
168
|
-
.with("statuses/update.json") \
|
169
|
-
.returns(http_subresource)
|
170
|
-
@io.expects(:confirm).with("Really send?").returns(true)
|
171
|
-
@io.expects(:show_status_preview).with(status)
|
172
|
-
@io.expects(:info).with("Sent status update.\n\n")
|
173
|
-
@io.expects(:show_record).with(internal_records[0])
|
174
|
-
@client.update([status])
|
175
|
-
end
|
176
|
-
|
177
|
-
should "post a status update via prompt, when positive confirmation" do
|
178
|
-
status = "wondering around"
|
179
|
-
twitter_records, internal_records = create_test_twitter_status_records_from_rest_api(
|
180
|
-
{
|
181
|
-
:from_user => @username,
|
182
|
-
:status => status,
|
183
|
-
:created_at => Time.at(1).to_s,
|
184
|
-
:to_user => nil
|
185
|
-
}
|
186
|
-
)
|
187
|
-
http_subresource = mock()
|
188
|
-
http_subresource.expects(:post) \
|
189
|
-
.with({ :status => status }) \
|
190
|
-
.returns(twitter_records[0].to_json)
|
191
|
-
@http_resource.expects(:[]) \
|
192
|
-
.with("statuses/update.json") \
|
193
|
-
.returns(http_subresource)
|
194
|
-
@io.expects(:prompt).with("Status update").returns(status)
|
195
|
-
@io.expects(:show_status_preview).with(status)
|
196
|
-
@io.expects(:confirm).with("Really send?").returns(true)
|
197
|
-
@io.expects(:info).with("Sent status update.\n\n")
|
198
|
-
@io.expects(:show_record).with(internal_records[0])
|
199
|
-
@client.update
|
200
|
-
end
|
201
|
-
|
202
|
-
should "cancel a status update via argument, when negative confirmation" do
|
203
|
-
status = "wondering around"
|
204
|
-
@http_resource.expects(:[]).never
|
205
|
-
@io.expects(:show_status_preview).with(status)
|
206
|
-
@io.expects(:confirm).with("Really send?").returns(false)
|
207
|
-
@io.expects(:info).with("Cancelled.")
|
208
|
-
@io.expects(:show_record).never
|
209
|
-
@client.update([status])
|
210
|
-
end
|
211
|
-
|
212
|
-
should "cancel a status update via prompt, when negative confirmation" do
|
213
|
-
status = "wondering around"
|
214
|
-
@http_resource.expects(:[]).never
|
215
|
-
@io.expects(:prompt).with("Status update").returns(status)
|
216
|
-
@io.expects(:show_status_preview).with(status)
|
217
|
-
@io.expects(:confirm).with("Really send?").returns(false)
|
218
|
-
@io.expects(:info).with("Cancelled.")
|
219
|
-
@io.expects(:show_record).never
|
220
|
-
@client.update
|
221
|
-
end
|
222
|
-
|
223
|
-
should "cancel a status update via argument, when empty status" do
|
224
|
-
@http_resource.expects(:[]).never
|
225
|
-
@io.expects(:prompt).with("Status update").returns("")
|
226
|
-
@io.expects(:confirm).never
|
227
|
-
@io.expects(:info).with("Cancelled.")
|
228
|
-
@io.expects(:show_record).never
|
229
|
-
@client.update([""])
|
230
|
-
end
|
231
|
-
|
232
|
-
should "cancel a status update via prompt, when empty status" do
|
233
|
-
@http_resource.expects(:[]).never
|
234
|
-
@io.expects(:prompt).with("Status update").returns("")
|
235
|
-
@io.expects(:confirm).never
|
236
|
-
@io.expects(:info).with("Cancelled.")
|
237
|
-
@io.expects(:show_record).never
|
238
|
-
@client.update
|
239
|
-
end
|
240
|
-
|
241
|
-
should "remove excess whitespace around a status update" do
|
242
|
-
whitespaced_status = " oh, i was sloppy \t "
|
243
|
-
stripped_status = "oh, i was sloppy"
|
244
|
-
twitter_records, internal_records = create_test_twitter_status_records_from_rest_api(
|
245
|
-
{
|
246
|
-
:from_user => @username,
|
247
|
-
:status => stripped_status,
|
248
|
-
:created_at => Time.at(1).to_s,
|
249
|
-
:to_user => nil
|
250
|
-
}
|
251
|
-
)
|
252
|
-
http_subresource = mock()
|
253
|
-
http_subresource.expects(:post) \
|
254
|
-
.with({ :status => stripped_status }) \
|
255
|
-
.returns(twitter_records[0].to_json)
|
256
|
-
@http_resource.expects(:[]) \
|
257
|
-
.with("statuses/update.json") \
|
258
|
-
.returns(http_subresource)
|
259
|
-
@io.expects(:show_status_preview).with(stripped_status)
|
260
|
-
@io.expects(:confirm).with("Really send?").returns(true)
|
261
|
-
@io.expects(:info).with("Sent status update.\n\n")
|
262
|
-
@io.expects(:show_record).with(internal_records[0])
|
263
|
-
@client.update([whitespaced_status])
|
264
|
-
end
|
265
|
-
|
266
|
-
should "truncate a status update with too long argument and warn the user" do
|
267
|
-
long_status = "x aaa bbb ccc ddd eee fff ggg hhh iii jjj kkk lll mmm nnn ooo ppp qqq rrr sss ttt uuu vvv www xxx yyy zzz 111 222 333 444 555 666 777 888 999 000"
|
268
|
-
truncated_status = "x aaa bbb ccc ddd eee fff ggg hhh iii jjj kkk lll mmm nnn ooo ppp qqq rrr sss ttt uuu vvv www xxx yyy zzz 111 222 333 444 555 666 777 888 99"
|
269
|
-
twitter_records, internal_records = create_test_twitter_status_records_from_rest_api(
|
270
|
-
{
|
271
|
-
:from_user => @username,
|
272
|
-
:status => truncated_status,
|
273
|
-
:created_at => Time.at(1).to_s,
|
274
|
-
:to_user => nil
|
275
|
-
}
|
276
|
-
)
|
277
|
-
http_subresource = mock()
|
278
|
-
http_subresource.expects(:post) \
|
279
|
-
.with({ :status => truncated_status }) \
|
280
|
-
.returns(twitter_records[0].to_json)
|
281
|
-
@http_resource.expects(:[]) \
|
282
|
-
.with("statuses/update.json") \
|
283
|
-
.returns(http_subresource)
|
284
|
-
@io.expects(:warn).with("Status will be truncated.")
|
285
|
-
@io.expects(:show_status_preview).with(truncated_status)
|
286
|
-
@io.expects(:confirm).with("Really send?").returns(true)
|
287
|
-
@io.expects(:info).with("Sent status update.\n\n")
|
288
|
-
@io.expects(:show_record).with(internal_records[0])
|
289
|
-
@client.update([long_status])
|
290
|
-
end
|
291
|
-
|
292
|
-
context "with URL shortening enabled" do
|
293
|
-
setup do
|
294
|
-
@client = Client.new(@deps, {
|
295
|
-
:username => @username,
|
296
|
-
:password => @password,
|
297
|
-
:shorten_urls => {
|
298
|
-
:enable => true,
|
299
|
-
:service_url => "http://shorten.it/create",
|
300
|
-
:method => "post",
|
301
|
-
:url_param_name => "url",
|
302
|
-
:xpath_selector => "//input[@id='short_url']/@value"
|
303
|
-
}
|
304
|
-
})
|
305
|
-
end
|
306
|
-
|
307
|
-
should "shorten URLs, avoiding truncation with long URLs" do
|
308
|
-
long_urls = ["http://www.google.fi/search?q=ruby+nokogiri&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a", "http://www.w3.org/TR/1999/REC-xpath-19991116"]
|
309
|
-
long_status = long_urls.join(" and ")
|
310
|
-
short_urls = ["http://shorten.it/2k7i8", "http://shorten.it/2k7mk"]
|
311
|
-
shortened_status = short_urls.join(" and ")
|
312
|
-
twitter_records, internal_records = create_test_twitter_status_records_from_rest_api(
|
313
|
-
{
|
314
|
-
:from_user => @username,
|
315
|
-
:status => shortened_status,
|
316
|
-
:created_at => Time.at(1).to_s,
|
317
|
-
:to_user => nil
|
318
|
-
}
|
319
|
-
)
|
320
|
-
http_subresource = mock()
|
321
|
-
http_subresource.expects(:post) \
|
322
|
-
.with({ :status => shortened_status }) \
|
323
|
-
.returns(twitter_records[0].to_json)
|
324
|
-
@http_resource.expects(:[]) \
|
325
|
-
.with("statuses/update.json") \
|
326
|
-
.returns(http_subresource)
|
327
|
-
@url_shortener.expects(:shorten).with(long_urls.first).returns(short_urls.first)
|
328
|
-
@url_shortener.expects(:shorten).with(long_urls.last).returns(short_urls.last)
|
329
|
-
@io.expects(:show_status_preview).with(shortened_status)
|
330
|
-
@io.expects(:confirm).with("Really send?").returns(true)
|
331
|
-
@io.expects(:info).with("Sent status update.\n\n")
|
332
|
-
@io.expects(:show_record).with(internal_records[0])
|
333
|
-
@client.update([long_status])
|
334
|
-
end
|
335
|
-
|
336
|
-
should "discard obviously invalid shortened URLs, using originals instead" do
|
337
|
-
long_urls = ["http://www.google.fi/", "http://www.w3.org/TR/1999/REC-xpath-19991116"]
|
338
|
-
status = long_urls.join(" and ")
|
339
|
-
short_urls = [nil, ""]
|
340
|
-
twitter_records, internal_records = create_test_twitter_status_records_from_rest_api(
|
341
|
-
{
|
342
|
-
:from_user => @username,
|
343
|
-
:status => status,
|
344
|
-
:created_at => Time.at(1).to_s,
|
345
|
-
:to_user => nil
|
346
|
-
}
|
347
|
-
)
|
348
|
-
http_subresource = mock()
|
349
|
-
http_subresource.expects(:post) \
|
350
|
-
.with({ :status => status }) \
|
351
|
-
.returns(twitter_records[0].to_json)
|
352
|
-
@http_resource.expects(:[]) \
|
353
|
-
.with("statuses/update.json") \
|
354
|
-
.returns(http_subresource)
|
355
|
-
@url_shortener.expects(:shorten).with(long_urls.first).returns(short_urls.first)
|
356
|
-
@url_shortener.expects(:shorten).with(long_urls.last).returns(short_urls.last)
|
357
|
-
@io.expects(:show_status_preview).with(status)
|
358
|
-
@io.expects(:confirm).with("Really send?").returns(true)
|
359
|
-
@io.expects(:info).with("Sent status update.\n\n")
|
360
|
-
@io.expects(:show_record).with(internal_records[0])
|
361
|
-
@client.update([status])
|
362
|
-
end
|
363
|
-
|
364
|
-
should "reuse a shortened URL for duplicate long URLs" do
|
365
|
-
long_urls = ["http://www.w3.org/TR/1999/REC-xpath-19991116"] * 2
|
366
|
-
long_status = long_urls.join(" and ")
|
367
|
-
short_url = "http://shorten.it/2k7mk"
|
368
|
-
short_status = ([short_url] * 2).join(" and ")
|
369
|
-
twitter_records, internal_records = create_test_twitter_status_records_from_rest_api(
|
370
|
-
{
|
371
|
-
:from_user => @username,
|
372
|
-
:status => short_status,
|
373
|
-
:created_at => Time.at(1).to_s,
|
374
|
-
:to_user => nil
|
375
|
-
}
|
376
|
-
)
|
377
|
-
http_subresource = mock()
|
378
|
-
http_subresource.expects(:post) \
|
379
|
-
.with({ :status => short_status }) \
|
380
|
-
.returns(twitter_records[0].to_json)
|
381
|
-
@http_resource.expects(:[]) \
|
382
|
-
.with("statuses/update.json") \
|
383
|
-
.returns(http_subresource)
|
384
|
-
@url_shortener.expects(:shorten).with(long_urls.first).returns(short_url)
|
385
|
-
@io.expects(:show_status_preview).with(short_status)
|
386
|
-
@io.expects(:confirm).with("Really send?").returns(true)
|
387
|
-
@io.expects(:info).with("Sent status update.\n\n")
|
388
|
-
@io.expects(:show_record).with(internal_records[0])
|
389
|
-
@client.update([long_status])
|
390
|
-
end
|
391
|
-
|
392
|
-
context "in erroneous situations" do
|
393
|
-
setup do
|
394
|
-
@url = "http://www.w3.org/TR/1999/REC-xpath-19991116"
|
395
|
-
@status = "skimming through #{@url}"
|
396
|
-
@twitter_records, @internal_records = create_test_twitter_status_records_from_rest_api(
|
397
|
-
{
|
398
|
-
:from_user => @username,
|
399
|
-
:status => @status,
|
400
|
-
:created_at => Time.at(1).to_s,
|
401
|
-
:to_user => nil
|
402
|
-
}
|
403
|
-
)
|
404
|
-
end
|
405
|
-
|
406
|
-
should "skip shortening URLs if required libraries are not found" do
|
407
|
-
http_subresource = mock()
|
408
|
-
http_subresource.expects(:post) \
|
409
|
-
.with({ :status => @status }) \
|
410
|
-
.returns(@twitter_records[0].to_json)
|
411
|
-
@http_resource.expects(:[]) \
|
412
|
-
.with("statuses/update.json") \
|
413
|
-
.returns(http_subresource)
|
414
|
-
@url_shortener.expects(:shorten).with(@url).raises(LoadError, "gem not found")
|
415
|
-
@io.expects(:warn)
|
416
|
-
@io.expects(:show_status_preview).with(@status)
|
417
|
-
@io.expects(:confirm).with("Really send?").returns(true)
|
418
|
-
@io.expects(:info).with("Sent status update.\n\n")
|
419
|
-
@io.expects(:show_record).with(@internal_records[0])
|
420
|
-
@client.update([@status])
|
421
|
-
end
|
422
|
-
|
423
|
-
should "skip shortening URLs upon connection error to the URL shortening service" do
|
424
|
-
http_subresource = mock()
|
425
|
-
http_subresource.expects(:post) \
|
426
|
-
.with({ :status => @status }) \
|
427
|
-
.returns(@twitter_records[0].to_json)
|
428
|
-
@http_resource.expects(:[]) \
|
429
|
-
.with("statuses/update.json") \
|
430
|
-
.returns(http_subresource)
|
431
|
-
@url_shortener.expects(:shorten).with(@url).raises(HttpError, "connection error")
|
432
|
-
@io.expects(:warn)
|
433
|
-
@io.expects(:show_status_preview).with(@status)
|
434
|
-
@io.expects(:confirm).with("Really send?").returns(true)
|
435
|
-
@io.expects(:info).with("Sent status update.\n\n")
|
436
|
-
@io.expects(:show_record).with(@internal_records[0])
|
437
|
-
@client.update([@status])
|
438
|
-
end
|
439
|
-
end
|
440
|
-
end
|
441
|
-
end
|
442
|
-
|
443
|
-
should "fetch friends" do
|
444
|
-
twitter_records, internal_records = create_test_twitter_user_records_from_rest_api(
|
445
|
-
{
|
446
|
-
:from_user => "zanzibar",
|
447
|
-
:status => "wassup, @foo?",
|
448
|
-
:created_at => Time.at(1).to_s,
|
449
|
-
:to_user => "foo"
|
450
|
-
},
|
451
|
-
{
|
452
|
-
:from_user => "lulzwoo",
|
453
|
-
:status => "@foo, doing nuttin'",
|
454
|
-
:created_at => Time.at(1).to_s,
|
455
|
-
:to_user => "foo"
|
456
|
-
}
|
457
|
-
)
|
458
|
-
@http_resource.expects(:[]) \
|
459
|
-
.with("statuses/friends/#{@username}.json") \
|
460
|
-
.returns(stub(:get => twitter_records.to_json))
|
461
|
-
@io.expects(:show_record).with(internal_records[0])
|
462
|
-
@io.expects(:show_record).with(internal_records[1])
|
463
|
-
@client.friends
|
464
|
-
end
|
465
|
-
|
466
|
-
should "fetch followers" do
|
467
|
-
twitter_records, internal_records = create_test_twitter_user_records_from_rest_api(
|
468
|
-
{
|
469
|
-
:from_user => "zanzibar",
|
470
|
-
:status => "wassup, @foo?",
|
471
|
-
:created_at => Time.at(1).to_s,
|
472
|
-
:to_user => "foo"
|
473
|
-
},
|
474
|
-
{
|
475
|
-
:from_user => "lulzwoo",
|
476
|
-
:status => nil,
|
477
|
-
:created_at => nil,
|
478
|
-
:to_user => nil
|
479
|
-
}
|
480
|
-
)
|
481
|
-
@http_resource.expects(:[]) \
|
482
|
-
.with("statuses/followers/#{@username}.json") \
|
483
|
-
.returns(stub(:get => twitter_records.to_json))
|
484
|
-
@io.expects(:show_record).with(internal_records[0])
|
485
|
-
@io.expects(:show_record).with(internal_records[1])
|
486
|
-
@client.followers
|
487
|
-
end
|
488
|
-
|
489
|
-
context "for searching tweets" do
|
490
|
-
should "raise exception if no search word is given" do
|
491
|
-
assert_raise(ArgumentError) { @client.search() }
|
492
|
-
end
|
493
|
-
|
494
|
-
should "allow searching for tweets that match all the given words" do
|
495
|
-
twitter_response, internal_records = create_test_twitter_records_from_search_api(
|
496
|
-
{
|
497
|
-
:from_user => "zanzibar",
|
498
|
-
:status => "@foo, wassup? #greets",
|
499
|
-
:created_at => Time.at(1).to_s,
|
500
|
-
:to_user => "foo"
|
501
|
-
},
|
502
|
-
{
|
503
|
-
:from_user => "spoonman",
|
504
|
-
:status => "@foo long time no see #greets",
|
505
|
-
:created_at => Time.at(1).to_s,
|
506
|
-
:to_user => "foo"
|
507
|
-
}
|
508
|
-
)
|
509
|
-
@http_client.expects(:get) \
|
510
|
-
.with("#{@search_api_base_url}?q=%23greets%20%40foo&#{@search_api_query_str}") \
|
511
|
-
.returns(twitter_response.to_json)
|
512
|
-
@io.expects(:show_record).with(internal_records[0])
|
513
|
-
@io.expects(:show_record).with(internal_records[1])
|
514
|
-
@client.search(["#greets", "@foo"])
|
515
|
-
end
|
516
|
-
|
517
|
-
should "allow searching for tweets that match any of the given words" do
|
518
|
-
twitter_response, internal_records = create_test_twitter_records_from_search_api(
|
519
|
-
{
|
520
|
-
:from_user => "zanzibar",
|
521
|
-
:status => "spinning around the floor #habits",
|
522
|
-
:created_at => Time.at(1).to_s,
|
523
|
-
:to_user => "foo"
|
524
|
-
},
|
525
|
-
{
|
526
|
-
:from_user => "spoonman",
|
527
|
-
:status => "drinking coffee, again #neurotic",
|
528
|
-
:created_at => Time.at(1).to_s,
|
529
|
-
:to_user => "foo"
|
530
|
-
}
|
531
|
-
)
|
532
|
-
@http_client.expects(:get) \
|
533
|
-
.with("#{@search_api_base_url}?q=%23habits%20OR%20%23neurotic&#{@search_api_query_str}") \
|
534
|
-
.returns(twitter_response.to_json)
|
535
|
-
@io.expects(:show_record).with(internal_records[0])
|
536
|
-
@io.expects(:show_record).with(internal_records[1])
|
537
|
-
@client.search(["#habits", "#neurotic"], {:bin_op => :or})
|
538
|
-
end
|
539
|
-
end
|
540
|
-
end
|
541
|
-
end
|
542
|
-
end
|
543
|
-
|
544
|
-
end
|
data/test/options_test.rb
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
|
-
require "test_helper"
|
4
|
-
|
5
|
-
module Tweetwine
|
6
|
-
|
7
|
-
class OptionsTest < TweetwineTestCase
|
8
|
-
context "An Options instance" do
|
9
|
-
should "get the value corresponding to a key or nil (the default value)" do
|
10
|
-
assert_equal "alpha", Options.new({:a => "alpha"})[:a]
|
11
|
-
assert_equal nil, Options.new({})[:a]
|
12
|
-
end
|
13
|
-
|
14
|
-
context "for requiring options" do
|
15
|
-
should "raise ArgumentError if there's no value for the required option (a value that is nil)" do
|
16
|
-
assert_equal "alpha", Options.new({:a => "alpha"}).require(:a)
|
17
|
-
assert_raise(ArgumentError) { Options.new({}).require(:a) }
|
18
|
-
end
|
19
|
-
|
20
|
-
should "indicate the required option upon failure" do
|
21
|
-
error = nil
|
22
|
-
begin
|
23
|
-
Options.new({}).require(:a)
|
24
|
-
flunk "should have raised ArgumentError"
|
25
|
-
rescue ArgumentError => e
|
26
|
-
error = e
|
27
|
-
end
|
28
|
-
assert_equal("Option a is required", e.to_s)
|
29
|
-
end
|
30
|
-
|
31
|
-
should "indicate the required option upon failure, with optional error source" do
|
32
|
-
error = nil
|
33
|
-
begin
|
34
|
-
Options.new({}, "test options").require(:a)
|
35
|
-
flunk "should have raised ArgumentError"
|
36
|
-
rescue ArgumentError => e
|
37
|
-
error = e
|
38
|
-
end
|
39
|
-
assert_equal("Option a is required for test options", e.to_s)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
end
|