tuomas-tweetwine 0.1.11 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.rdoc +11 -0
- data/README.rdoc +36 -2
- data/Rakefile +2 -3
- data/bin/tweetwine +13 -4
- data/lib/tweetwine/client.rb +74 -39
- data/lib/tweetwine/io.rb +48 -28
- data/lib/tweetwine/meta.rb +10 -0
- data/lib/tweetwine/options.rb +17 -0
- data/lib/tweetwine/rest_client_wrapper.rb +17 -0
- data/lib/tweetwine/startup_config.rb +1 -4
- data/lib/tweetwine/url_shortener.rb +37 -0
- data/lib/tweetwine/util.rb +22 -0
- data/lib/tweetwine.rb +10 -1
- data/test/client_test.rb +252 -154
- data/test/io_test.rb +40 -16
- data/test/options_test.rb +19 -0
- data/test/rest_client_wrapper_test.rb +24 -0
- data/test/test_helper.rb +21 -18
- data/test/url_shortener_test.rb +68 -0
- data/test/util_test.rb +29 -0
- metadata +10 -3
data/test/client_test.rb
CHANGED
|
@@ -1,64 +1,65 @@
|
|
|
1
1
|
require File.dirname(__FILE__) << "/test_helper"
|
|
2
2
|
require "json"
|
|
3
3
|
|
|
4
|
+
Mocha::Configuration.allow(:stubbing_non_existent_method)
|
|
5
|
+
|
|
4
6
|
module Tweetwine
|
|
5
7
|
|
|
6
8
|
class ClientTest < Test::Unit::TestCase
|
|
7
|
-
context "Upon
|
|
9
|
+
context "Upon initialization, a client" do
|
|
10
|
+
setup do
|
|
11
|
+
@io = mock()
|
|
12
|
+
end
|
|
13
|
+
|
|
8
14
|
should "raise exception when no authentication data is given" do
|
|
9
|
-
assert_raises(ArgumentError) { Client.new({}) }
|
|
10
|
-
assert_raises(ArgumentError) { Client.new({ :password => "bar" }) }
|
|
11
|
-
assert_raises(ArgumentError) { Client.new({ :username => "", :password => "bar" }) }
|
|
12
|
-
assert_nothing_raised { Client.new({ :username => "foo", :password => "bar" }) }
|
|
15
|
+
assert_raises(ArgumentError) { Client.new(@io, {}) }
|
|
16
|
+
assert_raises(ArgumentError) { Client.new(@io, { :password => "bar" }) }
|
|
17
|
+
assert_raises(ArgumentError) { Client.new(@io, { :username => "", :password => "bar" }) }
|
|
18
|
+
assert_nothing_raised { Client.new(@io, { :username => "foo", :password => "bar" }) }
|
|
13
19
|
end
|
|
14
20
|
|
|
15
21
|
should "use default number of statuses if not configured otherwise" do
|
|
16
|
-
@client = Client.new({ :username => "foo", :password => "bar" })
|
|
22
|
+
@client = Client.new(@io, { :username => "foo", :password => "bar" })
|
|
17
23
|
assert_equal Client::DEFAULT_NUM_STATUSES, @client.num_statuses
|
|
18
24
|
end
|
|
19
25
|
|
|
20
26
|
should "use configured number of statuses if in allowed range" do
|
|
21
|
-
@client = Client.new({ :username => "foo", :password => "bar", :num_statuses => 12 })
|
|
27
|
+
@client = Client.new(@io, { :username => "foo", :password => "bar", :num_statuses => 12 })
|
|
22
28
|
assert_equal 12, @client.num_statuses
|
|
23
29
|
end
|
|
24
30
|
|
|
25
31
|
should "raise an exception for configured number of statuses if not in allowed range" do
|
|
26
|
-
assert_raises(ArgumentError) { Client.new({ :username => "foo", :password => "bar", :num_statuses => 0 }) }
|
|
32
|
+
assert_raises(ArgumentError) { Client.new(@io, { :username => "foo", :password => "bar", :num_statuses => 0 }) }
|
|
27
33
|
end
|
|
28
34
|
|
|
29
35
|
should "use default page number if not configured otherwise" do
|
|
30
|
-
@client = Client.new({ :username => "foo", :password => "bar" })
|
|
36
|
+
@client = Client.new(@io, { :username => "foo", :password => "bar" })
|
|
31
37
|
assert_equal Client::DEFAULT_PAGE_NUM, @client.page_num
|
|
32
38
|
end
|
|
33
39
|
|
|
34
40
|
should "use configured page number if in allowed range" do
|
|
35
|
-
@client = Client.new({ :username => "foo", :password => "bar", :page_num => 12 })
|
|
41
|
+
@client = Client.new(@io, { :username => "foo", :password => "bar", :page_num => 12 })
|
|
36
42
|
assert_equal 12, @client.page_num
|
|
37
43
|
end
|
|
38
44
|
|
|
39
45
|
should "raise an exception for configured page number if not in allowed range" do
|
|
40
|
-
assert_raises(ArgumentError) { Client.new({ :username => "foo", :password => "bar", :page_num => 0 }) }
|
|
46
|
+
assert_raises(ArgumentError) { Client.new(@io, { :username => "foo", :password => "bar", :page_num => 0 }) }
|
|
41
47
|
end
|
|
42
48
|
end
|
|
43
49
|
|
|
44
|
-
context "
|
|
50
|
+
context "At runtime, a client" do
|
|
45
51
|
setup do
|
|
46
|
-
@client = Client.new({ :username => "foo", :password => "bar" })
|
|
47
52
|
@io = mock()
|
|
48
|
-
@
|
|
53
|
+
@username = "spiky"
|
|
54
|
+
@password = "lullaby"
|
|
55
|
+
@client = Client.new(@io, { :username => @username, :password => @password })
|
|
56
|
+
@base_url = "https://#{@username}:#{@password}@twitter.com"
|
|
49
57
|
@statuses_query_params = "count=#{Client::DEFAULT_NUM_STATUSES}&page=#{Client::DEFAULT_PAGE_NUM}"
|
|
50
58
|
@users_query_params = "page=#{Client::DEFAULT_PAGE_NUM}"
|
|
51
59
|
end
|
|
52
60
|
|
|
53
|
-
should "raise ClientError for invalid request" do
|
|
54
|
-
RestClient.expects(:get) \
|
|
55
|
-
.with("https://foo:bar@twitter.com/statuses/friends_timeline.json?#{@statuses_query_params}") \
|
|
56
|
-
.raises(RestClient::Unauthorized)
|
|
57
|
-
assert_raises(ClientError) { @client.home }
|
|
58
|
-
end
|
|
59
|
-
|
|
60
61
|
should "fetch friends' statuses (home view)" do
|
|
61
|
-
|
|
62
|
+
status_records, gen_records = create_test_statuses(
|
|
62
63
|
{
|
|
63
64
|
:user => "zanzibar",
|
|
64
65
|
:status => {
|
|
@@ -76,45 +77,46 @@ class ClientTest < Test::Unit::TestCase
|
|
|
76
77
|
}
|
|
77
78
|
}
|
|
78
79
|
)
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
@io.expects(:
|
|
83
|
-
@io.expects(:
|
|
80
|
+
RestClientWrapper.expects(:get) \
|
|
81
|
+
.with("#{@base_url}/statuses/friends_timeline.json?#{@statuses_query_params}") \
|
|
82
|
+
.returns(status_records.to_json)
|
|
83
|
+
@io.expects(:show_record).with(gen_records[0])
|
|
84
|
+
@io.expects(:show_record).with(gen_records[1])
|
|
84
85
|
@client.home
|
|
85
86
|
end
|
|
86
87
|
|
|
87
88
|
should "fetch mentions" do
|
|
88
|
-
|
|
89
|
+
status_records, gen_records = create_test_statuses(
|
|
89
90
|
{
|
|
90
91
|
:user => "zanzibar",
|
|
91
92
|
:status => {
|
|
92
93
|
:created_at => Time.at(1).to_s,
|
|
93
|
-
:text => "wassup, @
|
|
94
|
-
:in_reply_to =>
|
|
94
|
+
:text => "wassup, @#{@username}?",
|
|
95
|
+
:in_reply_to => @username
|
|
95
96
|
}
|
|
96
97
|
},
|
|
97
98
|
{
|
|
98
99
|
:user => "lulzwoo",
|
|
99
100
|
:status => {
|
|
100
101
|
:created_at => Time.at(1).to_s,
|
|
101
|
-
:text => "@
|
|
102
|
-
:in_reply_to =>
|
|
102
|
+
:text => "@#{@username}, doing nuttin'",
|
|
103
|
+
:in_reply_to => @username
|
|
103
104
|
}
|
|
104
105
|
}
|
|
105
106
|
)
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
@io.expects(:
|
|
110
|
-
@io.expects(:
|
|
107
|
+
RestClientWrapper.expects(:get) \
|
|
108
|
+
.with("#{@base_url}/statuses/mentions.json?#{@statuses_query_params}") \
|
|
109
|
+
.returns(status_records.to_json)
|
|
110
|
+
@io.expects(:show_record).with(gen_records[0])
|
|
111
|
+
@io.expects(:show_record).with(gen_records[1])
|
|
111
112
|
@client.mentions
|
|
112
113
|
end
|
|
113
114
|
|
|
114
|
-
should "fetch a specific user's statuses,
|
|
115
|
-
|
|
115
|
+
should "fetch a specific user's statuses, when the user identified by given argument" do
|
|
116
|
+
user = "spoonman"
|
|
117
|
+
status_records, gen_records = create_test_statuses(
|
|
116
118
|
{
|
|
117
|
-
:user =>
|
|
119
|
+
:user => user,
|
|
118
120
|
:status => {
|
|
119
121
|
:created_at => Time.at(1).to_s,
|
|
120
122
|
:text => "wassup?",
|
|
@@ -122,17 +124,17 @@ class ClientTest < Test::Unit::TestCase
|
|
|
122
124
|
}
|
|
123
125
|
}
|
|
124
126
|
)
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
@io.expects(:
|
|
129
|
-
@client.user(
|
|
127
|
+
RestClientWrapper.expects(:get) \
|
|
128
|
+
.with("#{@base_url}/statuses/user_timeline/#{user}.json?#{@statuses_query_params}") \
|
|
129
|
+
.returns(status_records.to_json)
|
|
130
|
+
@io.expects(:show_record).with(gen_records[0])
|
|
131
|
+
@client.user(user)
|
|
130
132
|
end
|
|
131
133
|
|
|
132
134
|
should "fetch a specific user's statuses, with the user being the authenticated user itself when given no argument" do
|
|
133
|
-
|
|
135
|
+
status_records, gen_records = create_test_statuses(
|
|
134
136
|
{
|
|
135
|
-
:user =>
|
|
137
|
+
:user => @username,
|
|
136
138
|
:status => {
|
|
137
139
|
:created_at => Time.at(1).to_s,
|
|
138
140
|
:text => "wassup?",
|
|
@@ -140,111 +142,212 @@ class ClientTest < Test::Unit::TestCase
|
|
|
140
142
|
}
|
|
141
143
|
}
|
|
142
144
|
)
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
@io.expects(:
|
|
145
|
+
RestClientWrapper.expects(:get) \
|
|
146
|
+
.with("#{@base_url}/statuses/user_timeline/#{@username}.json?#{@statuses_query_params}") \
|
|
147
|
+
.returns(status_records.to_json)
|
|
148
|
+
@io.expects(:show_record).with(gen_records[0])
|
|
147
149
|
@client.user
|
|
148
150
|
end
|
|
149
151
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
:
|
|
156
|
-
:
|
|
157
|
-
|
|
152
|
+
context "for posting status updates" do
|
|
153
|
+
should "post a status update via argument, when positive confirmation" do
|
|
154
|
+
status = "wondering around"
|
|
155
|
+
status_records, gen_records = create_test_statuses(
|
|
156
|
+
{
|
|
157
|
+
:user => @username,
|
|
158
|
+
:status => {
|
|
159
|
+
:created_at => Time.at(1).to_s,
|
|
160
|
+
:text => status,
|
|
161
|
+
:in_reply_to => nil
|
|
162
|
+
}
|
|
158
163
|
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
164
|
+
)
|
|
165
|
+
RestClientWrapper.expects(:post) \
|
|
166
|
+
.with("#{@base_url}/statuses/update.json", {:status => status}) \
|
|
167
|
+
.returns(status_records[0].to_json)
|
|
168
|
+
@io.expects(:confirm).with("Really send?").returns(true)
|
|
169
|
+
@io.expects(:show_status_preview).with(status)
|
|
170
|
+
@io.expects(:info).with("Sent status update.\n\n")
|
|
171
|
+
@io.expects(:show_record).with(gen_records[0])
|
|
172
|
+
@client.update(status)
|
|
173
|
+
end
|
|
169
174
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
:
|
|
174
|
-
:
|
|
175
|
-
|
|
176
|
-
|
|
175
|
+
should "post a status update via prompt, when positive confirmation" do
|
|
176
|
+
status = "wondering around"
|
|
177
|
+
status_records, gen_records = create_test_statuses(
|
|
178
|
+
{ :user => @username,
|
|
179
|
+
:status => {
|
|
180
|
+
:created_at => Time.at(1).to_s,
|
|
181
|
+
:text => status,
|
|
182
|
+
:in_reply_to => nil
|
|
183
|
+
}
|
|
177
184
|
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
185
|
+
)
|
|
186
|
+
RestClientWrapper.expects(:post) \
|
|
187
|
+
.with("#{@base_url}/statuses/update.json", {:status => status}) \
|
|
188
|
+
.returns(status_records[0].to_json)
|
|
189
|
+
@io.expects(:prompt).with("Status update").returns(status)
|
|
190
|
+
@io.expects(:show_status_preview).with(status)
|
|
191
|
+
@io.expects(:confirm).with("Really send?").returns(true)
|
|
192
|
+
@io.expects(:info).with("Sent status update.\n\n")
|
|
193
|
+
@io.expects(:show_record).with(gen_records[0])
|
|
194
|
+
@client.update
|
|
195
|
+
end
|
|
189
196
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
+
should "cancel a status update via argument, when negative confirmation" do
|
|
198
|
+
status = "wondering around"
|
|
199
|
+
RestClientWrapper.expects(:post).never
|
|
200
|
+
@io.expects(:show_status_preview).with(status)
|
|
201
|
+
@io.expects(:confirm).with("Really send?").returns(false)
|
|
202
|
+
@io.expects(:info).with("Cancelled.")
|
|
203
|
+
@io.expects(:show_record).never
|
|
204
|
+
@client.update(status)
|
|
205
|
+
end
|
|
197
206
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
207
|
+
should "cancel a status update via prompt, when negative confirmation" do
|
|
208
|
+
status = "wondering around"
|
|
209
|
+
RestClientWrapper.expects(:post).never
|
|
210
|
+
@io.expects(:prompt).with("Status update").returns(status)
|
|
211
|
+
@io.expects(:show_status_preview).with(status)
|
|
212
|
+
@io.expects(:confirm).with("Really send?").returns(false)
|
|
213
|
+
@io.expects(:info).with("Cancelled.")
|
|
214
|
+
@io.expects(:show_record).never
|
|
215
|
+
@client.update
|
|
216
|
+
end
|
|
206
217
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
218
|
+
should "cancel a status update via argument, when empty status" do
|
|
219
|
+
RestClientWrapper.expects(:post).never
|
|
220
|
+
@io.expects(:confirm).never
|
|
221
|
+
@io.expects(:info).with("Cancelled.")
|
|
222
|
+
@io.expects(:show_record).never
|
|
223
|
+
@client.update("")
|
|
224
|
+
end
|
|
214
225
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
226
|
+
should "cancel a status update via prompt, when empty status" do
|
|
227
|
+
RestClientWrapper.expects(:post).never
|
|
228
|
+
@io.expects(:prompt).with("Status update").returns("")
|
|
229
|
+
@io.expects(:confirm).never
|
|
230
|
+
@io.expects(:info).with("Cancelled.")
|
|
231
|
+
@io.expects(:show_record).never
|
|
232
|
+
@client.update
|
|
233
|
+
end
|
|
223
234
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
235
|
+
should "remove excess whitespace around a status update" do
|
|
236
|
+
whitespaced_status = " oh, i was sloppy \t "
|
|
237
|
+
stripped_status = "oh, i was sloppy"
|
|
238
|
+
status_records, gen_records = create_test_statuses(
|
|
239
|
+
{ :user => @username,
|
|
240
|
+
:status => {
|
|
241
|
+
:created_at => Time.at(1).to_s,
|
|
242
|
+
:text => stripped_status,
|
|
243
|
+
:in_reply_to => nil
|
|
244
|
+
}
|
|
233
245
|
}
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
246
|
+
)
|
|
247
|
+
RestClientWrapper.expects(:post) \
|
|
248
|
+
.with("#{@base_url}/statuses/update.json", {:status => stripped_status}) \
|
|
249
|
+
.returns(status_records[0].to_json)
|
|
250
|
+
@io.expects(:show_status_preview).with(stripped_status)
|
|
251
|
+
@io.expects(:confirm).with("Really send?").returns(true)
|
|
252
|
+
@io.expects(:info).with("Sent status update.\n\n")
|
|
253
|
+
@io.expects(:show_record).with(gen_records[0])
|
|
254
|
+
@client.update(whitespaced_status)
|
|
255
|
+
end
|
|
256
|
+
|
|
257
|
+
should "truncate a status update with too long argument and warn the user" do
|
|
258
|
+
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"
|
|
259
|
+
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"
|
|
260
|
+
status_records, gen_records = create_test_statuses(
|
|
261
|
+
{ :user => @username,
|
|
262
|
+
:status => {
|
|
263
|
+
:created_at => Time.at(1).to_s,
|
|
264
|
+
:text => truncated_status,
|
|
265
|
+
:in_reply_to => nil
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
)
|
|
269
|
+
RestClientWrapper.expects(:post) \
|
|
270
|
+
.with("#{@base_url}/statuses/update.json", {:status => truncated_status}) \
|
|
271
|
+
.returns(status_records[0].to_json)
|
|
272
|
+
@io.expects(:warn).with("Status will be truncated.")
|
|
273
|
+
@io.expects(:show_status_preview).with(truncated_status)
|
|
274
|
+
@io.expects(:confirm).with("Really send?").returns(true)
|
|
275
|
+
@io.expects(:info).with("Sent status update.\n\n")
|
|
276
|
+
@io.expects(:show_record).with(gen_records[0])
|
|
277
|
+
@client.update(long_status)
|
|
278
|
+
end
|
|
279
|
+
|
|
280
|
+
context "with URL shortening enabled" do
|
|
281
|
+
setup do
|
|
282
|
+
@client = Client.new(@io, {
|
|
283
|
+
:username => @username,
|
|
284
|
+
:password => @password,
|
|
285
|
+
:shorten_urls => {
|
|
286
|
+
:enable => true,
|
|
287
|
+
:service_url => "http://shorten.it/create",
|
|
288
|
+
:method => "post",
|
|
289
|
+
:url_param_name => "url",
|
|
290
|
+
:xpath_selector => "//input[@id='short_url']/@value"
|
|
291
|
+
}
|
|
292
|
+
})
|
|
293
|
+
@url_shortener = @client.instance_variable_get(:@url_shortener)
|
|
294
|
+
end
|
|
295
|
+
|
|
296
|
+
should "shorten URLs, avoiding truncation with long URLs" do
|
|
297
|
+
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"]
|
|
298
|
+
long_status = long_urls.join(" and ")
|
|
299
|
+
short_urls = ["http://shorten.it/2k7i8", "http://shorten.it/2k7mk"]
|
|
300
|
+
shortened_status = short_urls.join(" and ")
|
|
301
|
+
status_records, gen_records = create_test_statuses(
|
|
302
|
+
{ :user => @username,
|
|
303
|
+
:status => {
|
|
304
|
+
:created_at => Time.at(1).to_s,
|
|
305
|
+
:text => shortened_status,
|
|
306
|
+
:in_reply_to => nil
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
)
|
|
310
|
+
RestClientWrapper.expects(:post) \
|
|
311
|
+
.with("#{@base_url}/statuses/update.json", {:status => shortened_status}) \
|
|
312
|
+
.returns(status_records[0].to_json)
|
|
313
|
+
@url_shortener.expects(:shorten).with(long_urls.first).returns(short_urls.first)
|
|
314
|
+
@url_shortener.expects(:shorten).with(long_urls.last).returns(short_urls.last)
|
|
315
|
+
@io.expects(:show_status_preview).with(shortened_status)
|
|
316
|
+
@io.expects(:confirm).with("Really send?").returns(true)
|
|
317
|
+
@io.expects(:info).with("Sent status update.\n\n")
|
|
318
|
+
@io.expects(:show_record).with(gen_records[0])
|
|
319
|
+
@client.update(long_status)
|
|
320
|
+
end
|
|
321
|
+
|
|
322
|
+
should "discard obviously invalid shortened URLs, using originals instead" do
|
|
323
|
+
long_urls = ["http://www.google.fi/", "http://www.w3.org/TR/1999/REC-xpath-19991116"]
|
|
324
|
+
status = long_urls.join(" and ")
|
|
325
|
+
short_urls = [nil, ""]
|
|
326
|
+
status_records, gen_records = create_test_statuses(
|
|
327
|
+
{ :user => @username,
|
|
328
|
+
:status => {
|
|
329
|
+
:created_at => Time.at(1).to_s,
|
|
330
|
+
:text => status,
|
|
331
|
+
:in_reply_to => nil
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
)
|
|
335
|
+
RestClientWrapper.expects(:post) \
|
|
336
|
+
.with("#{@base_url}/statuses/update.json", {:status => status}) \
|
|
337
|
+
.returns(status_records[0].to_json)
|
|
338
|
+
@url_shortener.expects(:shorten).with(long_urls.first).returns(short_urls.first)
|
|
339
|
+
@url_shortener.expects(:shorten).with(long_urls.last).returns(short_urls.last)
|
|
340
|
+
@io.expects(:show_status_preview).with(status)
|
|
341
|
+
@io.expects(:confirm).with("Really send?").returns(true)
|
|
342
|
+
@io.expects(:info).with("Sent status update.\n\n")
|
|
343
|
+
@io.expects(:show_record).with(gen_records[0])
|
|
344
|
+
@client.update(status)
|
|
345
|
+
end
|
|
346
|
+
end
|
|
244
347
|
end
|
|
245
348
|
|
|
246
349
|
should "fetch friends" do
|
|
247
|
-
|
|
350
|
+
user_records, gen_records = create_test_users(
|
|
248
351
|
{
|
|
249
352
|
:user => "zanzibar",
|
|
250
353
|
:status => {
|
|
@@ -262,16 +365,16 @@ class ClientTest < Test::Unit::TestCase
|
|
|
262
365
|
}
|
|
263
366
|
}
|
|
264
367
|
)
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
@io.expects(:
|
|
269
|
-
@io.expects(:
|
|
368
|
+
RestClientWrapper.expects(:get) \
|
|
369
|
+
.with("#{@base_url}/statuses/friends/#{@username}.json?#{@users_query_params}") \
|
|
370
|
+
.returns(user_records.to_json)
|
|
371
|
+
@io.expects(:show_record).with(gen_records[0])
|
|
372
|
+
@io.expects(:show_record).with(gen_records[1])
|
|
270
373
|
@client.friends
|
|
271
374
|
end
|
|
272
375
|
|
|
273
376
|
should "fetch followers" do
|
|
274
|
-
|
|
377
|
+
user_records, gen_records = create_test_users(
|
|
275
378
|
{
|
|
276
379
|
:user => "zanzibar",
|
|
277
380
|
:status => {
|
|
@@ -281,19 +384,14 @@ class ClientTest < Test::Unit::TestCase
|
|
|
281
384
|
}
|
|
282
385
|
},
|
|
283
386
|
{
|
|
284
|
-
:user => "lulzwoo"
|
|
285
|
-
:status => {
|
|
286
|
-
:created_at => Time.at(1).to_s,
|
|
287
|
-
:text => "@foo, doing nuttin'",
|
|
288
|
-
:in_reply_to => "foo"
|
|
289
|
-
}
|
|
387
|
+
:user => "lulzwoo"
|
|
290
388
|
}
|
|
291
389
|
)
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
@io.expects(:
|
|
296
|
-
@io.expects(:
|
|
390
|
+
RestClientWrapper.expects(:get) \
|
|
391
|
+
.with("#{@base_url}/statuses/followers/#{@username}.json?#{@users_query_params}") \
|
|
392
|
+
.returns(user_records.to_json)
|
|
393
|
+
@io.expects(:show_record).with(gen_records[0])
|
|
394
|
+
@io.expects(:show_record).with(gen_records[1])
|
|
297
395
|
@client.followers
|
|
298
396
|
end
|
|
299
397
|
end
|
data/test/io_test.rb
CHANGED
|
@@ -59,44 +59,57 @@ fooman
|
|
|
59
59
|
|
|
60
60
|
END
|
|
61
61
|
)
|
|
62
|
-
@io.
|
|
62
|
+
@io.show_record(record)
|
|
63
63
|
end
|
|
64
64
|
|
|
65
|
-
should "output record as
|
|
65
|
+
should "output a record as status info when status is given, without in-reply info" do
|
|
66
|
+
status = "Hi, @barman! Lulz woo!"
|
|
66
67
|
record = {
|
|
67
68
|
:user => "fooman",
|
|
68
69
|
:status => {
|
|
69
70
|
:created_at => Time.at(1),
|
|
70
|
-
:text =>
|
|
71
|
+
:text => status
|
|
71
72
|
}
|
|
72
73
|
}
|
|
73
74
|
Util.expects(:humanize_time_diff).returns([2, "secs"])
|
|
74
75
|
@output.expects(:puts).with(<<-END
|
|
75
76
|
fooman, 2 secs ago:
|
|
76
|
-
|
|
77
|
+
#{status}
|
|
77
78
|
|
|
78
79
|
END
|
|
79
80
|
)
|
|
80
|
-
@io.
|
|
81
|
+
@io.show_record(record)
|
|
81
82
|
end
|
|
82
83
|
|
|
83
|
-
should "output record as
|
|
84
|
+
should "output a record as status info when status is given, with in-reply info" do
|
|
85
|
+
status = "Hi, @fooman! How are you doing?"
|
|
84
86
|
record = {
|
|
85
87
|
:user => "barman",
|
|
86
88
|
:status => {
|
|
87
89
|
:created_at => Time.at(1),
|
|
88
|
-
:text =>
|
|
90
|
+
:text => status,
|
|
89
91
|
:in_reply_to => "fooman"
|
|
90
92
|
}
|
|
91
93
|
}
|
|
92
94
|
Util.expects(:humanize_time_diff).returns([2, "secs"])
|
|
93
95
|
@output.expects(:puts).with(<<-END
|
|
94
96
|
barman, in reply to fooman, 2 secs ago:
|
|
95
|
-
|
|
97
|
+
#{status}
|
|
98
|
+
|
|
99
|
+
END
|
|
100
|
+
)
|
|
101
|
+
@io.show_record(record)
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
should "output a preview of a status" do
|
|
105
|
+
status = "@nick, check http://bit.ly/18rU_Vx"
|
|
106
|
+
@output.expects(:puts).with(<<-END
|
|
107
|
+
|
|
108
|
+
#{status}
|
|
96
109
|
|
|
97
110
|
END
|
|
98
111
|
)
|
|
99
|
-
@io.
|
|
112
|
+
@io.show_status_preview(status)
|
|
100
113
|
end
|
|
101
114
|
end
|
|
102
115
|
|
|
@@ -114,10 +127,10 @@ Hi, @fooman! How are you doing?
|
|
|
114
127
|
|
|
115
128
|
END
|
|
116
129
|
)
|
|
117
|
-
@io.
|
|
130
|
+
@io.show_record(record)
|
|
118
131
|
end
|
|
119
132
|
|
|
120
|
-
should "output record as
|
|
133
|
+
should "output a record as status info when status is given, without in-reply info" do
|
|
121
134
|
record = {
|
|
122
135
|
:user => "fooman",
|
|
123
136
|
:status => {
|
|
@@ -132,10 +145,10 @@ Wondering the meaning of life.
|
|
|
132
145
|
|
|
133
146
|
END
|
|
134
147
|
)
|
|
135
|
-
@io.
|
|
148
|
+
@io.show_record(record)
|
|
136
149
|
end
|
|
137
150
|
|
|
138
|
-
should "output record as
|
|
151
|
+
should "output a record as status info when status is given, with in-reply info" do
|
|
139
152
|
record = {
|
|
140
153
|
:user => "barman",
|
|
141
154
|
:status => {
|
|
@@ -151,7 +164,18 @@ Hi, \033[33m@fooman\033[0m! How are you doing?
|
|
|
151
164
|
|
|
152
165
|
END
|
|
153
166
|
)
|
|
154
|
-
@io.
|
|
167
|
+
@io.show_record(record)
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
should "output a preview of a status" do
|
|
171
|
+
status = "@nick, check http://bit.ly/18rU_Vx"
|
|
172
|
+
@output.expects(:puts).with(<<-END
|
|
173
|
+
|
|
174
|
+
\033[33m@nick\033[0m, check \033[36mhttp://bit.ly/18rU_Vx\033[0m
|
|
175
|
+
|
|
176
|
+
END
|
|
177
|
+
)
|
|
178
|
+
@io.show_status_preview(status)
|
|
155
179
|
end
|
|
156
180
|
|
|
157
181
|
should "highlight HTTP and HTTPS URIs in a status" do
|
|
@@ -169,7 +193,7 @@ Three links: \033[36mhttp://bit.ly/18rU_Vx\033[0m \033[36mhttp://is.gd/1qLk3\033
|
|
|
169
193
|
|
|
170
194
|
END
|
|
171
195
|
)
|
|
172
|
-
@io.
|
|
196
|
+
@io.show_record(record)
|
|
173
197
|
end
|
|
174
198
|
|
|
175
199
|
should "highlight nicks in a status" do
|
|
@@ -187,7 +211,7 @@ I salute you \033[33m@fooman\033[0m, \033[33m@barbaz\033[0m, and \033[33m@spoonm
|
|
|
187
211
|
|
|
188
212
|
END
|
|
189
213
|
)
|
|
190
|
-
@io.
|
|
214
|
+
@io.show_record(record)
|
|
191
215
|
end
|
|
192
216
|
end
|
|
193
217
|
|