tweetwine 0.4.1 → 0.4.2
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 +6 -0
- data/Rakefile +22 -23
- data/lib/tweetwine/cli.rb +167 -165
- data/lib/tweetwine/config.rb +3 -2
- data/lib/tweetwine/exceptions.rb +1 -0
- data/lib/tweetwine/version.rb +1 -1
- data/project.rb +16 -16
- data/test/fixture/{config_example.yaml → config_integration.yaml} +0 -0
- data/test/fixture/oauth.rb +11 -11
- data/test/{test_helper.rb → helper.rb} +16 -7
- data/test/{example/authorization_example.rb → integration/authorization_test.rb} +17 -17
- data/test/integration/global_options_test.rb +67 -0
- data/test/integration/helper.rb +70 -0
- data/test/integration/invalid_config_file_test.rb +28 -0
- data/test/integration/search_statuses_test.rb +81 -0
- data/test/integration/show_followers_test.rb +24 -0
- data/test/integration/show_friends_test.rb +24 -0
- data/test/integration/show_home_test.rb +47 -0
- data/test/integration/show_mentions_test.rb +24 -0
- data/test/integration/show_user_test.rb +48 -0
- data/test/integration/update_status_test.rb +199 -0
- data/test/integration/use_http_proxy_test.rb +71 -0
- data/test/{example/user_help_example.rb → integration/user_help_test.rb} +36 -36
- data/test/unit/character_encoding_test.rb +19 -15
- data/test/unit/cli_test.rb +9 -10
- data/test/unit/config_test.rb +73 -71
- data/test/unit/helper.rb +108 -0
- data/test/unit/http_test.rb +39 -39
- data/test/unit/oauth_test.rb +15 -16
- data/test/unit/obfuscate_test.rb +4 -4
- data/test/unit/option_parser_test.rb +12 -12
- data/test/unit/promise_test.rb +10 -10
- data/test/unit/support_test.rb +44 -45
- data/test/unit/tweet_helper.rb +1 -1
- data/test/unit/tweet_test.rb +42 -42
- data/test/unit/twitter_test.rb +300 -303
- data/test/unit/ui_test.rb +310 -312
- data/test/unit/uri_test.rb +7 -7
- data/test/unit/url_shortener_test.rb +77 -79
- data/tweetwine.gemspec +6 -15
- metadata +55 -145
- data/test/example/example_helper.rb +0 -58
- data/test/example/global_options_example.rb +0 -64
- data/test/example/search_statuses_example.rb +0 -76
- data/test/example/show_followers_example.rb +0 -24
- data/test/example/show_friends_example.rb +0 -24
- data/test/example/show_home_example.rb +0 -44
- data/test/example/show_mentions_example.rb +0 -24
- data/test/example/show_user_example.rb +0 -44
- data/test/example/update_status_example.rb +0 -183
- data/test/example/use_http_proxy_example.rb +0 -68
- data/test/unit/unit_helper.rb +0 -111
data/test/unit/ui_test.rb
CHANGED
@@ -1,368 +1,333 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
-
require '
|
4
|
-
require 'tweet_helper'
|
3
|
+
require 'unit/helper'
|
4
|
+
require 'unit/tweet_helper'
|
5
5
|
|
6
|
-
module Tweetwine::Test
|
6
|
+
module Tweetwine::Test::Unit
|
7
7
|
|
8
|
-
class UITest <
|
8
|
+
class UITest < TestCase
|
9
9
|
include TweetHelper
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
end
|
11
|
+
before do
|
12
|
+
@in = mock
|
13
|
+
@out = mock
|
14
|
+
@err = mock
|
15
|
+
@ui = UI.new({ :in => @in, :out => @out, :err => @err })
|
16
|
+
end
|
18
17
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
18
|
+
it "outputs prompt and return input as trimmed" do
|
19
|
+
@out.expects(:print).with("The answer: ")
|
20
|
+
@in.expects(:gets).returns(" 42 ")
|
21
|
+
assert_equal "42", @ui.prompt("The answer")
|
22
|
+
end
|
24
23
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
24
|
+
it "outputs info message" do
|
25
|
+
@out.expects(:puts).with("foo")
|
26
|
+
@ui.info("foo")
|
27
|
+
end
|
29
28
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
29
|
+
it "outputs info message in process style when given a block" do
|
30
|
+
inform = sequence('inform')
|
31
|
+
@out.expects(:print).with("processing...").in_sequence(inform)
|
32
|
+
@out.expects(:puts).with(" done.").in_sequence(inform)
|
33
|
+
@ui.info("processing...") { true }
|
34
|
+
end
|
36
35
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
36
|
+
it "outputs empty line as info message" do
|
37
|
+
@out.expects(:puts).with("\n")
|
38
|
+
@ui.info
|
39
|
+
end
|
41
40
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
41
|
+
it "outputs warning message" do
|
42
|
+
@out.expects(:puts).with("Warning: monkey patching ahead")
|
43
|
+
@ui.warn("monkey patching ahead")
|
44
|
+
end
|
46
45
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
46
|
+
it "outputs error message" do
|
47
|
+
@err.expects(:puts).with("ERROR: Invalid monkey patch")
|
48
|
+
@ui.error("Invalid monkey patch")
|
49
|
+
end
|
51
50
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
51
|
+
it "confirms action, with positive answer" do
|
52
|
+
@out.expects(:print).with("Fire nukes? [yN] ")
|
53
|
+
@in.expects(:gets).returns("y")
|
54
|
+
assert_equal true, @ui.confirm("Fire nukes?")
|
55
|
+
end
|
57
56
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
57
|
+
it "confirms action, with negative answer" do
|
58
|
+
@out.expects(:print).with("Fire nukes? [yN] ")
|
59
|
+
@in.expects(:gets).returns("n")
|
60
|
+
assert_equal false, @ui.confirm("Fire nukes?")
|
61
|
+
end
|
63
62
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
63
|
+
it "confirms action, with default answer" do
|
64
|
+
@out.expects(:print).with("Fire nukes? [yN] ")
|
65
|
+
@in.expects(:gets).returns("")
|
66
|
+
assert_equal false, @ui.confirm("Fire nukes?")
|
67
|
+
end
|
69
68
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
69
|
+
describe "when colors are disabled" do
|
70
|
+
before do
|
71
|
+
@ui = UI.new({:in => @in, :out => @out, :colors => false })
|
72
|
+
end
|
74
73
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
74
|
+
it "outputs tweet with just user info" do
|
75
|
+
from_user = "fooman"
|
76
|
+
tweet = create_tweet(:from_user => from_user)
|
77
|
+
@out.expects(:puts).with(<<-END
|
79
78
|
#{from_user}
|
80
79
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
80
|
+
END
|
81
|
+
)
|
82
|
+
@ui.show_tweet(tweet)
|
83
|
+
end
|
85
84
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
85
|
+
it "outputs regular tweet" do
|
86
|
+
from_user = "fooman"
|
87
|
+
status = "Hi, @barman! Lulz woo! #hellos"
|
88
|
+
time = 2
|
89
|
+
tweet = create_tweet(
|
90
|
+
:from_user => from_user,
|
91
|
+
:status => status,
|
92
|
+
:created_at => create_timestamp(time)
|
93
|
+
)
|
94
|
+
@out.expects(:puts).with(<<-END
|
96
95
|
#{from_user}, #{time} sec ago:
|
97
96
|
#{status}
|
98
97
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
98
|
+
END
|
99
|
+
)
|
100
|
+
show_tweet_at_default_time(tweet)
|
101
|
+
end
|
103
102
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
103
|
+
it "outputs replying tweet" do
|
104
|
+
from_user = "barman"
|
105
|
+
to_user = "fooman"
|
106
|
+
status = "Hi, @#{to_user}! How are you doing?"
|
107
|
+
tweet = create_tweet(
|
108
|
+
:from_user => from_user,
|
109
|
+
:status => status,
|
110
|
+
:to_user => to_user
|
111
|
+
)
|
112
|
+
@out.expects(:puts).with(<<-END
|
114
113
|
#{from_user}, in reply to #{to_user}, 0 sec ago:
|
115
114
|
#{status}
|
116
115
|
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
116
|
+
END
|
117
|
+
)
|
118
|
+
show_tweet_at_default_time(tweet)
|
119
|
+
end
|
121
120
|
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
121
|
+
it "outputs regular retweet" do
|
122
|
+
from_user = "barman"
|
123
|
+
rt_user = "fooman"
|
124
|
+
status = "status worth retweeting"
|
125
|
+
tweet = create_tweet(
|
126
|
+
:from_user => from_user,
|
127
|
+
:status => status,
|
128
|
+
:rt_user => rt_user
|
129
|
+
)
|
130
|
+
@out.expects(:puts).with(<<-END
|
132
131
|
#{rt_user} RT #{from_user}, 0 sec ago:
|
133
132
|
#{status}
|
134
133
|
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
134
|
+
END
|
135
|
+
)
|
136
|
+
show_tweet_at_default_time(tweet)
|
137
|
+
end
|
139
138
|
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
139
|
+
it "outputs replying retweet" do
|
140
|
+
from_user = "barman"
|
141
|
+
to_user = "jackman"
|
142
|
+
rt_user = "fooman"
|
143
|
+
status = "@#{to_user}, reply worth retweeting"
|
144
|
+
tweet = create_tweet(
|
145
|
+
:from_user => from_user,
|
146
|
+
:to_user => to_user,
|
147
|
+
:status => status,
|
148
|
+
:rt_user => rt_user
|
149
|
+
)
|
150
|
+
@out.expects(:puts).with(<<-END
|
152
151
|
#{rt_user} RT #{from_user}, in reply to #{to_user}, 0 sec ago:
|
153
152
|
#{status}
|
154
153
|
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
154
|
+
END
|
155
|
+
)
|
156
|
+
show_tweet_at_default_time(tweet)
|
157
|
+
end
|
159
158
|
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
159
|
+
it "unescapes HTML in a status" do
|
160
|
+
from_user = "fooman"
|
161
|
+
escaped_status = "apple > orange & grapefruit < banana"
|
162
|
+
unescaped_status = "apple > orange & grapefruit < banana"
|
163
|
+
tweet = create_tweet(
|
164
|
+
:from_user => from_user,
|
165
|
+
:status => escaped_status
|
166
|
+
)
|
167
|
+
@out.expects(:puts).with(<<-END
|
169
168
|
#{from_user}, 0 sec ago:
|
170
169
|
#{unescaped_status}
|
171
170
|
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
171
|
+
END
|
172
|
+
)
|
173
|
+
show_tweet_at_default_time(tweet)
|
174
|
+
end
|
176
175
|
|
177
|
-
|
178
|
-
|
179
|
-
|
176
|
+
it "outputs a preview of a status" do
|
177
|
+
status = "@nick, check http://bit.ly/18rU_Vx"
|
178
|
+
@out.expects(:puts).with(<<-END
|
180
179
|
|
181
180
|
#{status}
|
182
181
|
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
end
|
182
|
+
END
|
183
|
+
)
|
184
|
+
@ui.show_status_preview(status)
|
187
185
|
end
|
186
|
+
end
|
188
187
|
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
188
|
+
describe "when colors are enabled" do
|
189
|
+
before do
|
190
|
+
@ui = UI.new({:in => @in, :out => @out, :colors => true})
|
191
|
+
end
|
193
192
|
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
193
|
+
it "outputs tweet with just user info" do
|
194
|
+
from_user = "fooman"
|
195
|
+
tweet = create_tweet(:from_user => from_user)
|
196
|
+
@out.expects(:puts).with(<<-END
|
198
197
|
\e[32m#{from_user}\e[0m
|
199
198
|
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
199
|
+
END
|
200
|
+
)
|
201
|
+
@ui.show_tweet(tweet)
|
202
|
+
end
|
204
203
|
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
204
|
+
it "outputs regular tweet" do
|
205
|
+
from_user = "fooman"
|
206
|
+
status = "Wondering about the meaning of life."
|
207
|
+
tweet = create_tweet(
|
208
|
+
:from_user => from_user,
|
209
|
+
:status => status
|
210
|
+
)
|
211
|
+
@out.expects(:puts).with(<<-END
|
213
212
|
\e[32m#{from_user}\e[0m, 0 sec ago:
|
214
213
|
#{status}
|
215
214
|
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
215
|
+
END
|
216
|
+
)
|
217
|
+
show_tweet_at_default_time(tweet)
|
218
|
+
end
|
220
219
|
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
220
|
+
it "outputs replying tweet" do
|
221
|
+
from_user = "barman"
|
222
|
+
to_user = "fooman"
|
223
|
+
tweet = create_tweet(
|
224
|
+
:from_user => from_user,
|
225
|
+
:status => "@#{to_user}! How are you doing?",
|
226
|
+
:to_user => to_user
|
227
|
+
)
|
228
|
+
@out.expects(:puts).with(<<-END
|
230
229
|
\e[32m#{from_user}\e[0m, in reply to \e[32m#{to_user}\e[0m, 0 sec ago:
|
231
230
|
\e[33m@#{to_user}\e[0m! How are you doing?
|
232
231
|
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
232
|
+
END
|
233
|
+
)
|
234
|
+
show_tweet_at_default_time(tweet)
|
235
|
+
end
|
237
236
|
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
237
|
+
it "outputs regular retweet" do
|
238
|
+
from_user = "barman"
|
239
|
+
rt_user = "fooman"
|
240
|
+
status = "status worth retweeting"
|
241
|
+
tweet = create_tweet(
|
242
|
+
:from_user => from_user,
|
243
|
+
:status => status,
|
244
|
+
:rt_user => rt_user
|
245
|
+
)
|
246
|
+
@out.expects(:puts).with(<<-END
|
248
247
|
\e[32m#{rt_user}\e[0m RT \e[32m#{from_user}\e[0m, 0 sec ago:
|
249
248
|
#{status}
|
250
249
|
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
250
|
+
END
|
251
|
+
)
|
252
|
+
show_tweet_at_default_time(tweet)
|
253
|
+
end
|
255
254
|
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
255
|
+
it "outputs replying retweet" do
|
256
|
+
from_user = "barman"
|
257
|
+
to_user = "jackman"
|
258
|
+
rt_user = "fooman"
|
259
|
+
tweet = create_tweet(
|
260
|
+
:from_user => from_user,
|
261
|
+
:to_user => to_user,
|
262
|
+
:status => "@#{to_user}, reply worth retweeting",
|
263
|
+
:rt_user => rt_user
|
264
|
+
)
|
265
|
+
@out.expects(:puts).with(<<-END
|
267
266
|
\e[32m#{rt_user}\e[0m RT \e[32m#{from_user}\e[0m, in reply to \e[32m#{to_user}\e[0m, 0 sec ago:
|
268
267
|
\e[33m@#{to_user}\e[0m, reply worth retweeting
|
269
268
|
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
269
|
+
END
|
270
|
+
)
|
271
|
+
show_tweet_at_default_time(tweet)
|
272
|
+
end
|
274
273
|
|
275
|
-
|
276
|
-
|
277
|
-
|
274
|
+
it "outputs a preview of a status" do
|
275
|
+
status = "@nick, check http://bit.ly/18rU_Vx"
|
276
|
+
@out.expects(:puts).with(<<-END
|
278
277
|
|
279
278
|
\e[33m@nick\e[0m, check \e[36mhttp://bit.ly/18rU_Vx\e[0m
|
280
279
|
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
280
|
+
END
|
281
|
+
)
|
282
|
+
@ui.show_status_preview(status)
|
283
|
+
end
|
285
284
|
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
285
|
+
it "highlights hashtags in a status" do
|
286
|
+
from_user = "barman"
|
287
|
+
hashtags = %w{#slang #beignHappy}
|
288
|
+
tweet = create_tweet(
|
289
|
+
:from_user => from_user,
|
290
|
+
:status => "Lulz, so happy! #{hashtags[0]} #{hashtags[1]}"
|
291
|
+
)
|
292
|
+
@out.expects(:puts).with(<<-END
|
294
293
|
\e[32m#{from_user}\e[0m, 0 sec ago:
|
295
294
|
Lulz, so happy! \e[35m#{hashtags[0]}\e[0m \e[35m#{hashtags[1]}\e[0m
|
296
295
|
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
%w{http://is.gd/1qLk3 http://is.gd/1qLk3?id=foo}.each do |url|
|
303
|
-
should "highlight HTTP and HTTPS URLs in a status, given #{url}" do
|
304
|
-
from_user = "barman"
|
305
|
-
tweet = create_tweet(
|
306
|
-
:from_user => from_user,
|
307
|
-
:status => "New Rails³ - #{url}"
|
308
|
-
)
|
309
|
-
@out.expects(:puts).with(<<-END
|
310
|
-
\e[32m#{from_user}\e[0m, 0 sec ago:
|
311
|
-
New Rails³ - \e[36m#{url}\e[0m
|
312
|
-
|
313
|
-
END
|
314
|
-
)
|
315
|
-
show_tweet_at_default_time(tweet)
|
316
|
-
end
|
317
|
-
end
|
318
|
-
|
319
|
-
[
|
320
|
-
%w{http://is.gd/1qLk3 http://is.gd/1qLk3},
|
321
|
-
%w{http://is.gd/1qLk3 http://is.gd/1q}
|
322
|
-
].each do |(first_url, second_url)|
|
323
|
-
should "highlight HTTP and HTTPS URLs in a status, given #{first_url} and #{second_url}" do
|
324
|
-
from_user = "barman"
|
325
|
-
tweet = create_tweet(
|
326
|
-
:from_user => from_user,
|
327
|
-
:status => "Links: #{first_url} and #{second_url} np"
|
328
|
-
)
|
329
|
-
@out.expects(:puts).with(<<-END
|
330
|
-
\e[32m#{from_user}\e[0m, 0 sec ago:
|
331
|
-
Links: \e[36m#{first_url}\e[0m and \e[36m#{second_url}\e[0m np
|
332
|
-
|
333
|
-
END
|
334
|
-
)
|
335
|
-
show_tweet_at_default_time(tweet)
|
336
|
-
end
|
337
|
-
end
|
296
|
+
END
|
297
|
+
)
|
298
|
+
show_tweet_at_default_time(tweet)
|
299
|
+
end
|
338
300
|
|
339
|
-
|
301
|
+
%w{http://is.gd/1qLk3 http://is.gd/1qLk3?id=foo}.each do |url|
|
302
|
+
it "highlights HTTP and HTTPS URLs in a status, given #{url}" do
|
340
303
|
from_user = "barman"
|
341
|
-
users = %w{@fooman @barbaz @spoonman}
|
342
304
|
tweet = create_tweet(
|
343
305
|
:from_user => from_user,
|
344
|
-
:status => "
|
306
|
+
:status => "New Rails³ - #{url}"
|
345
307
|
)
|
346
308
|
@out.expects(:puts).with(<<-END
|
347
309
|
\e[32m#{from_user}\e[0m, 0 sec ago:
|
348
|
-
|
310
|
+
New Rails³ - \e[36m#{url}\e[0m
|
349
311
|
|
350
312
|
END
|
351
313
|
)
|
352
314
|
show_tweet_at_default_time(tweet)
|
353
315
|
end
|
316
|
+
end
|
354
317
|
|
355
|
-
|
318
|
+
[
|
319
|
+
%w{http://is.gd/1qLk3 http://is.gd/1qLk3},
|
320
|
+
%w{http://is.gd/1qLk3 http://is.gd/1q}
|
321
|
+
].each do |(first_url, second_url)|
|
322
|
+
it "highlights HTTP and HTTPS URLs in a status, given #{first_url} and #{second_url}" do
|
356
323
|
from_user = "barman"
|
357
|
-
users = %w{@fooman @barbaz}
|
358
|
-
email = "barbaz@foo.net"
|
359
324
|
tweet = create_tweet(
|
360
325
|
:from_user => from_user,
|
361
|
-
:status => "
|
326
|
+
:status => "Links: #{first_url} and #{second_url} np"
|
362
327
|
)
|
363
328
|
@out.expects(:puts).with(<<-END
|
364
329
|
\e[32m#{from_user}\e[0m, 0 sec ago:
|
365
|
-
|
330
|
+
Links: \e[36m#{first_url}\e[0m and \e[36m#{second_url}\e[0m np
|
366
331
|
|
367
332
|
END
|
368
333
|
)
|
@@ -370,55 +335,88 @@ Hi, \e[33m#{users[0]}\e[0m! You should notify \e[33m#{users[1]}\e[0m, #{email}
|
|
370
335
|
end
|
371
336
|
end
|
372
337
|
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
338
|
+
it "highlights usernames in a status" do
|
339
|
+
from_user = "barman"
|
340
|
+
users = %w{@fooman @barbaz @spoonman}
|
341
|
+
tweet = create_tweet(
|
342
|
+
:from_user => from_user,
|
343
|
+
:status => "I salute you #{users[0]}, #{users[1]}, and #{users[2]}!"
|
344
|
+
)
|
345
|
+
@out.expects(:puts).with(<<-END
|
346
|
+
\e[32m#{from_user}\e[0m, 0 sec ago:
|
347
|
+
I salute you \e[33m#{users[0]}\e[0m, \e[33m#{users[1]}\e[0m, and \e[33m#{users[2]}\e[0m!
|
348
|
+
|
349
|
+
END
|
350
|
+
)
|
351
|
+
show_tweet_at_default_time(tweet)
|
352
|
+
end
|
353
|
+
|
354
|
+
it "does not highlight email addresses as usernames in a status" do
|
355
|
+
from_user = "barman"
|
356
|
+
users = %w{@fooman @barbaz}
|
357
|
+
email = "barbaz@foo.net"
|
358
|
+
tweet = create_tweet(
|
359
|
+
:from_user => from_user,
|
360
|
+
:status => "Hi, #{users[0]}! You should notify #{users[1]}, #{email}"
|
361
|
+
)
|
362
|
+
@out.expects(:puts).with(<<-END
|
363
|
+
\e[32m#{from_user}\e[0m, 0 sec ago:
|
364
|
+
Hi, \e[33m#{users[0]}\e[0m! You should notify \e[33m#{users[1]}\e[0m, #{email}
|
365
|
+
|
366
|
+
END
|
367
|
+
)
|
368
|
+
show_tweet_at_default_time(tweet)
|
369
|
+
end
|
370
|
+
end
|
371
|
+
|
372
|
+
describe "when outputting a collection of tweets" do
|
373
|
+
before do
|
374
|
+
users_and_times = [
|
375
|
+
['first', 11],
|
376
|
+
['second', 12],
|
377
|
+
['third', 13]
|
378
|
+
]
|
379
|
+
statuses = users_and_times.map { |(user, _)| "Hi, I'm #{user}." }
|
380
|
+
users_and_statuses = users_and_times.zip(statuses)
|
381
|
+
@outputs = Hash[users_and_statuses.map { |(user, time), status|
|
382
|
+
output = <<-END
|
384
383
|
#{user}, #{time} sec ago:
|
385
384
|
#{status}
|
386
385
|
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
386
|
+
END
|
387
|
+
[user.to_sym, output]
|
388
|
+
}]
|
389
|
+
@tweets = users_and_statuses.map { |(user, time), status| create_tweet(
|
390
|
+
:from_user => user,
|
391
|
+
:status => status,
|
392
|
+
:created_at => create_timestamp(time)
|
393
|
+
)}
|
394
|
+
end
|
396
395
|
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
end
|
402
|
-
show_tweets_at_default_time(@tweets)
|
396
|
+
it "outputs tweets in normal order" do
|
397
|
+
@ui = UI.new({ :out => @out, :show_reverse => false })
|
398
|
+
[:first, :second, :third].each do |user|
|
399
|
+
@out.expects(:puts).with(@outputs[user])
|
403
400
|
end
|
401
|
+
show_tweets_at_default_time(@tweets)
|
402
|
+
end
|
404
403
|
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
end
|
410
|
-
show_tweets_at_default_time(@tweets)
|
404
|
+
it "outputs tweets in reverse order" do
|
405
|
+
@ui = UI.new({ :out => @out, :show_reverse => true })
|
406
|
+
[:third, :second, :first].each do |user|
|
407
|
+
@out.expects(:puts).with(@outputs[user])
|
411
408
|
end
|
409
|
+
show_tweets_at_default_time(@tweets)
|
412
410
|
end
|
413
411
|
end
|
414
412
|
|
415
|
-
|
413
|
+
describe "username regex" do
|
416
414
|
[
|
417
415
|
['@nick', 'normal'],
|
418
416
|
['@nick_man', 'underscore separated'],
|
419
417
|
[' @nick', 'beginning with space']
|
420
418
|
].each do |(nick, desc)|
|
421
|
-
|
419
|
+
it "matches proper username reference, case #{desc}" do
|
422
420
|
assert_full_match UI::USERNAME_REGEX, nick
|
423
421
|
end
|
424
422
|
end
|
@@ -433,19 +431,19 @@ Hi, \e[33m#{users[0]}\e[0m! You should notify \e[33m#{users[1]}\e[0m, #{email}
|
|
433
431
|
['man @nick', 'space separated'],
|
434
432
|
['man@nick', 'prefix in between']
|
435
433
|
].each do |(no_nick, desc)|
|
436
|
-
|
434
|
+
it "does not match an inproper username reference, case #{desc}" do
|
437
435
|
assert_no_full_match UI::USERNAME_REGEX, no_nick
|
438
436
|
end
|
439
437
|
end
|
440
438
|
end
|
441
439
|
|
442
|
-
|
440
|
+
describe "hashtag regex" do
|
443
441
|
[
|
444
442
|
['#mayhem', 'normal'],
|
445
443
|
['#friday_mayhem', 'underscore separated'],
|
446
444
|
['#friday-mayhem', 'dash separated']
|
447
445
|
].each do |(hashtag, desc)|
|
448
|
-
|
446
|
+
it "matches a proper hashtag reference, case #{desc}" do
|
449
447
|
assert_full_match UI::HASHTAG_REGEX, hashtag
|
450
448
|
end
|
451
449
|
end
|
@@ -457,7 +455,7 @@ Hi, \e[33m#{users[0]}\e[0m! You should notify \e[33m#{users[1]}\e[0m, #{email}
|
|
457
455
|
['#mayhem ', 'ending with space'],
|
458
456
|
[' #mayhem ', 'surrounded with space']
|
459
457
|
].each do |(no_hashtag, desc)|
|
460
|
-
|
458
|
+
it "does not match an inproper hashtag reference, case #{desc}" do
|
461
459
|
assert_no_full_match UI::HASHTAG_REGEX, no_hashtag
|
462
460
|
end
|
463
461
|
end
|