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/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 initializing a client" do
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 "A client" do
50
+ context "At runtime, a client" do
45
51
  setup do
46
- @client = Client.new({ :username => "foo", :password => "bar" })
47
52
  @io = mock()
48
- @client.instance_variable_set(:@io, @io)
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
- statuses, records = create_test_statuses(
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
- RestClient.expects(:get) \
80
- .with("https://foo:bar@twitter.com/statuses/friends_timeline.json?#{@statuses_query_params}") \
81
- .returns(statuses.to_json)
82
- @io.expects(:show).with(records[0])
83
- @io.expects(:show).with(records[1])
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
- statuses, records = create_test_statuses(
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, @foo?",
94
- :in_reply_to => "foo"
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 => "@foo, doing nuttin'",
102
- :in_reply_to => "foo"
102
+ :text => "@#{@username}, doing nuttin'",
103
+ :in_reply_to => @username
103
104
  }
104
105
  }
105
106
  )
106
- RestClient.expects(:get) \
107
- .with("https://foo:bar@twitter.com/statuses/mentions.json?#{@statuses_query_params}") \
108
- .returns(statuses.to_json)
109
- @io.expects(:show).with(records[0])
110
- @io.expects(:show).with(records[1])
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, with the user identified by given argument" do
115
- statuses, records = create_test_statuses(
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 => "zanzibar",
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
- RestClient.expects(:get) \
126
- .with("https://foo:bar@twitter.com/statuses/user_timeline/zanzibar.json?#{@statuses_query_params}") \
127
- .returns(statuses.to_json)
128
- @io.expects(:show).with(records[0])
129
- @client.user("zanzibar")
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
- statuses, records = create_test_statuses(
135
+ status_records, gen_records = create_test_statuses(
134
136
  {
135
- :user => "foo",
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
- RestClient.expects(:get) \
144
- .with("https://foo:bar@twitter.com/statuses/user_timeline/foo.json?#{@statuses_query_params}") \
145
- .returns(statuses.to_json)
146
- @io.expects(:show).with(records[0])
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
- should "post a status update via argument, when positive confirmation" do
151
- statuses, records = create_test_statuses(
152
- {
153
- :user => "foo",
154
- :status => {
155
- :created_at => Time.at(1).to_s,
156
- :text => "wondering around",
157
- :in_reply_to => nil
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
- RestClient.expects(:post) \
162
- .with("https://foo:bar@twitter.com/statuses/update.json", {:status => "wondering about"}) \
163
- .returns(statuses[0].to_json)
164
- @io.expects(:confirm).with("Really send?").returns(true)
165
- @io.expects(:info).with("Sent status update.\n\n")
166
- @io.expects(:show).with(records[0])
167
- @client.update("wondering about")
168
- end
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
- should "post a status update via prompt, when positive confirmation" do
171
- statuses, records = create_test_statuses(
172
- { :user => "foo",
173
- :status => {
174
- :created_at => Time.at(1).to_s,
175
- :text => "wondering around",
176
- :in_reply_to => nil
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
- RestClient.expects(:post) \
181
- .with("https://foo:bar@twitter.com/statuses/update.json", {:status => "wondering about"}) \
182
- .returns(statuses[0].to_json)
183
- @io.expects(:prompt).with("Status update").returns("wondering about")
184
- @io.expects(:confirm).with("Really send?").returns(true)
185
- @io.expects(:info).with("Sent status update.\n\n")
186
- @io.expects(:show).with(records[0])
187
- @client.update
188
- end
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
- should "cancel a status update via argument, when negative confirmation" do
191
- RestClient.expects(:post).never
192
- @io.expects(:confirm).with("Really send?").returns(false)
193
- @io.expects(:info).with("Cancelled.")
194
- @io.expects(:show).never
195
- @client.update("wondering around")
196
- end
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
- should "cancel a status update via prompt, when negative confirmation" do
199
- RestClient.expects(:post).never
200
- @io.expects(:prompt).with("Status update").returns("wondering about")
201
- @io.expects(:confirm).with("Really send?").returns(false)
202
- @io.expects(:info).with("Cancelled.")
203
- @io.expects(:show).never
204
- @client.update
205
- end
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
- should "cancel a status update via argument, when empty status" do
208
- RestClient.expects(:post).never
209
- @io.expects(:confirm).never
210
- @io.expects(:info).with("Cancelled.")
211
- @io.expects(:show).never
212
- @client.update("")
213
- end
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
- should "cancel a status update via prompt, when empty status" do
216
- RestClient.expects(:post).never
217
- @io.expects(:prompt).with("Status update").returns("")
218
- @io.expects(:confirm).never
219
- @io.expects(:info).with("Cancelled.")
220
- @io.expects(:show).never
221
- @client.update
222
- end
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
- should "truncate a status update with too long argument and warn the user" do
225
- long_status_update = "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"
226
- truncated_status_update = "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"
227
- statuses, records = create_test_statuses(
228
- { :user => "foo",
229
- :status => {
230
- :created_at => Time.at(1).to_s,
231
- :text => truncated_status_update,
232
- :in_reply_to => nil
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
- RestClient.expects(:post) \
237
- .with("https://foo:bar@twitter.com/statuses/update.json", {:status => truncated_status_update}) \
238
- .returns(statuses[0].to_json)
239
- @io.expects(:warn).with("Status will be truncated: #{truncated_status_update}")
240
- @io.expects(:confirm).with("Really send?").returns(true)
241
- @io.expects(:info).with("Sent status update.\n\n")
242
- @io.expects(:show).with(records[0])
243
- @client.update(long_status_update)
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
- users, records = create_test_users(
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
- RestClient.expects(:get) \
266
- .with("https://foo:bar@twitter.com/statuses/friends/foo.json?#{@users_query_params}") \
267
- .returns(users.to_json)
268
- @io.expects(:show).with(records[0])
269
- @io.expects(:show).with(records[1])
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
- users, records = create_test_users(
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
- RestClient.expects(:get) \
293
- .with("https://foo:bar@twitter.com/statuses/followers/foo.json?#{@users_query_params}") \
294
- .returns(users.to_json)
295
- @io.expects(:show).with(records[0])
296
- @io.expects(:show).with(records[1])
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.show(record)
62
+ @io.show_record(record)
63
63
  end
64
64
 
65
- should "output record as a status when status is given, without in-reply info" do
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 => "Hi, @barman! Lulz woo!"
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
- Hi, @barman! Lulz woo!
77
+ #{status}
77
78
 
78
79
  END
79
80
  )
80
- @io.show(record)
81
+ @io.show_record(record)
81
82
  end
82
83
 
83
- should "output record as a status when status is given, with in-reply info" do
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 => "Hi, @fooman! How are you doing?",
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
- Hi, @fooman! How are you doing?
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.show(record)
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.show(record)
130
+ @io.show_record(record)
118
131
  end
119
132
 
120
- should "output record as a status when status is given, without in-reply info" do
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.show(record)
148
+ @io.show_record(record)
136
149
  end
137
150
 
138
- should "output record as a status when status is given, with in-reply info" do
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.show(record)
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.show(record)
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.show(record)
214
+ @io.show_record(record)
191
215
  end
192
216
  end
193
217