tweetwine 0.2.5 → 0.2.7
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +30 -17
- data/README.rdoc +16 -17
- data/Rakefile +2 -0
- data/bin/tweetwine +3 -68
- data/example/example_helper.rb +31 -41
- data/example/fixtures/{statuses.json → home.json} +0 -0
- data/example/fixtures/mentions.json +1 -0
- data/example/fixtures/search.json +1 -0
- data/example/fixtures/update.json +1 -0
- data/example/fixtures/user.json +1 -0
- data/example/fixtures/users.json +1 -0
- data/example/search_statuses_example.rb +36 -0
- data/example/show_followers_example.rb +23 -0
- data/example/show_friends_example.rb +23 -0
- data/example/show_home_example.rb +51 -0
- data/example/show_mentions_example.rb +23 -0
- data/example/show_metadata_example.rb +54 -7
- data/example/show_user_example.rb +37 -0
- data/example/update_status_example.rb +65 -0
- data/lib/tweetwine/cli.rb +241 -0
- data/lib/tweetwine/client.rb +94 -57
- data/lib/tweetwine/io.rb +39 -28
- data/lib/tweetwine/meta.rb +1 -1
- data/lib/tweetwine/retrying_http.rb +93 -0
- data/lib/tweetwine/startup_config.rb +14 -15
- data/lib/tweetwine/url_shortener.rb +13 -8
- data/lib/tweetwine/util.rb +14 -0
- data/lib/tweetwine.rb +2 -1
- data/test/cli_test.rb +16 -0
- data/test/client_test.rb +275 -205
- data/test/fixtures/test_config.yaml +2 -1
- data/test/io_test.rb +89 -62
- data/test/retrying_http_test.rb +127 -0
- data/test/startup_config_test.rb +52 -27
- data/test/test_helper.rb +32 -17
- data/test/url_shortener_test.rb +18 -18
- data/test/util_test.rb +145 -47
- metadata +20 -7
- data/example/show_latest_statuses_example.rb +0 -45
- data/lib/tweetwine/rest_client_wrapper.rb +0 -37
- data/test/rest_client_wrapper_test.rb +0 -68
data/test/io_test.rb
CHANGED
@@ -46,13 +46,14 @@ class IOTest < Test::Unit::TestCase
|
|
46
46
|
|
47
47
|
context "with colorization disabled" do
|
48
48
|
setup do
|
49
|
-
@io = IO.new({ :input => @input, :output => @output, :
|
49
|
+
@io = IO.new({ :input => @input, :output => @output, :colors => false })
|
50
50
|
end
|
51
51
|
|
52
52
|
should "output a record as user info when no status is given" do
|
53
|
-
|
53
|
+
from_user = "fooman"
|
54
|
+
record = { :from_user => from_user }
|
54
55
|
@output.expects(:puts).with(<<-END
|
55
|
-
|
56
|
+
#{from_user}
|
56
57
|
|
57
58
|
END
|
58
59
|
)
|
@@ -60,17 +61,17 @@ fooman
|
|
60
61
|
end
|
61
62
|
|
62
63
|
should "output a record as status info when status is given, without in-reply info" do
|
64
|
+
from_user = "fooman"
|
63
65
|
status = "Hi, @barman! Lulz woo! #hellos"
|
64
66
|
record = {
|
65
|
-
:
|
66
|
-
:status
|
67
|
-
|
68
|
-
|
69
|
-
}
|
67
|
+
:from_user => from_user,
|
68
|
+
:status => status,
|
69
|
+
:created_at => Time.at(1),
|
70
|
+
:to_user => nil
|
70
71
|
}
|
71
72
|
Util.expects(:humanize_time_diff).returns([2, "secs"])
|
72
73
|
@output.expects(:puts).with(<<-END
|
73
|
-
|
74
|
+
#{from_user}, 2 secs ago:
|
74
75
|
#{status}
|
75
76
|
|
76
77
|
END
|
@@ -79,18 +80,18 @@ fooman, 2 secs ago:
|
|
79
80
|
end
|
80
81
|
|
81
82
|
should "output a record as status info when status is given, with in-reply info" do
|
83
|
+
from_user = "barman"
|
84
|
+
to_user = "fooman"
|
82
85
|
status = "Hi, @fooman! How are you doing?"
|
83
86
|
record = {
|
84
|
-
:
|
85
|
-
:status
|
86
|
-
|
87
|
-
|
88
|
-
:in_reply_to => "fooman"
|
89
|
-
}
|
87
|
+
:from_user => from_user,
|
88
|
+
:status => status,
|
89
|
+
:created_at => Time.at(1),
|
90
|
+
:to_user => to_user
|
90
91
|
}
|
91
92
|
Util.expects(:humanize_time_diff).returns([2, "secs"])
|
92
93
|
@output.expects(:puts).with(<<-END
|
93
|
-
|
94
|
+
#{from_user}, in reply to #{to_user}, 2 secs ago:
|
94
95
|
#{status}
|
95
96
|
|
96
97
|
END
|
@@ -112,13 +113,14 @@ barman, in reply to fooman, 2 secs ago:
|
|
112
113
|
|
113
114
|
context "with colorization enabled" do
|
114
115
|
setup do
|
115
|
-
@io = IO.new({ :input => @input, :output => @output, :
|
116
|
+
@io = IO.new({ :input => @input, :output => @output, :colors => true })
|
116
117
|
end
|
117
118
|
|
118
119
|
should "output a record as user info when no status is given" do
|
119
|
-
|
120
|
+
from_user = "fooman"
|
121
|
+
record = { :from_user => from_user }
|
120
122
|
@output.expects(:puts).with(<<-END
|
121
|
-
\e[
|
123
|
+
\e[32m#{from_user}\e[0m
|
122
124
|
|
123
125
|
END
|
124
126
|
)
|
@@ -126,17 +128,18 @@ barman, in reply to fooman, 2 secs ago:
|
|
126
128
|
end
|
127
129
|
|
128
130
|
should "output a record as status info when status is given, without in-reply info" do
|
131
|
+
from_user = "fooman"
|
132
|
+
status = "Wondering about the meaning of life."
|
129
133
|
record = {
|
130
|
-
:
|
131
|
-
:status
|
132
|
-
|
133
|
-
|
134
|
-
}
|
134
|
+
:from_user => from_user,
|
135
|
+
:status => status,
|
136
|
+
:created_at => Time.at(1),
|
137
|
+
:to_user => nil
|
135
138
|
}
|
136
139
|
Util.expects(:humanize_time_diff).returns([2, "secs"])
|
137
140
|
@output.expects(:puts).with(<<-END
|
138
|
-
\e[
|
139
|
-
|
141
|
+
\e[32m#{from_user}\e[0m, 2 secs ago:
|
142
|
+
#{status}
|
140
143
|
|
141
144
|
END
|
142
145
|
)
|
@@ -144,18 +147,18 @@ Wondering the meaning of life.
|
|
144
147
|
end
|
145
148
|
|
146
149
|
should "output a record as status info when status is given, with in-reply info" do
|
150
|
+
from_user = "barman"
|
151
|
+
to_user = "fooman"
|
147
152
|
record = {
|
148
|
-
:
|
149
|
-
:status
|
150
|
-
|
151
|
-
|
152
|
-
:in_reply_to => "fooman"
|
153
|
-
}
|
153
|
+
:from_user => from_user,
|
154
|
+
:status => "@#{to_user}! How are you doing?",
|
155
|
+
:created_at => Time.at(1),
|
156
|
+
:to_user => to_user
|
154
157
|
}
|
155
158
|
Util.expects(:humanize_time_diff).returns([2, "secs"])
|
156
159
|
@output.expects(:puts).with(<<-END
|
157
|
-
\e[
|
158
|
-
|
160
|
+
\e[32m#{from_user}\e[0m, in reply to \e[32m#{to_user}\e[0m, 2 secs ago:
|
161
|
+
\e[33m@#{to_user}\e[0m! How are you doing?
|
159
162
|
|
160
163
|
END
|
161
164
|
)
|
@@ -173,18 +176,38 @@ Hi, \e[33m@fooman\e[0m! How are you doing? \e[35m#hellos\e[0m
|
|
173
176
|
@io.show_status_preview(status)
|
174
177
|
end
|
175
178
|
|
179
|
+
should "highlight hashtags in a status" do
|
180
|
+
from_user = "barman"
|
181
|
+
hashtags = %w{#slang #beignHappy}
|
182
|
+
record = {
|
183
|
+
:from_user => from_user,
|
184
|
+
:status => "Lulz, so happy! #{hashtags[0]} #{hashtags[1]}",
|
185
|
+
:created_at => Time.at(1),
|
186
|
+
:to_user => nil
|
187
|
+
}
|
188
|
+
Util.expects(:humanize_time_diff).returns([2, "secs"])
|
189
|
+
@output.expects(:puts).with(<<-END
|
190
|
+
\e[32m#{from_user}\e[0m, 2 secs ago:
|
191
|
+
Lulz, so happy! \e[35m#{hashtags[0]}\e[0m \e[35m#{hashtags[1]}\e[0m
|
192
|
+
|
193
|
+
END
|
194
|
+
)
|
195
|
+
@io.show_record(record)
|
196
|
+
end
|
197
|
+
|
176
198
|
should "highlight HTTP and HTTPS URLs in a status" do
|
199
|
+
from_user = "barman"
|
200
|
+
links = %w{http://bit.ly/18rU_Vx http://is.gd/1qLk3 https://is.gd/2rLk4}
|
177
201
|
record = {
|
178
|
-
:
|
179
|
-
:status
|
180
|
-
|
181
|
-
|
182
|
-
}
|
202
|
+
:from_user => from_user,
|
203
|
+
:status => "Three links: #{links[0]} #{links[1]} and #{links[2]}",
|
204
|
+
:created_at => Time.at(1),
|
205
|
+
:to_user => nil
|
183
206
|
}
|
184
207
|
Util.expects(:humanize_time_diff).returns([2, "secs"])
|
185
208
|
@output.expects(:puts).with(<<-END
|
186
|
-
\e[
|
187
|
-
Three links: \e[
|
209
|
+
\e[32m#{from_user}\e[0m, 2 secs ago:
|
210
|
+
Three links: \e[36m#{links[0]}\e[0m \e[36m#{links[1]}\e[0m and \e[36m#{links[2]}\e[0m
|
188
211
|
|
189
212
|
END
|
190
213
|
)
|
@@ -192,17 +215,18 @@ Three links: \e[36mhttp://bit.ly/18rU_Vx\e[0m \e[36mhttp://is.gd/1qLk3\e[0m and
|
|
192
215
|
end
|
193
216
|
|
194
217
|
should "highlight HTTP and HTTPS URLs in a status, even if duplicates" do
|
218
|
+
from_user = "barman"
|
219
|
+
link = "http://is.gd/1qLk3"
|
195
220
|
record = {
|
196
|
-
:
|
197
|
-
:status
|
198
|
-
|
199
|
-
|
200
|
-
}
|
221
|
+
:from_user => from_user,
|
222
|
+
:status => "Duplicate links: #{link} and #{link}",
|
223
|
+
:created_at => Time.at(1),
|
224
|
+
:to_user => nil
|
201
225
|
}
|
202
226
|
Util.expects(:humanize_time_diff).returns([2, "secs"])
|
203
227
|
@output.expects(:puts).with(<<-END
|
204
|
-
\e[
|
205
|
-
Duplicate links: \e[
|
228
|
+
\e[32m#{from_user}\e[0m, 2 secs ago:
|
229
|
+
Duplicate links: \e[36m#{link}\e[0m and \e[36m#{link}\e[0m
|
206
230
|
|
207
231
|
END
|
208
232
|
)
|
@@ -210,17 +234,18 @@ Duplicate links: \e[36mhttp://is.gd/1qLk3\e[0m and \e[36mhttp://is.gd/1qLk3\e[0m
|
|
210
234
|
end
|
211
235
|
|
212
236
|
should "highlight usernames in a status" do
|
237
|
+
from_user = "barman"
|
238
|
+
users = %w{@fooman @barbaz @spoonman}
|
213
239
|
record = {
|
214
|
-
:
|
215
|
-
:status
|
216
|
-
|
217
|
-
|
218
|
-
}
|
240
|
+
:from_user => from_user,
|
241
|
+
:status => "I salute you #{users[0]}, #{users[1]}, and #{users[2]}!",
|
242
|
+
:created_at => Time.at(1),
|
243
|
+
:to_user => nil
|
219
244
|
}
|
220
245
|
Util.expects(:humanize_time_diff).returns([2, "secs"])
|
221
246
|
@output.expects(:puts).with(<<-END
|
222
|
-
\e[
|
223
|
-
I salute you \e[33m
|
247
|
+
\e[32m#{from_user}\e[0m, 2 secs ago:
|
248
|
+
I salute you \e[33m#{users[0]}\e[0m, \e[33m#{users[1]}\e[0m, and \e[33m#{users[2]}\e[0m!
|
224
249
|
|
225
250
|
END
|
226
251
|
)
|
@@ -228,17 +253,19 @@ I salute you \e[33m@fooman\e[0m, \e[33m@barbaz\e[0m, and \e[33m@spoonman\e[0m!
|
|
228
253
|
end
|
229
254
|
|
230
255
|
should "not highlight email addresses as usernames in a status" do
|
256
|
+
from_user = "barman"
|
257
|
+
users = %w{@fooman @barbaz}
|
258
|
+
email = "barbaz@foo.net"
|
231
259
|
record = {
|
232
|
-
:
|
233
|
-
:status
|
234
|
-
|
235
|
-
|
236
|
-
}
|
260
|
+
:from_user => from_user,
|
261
|
+
:status => "Hi, #{users[0]}! You should notify #{users[1]}, #{email}",
|
262
|
+
:created_at => Time.at(1),
|
263
|
+
:to_user => nil
|
237
264
|
}
|
238
265
|
Util.expects(:humanize_time_diff).returns([2, "secs"])
|
239
266
|
@output.expects(:puts).with(<<-END
|
240
|
-
\e[
|
241
|
-
Hi, \e[33m
|
267
|
+
\e[32m#{from_user}\e[0m, 2 secs ago:
|
268
|
+
Hi, \e[33m#{users[0]}\e[0m! You should notify \e[33m#{users[1]}\e[0m, #{email}
|
242
269
|
|
243
270
|
END
|
244
271
|
)
|
@@ -0,0 +1,127 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
require "rest_client"
|
3
|
+
|
4
|
+
class Object
|
5
|
+
def sleep(timeout); end # speed up tests
|
6
|
+
end
|
7
|
+
|
8
|
+
module Tweetwine
|
9
|
+
module RetryingHttp
|
10
|
+
|
11
|
+
class ClientTest < Test::Unit::TestCase
|
12
|
+
context "A Client instance" do
|
13
|
+
setup do
|
14
|
+
@io = mock()
|
15
|
+
@client = Client.new(@io)
|
16
|
+
end
|
17
|
+
|
18
|
+
should "wrap RestClient.get" do
|
19
|
+
RestClient.expects(:get).with("https://site.org")
|
20
|
+
@client.get("https://site.org")
|
21
|
+
end
|
22
|
+
|
23
|
+
should "wrap RestClient.post" do
|
24
|
+
RestClient.expects(:post).with("https://site.org", { :key => "value" })
|
25
|
+
@client.post("https://site.org", { :key => "value" })
|
26
|
+
end
|
27
|
+
|
28
|
+
should "raise HttpError for an invalid request" do
|
29
|
+
RestClient.expects(:get).with("https://charlie:42@authorization.org").raises(RestClient::Unauthorized)
|
30
|
+
assert_raise(HttpError) { @client.get("https://charlie:42@authorization.org") }
|
31
|
+
end
|
32
|
+
|
33
|
+
should "raise HttpError when connection cannot be established" do
|
34
|
+
RestClient.expects(:get).with("https://unreachable.org").raises(Errno::ECONNABORTED)
|
35
|
+
assert_raise(HttpError) { @client.get("https://unreachable.org") }
|
36
|
+
end
|
37
|
+
|
38
|
+
should "raise HttpError when host cannot be resolved" do
|
39
|
+
RestClient.expects(:get).with("https://unresolved.org").raises(SocketError)
|
40
|
+
assert_raise(HttpError) { @client.get("https://unresolved.org") }
|
41
|
+
end
|
42
|
+
|
43
|
+
should "retry connection upon connection reset" do
|
44
|
+
retrying_calls = sequence("Retrying Client calls")
|
45
|
+
RestClient.expects(:get).with("https://moderate.traffic.org").in_sequence(retrying_calls).raises(Errno::ECONNRESET)
|
46
|
+
RestClient.expects(:get).with("https://moderate.traffic.org").in_sequence(retrying_calls)
|
47
|
+
@io.expects(:warn).with("Could not connect -- retrying in 4 seconds")
|
48
|
+
@client.get("https://moderate.traffic.org")
|
49
|
+
end
|
50
|
+
|
51
|
+
should "retry connection a maximum of certain number of times" do
|
52
|
+
retrying_calls = sequence("Retrying Client calls")
|
53
|
+
io_calls = sequence("IO")
|
54
|
+
Client::MAX_RETRIES.times do
|
55
|
+
RestClient.expects(:get).with("https://unresponsive.org").in_sequence(retrying_calls).raises(Errno::ECONNRESET)
|
56
|
+
end
|
57
|
+
(Client::MAX_RETRIES - 1).times do
|
58
|
+
@io.expects(:warn).in_sequence(io_calls)
|
59
|
+
end
|
60
|
+
assert_raise(HttpError) { @client.get("https://unresponsive.org") }
|
61
|
+
end
|
62
|
+
|
63
|
+
should "return a resource with IO inherited from the client" do
|
64
|
+
resource = @client.as_resource("http://foo.bar")
|
65
|
+
assert_equal(@io, resource.io)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
class ResourceTest < Test::Unit::TestCase
|
71
|
+
context "A Resource instance" do
|
72
|
+
setup do
|
73
|
+
@io = mock()
|
74
|
+
@wrapped = mock()
|
75
|
+
@resource = Resource.new(@wrapped)
|
76
|
+
@resource.io = @io
|
77
|
+
end
|
78
|
+
|
79
|
+
should "allow wrapping RestClient::Resource#get" do
|
80
|
+
@wrapped.expects(:get).with("https://site.org")
|
81
|
+
@resource.get("https://site.org")
|
82
|
+
end
|
83
|
+
|
84
|
+
should "allow wrapping RestClient::Resource#post" do
|
85
|
+
@wrapped.expects(:post).with("https://site.org", { :key => "value" })
|
86
|
+
@resource.post("https://site.org", { :key => "value" })
|
87
|
+
end
|
88
|
+
|
89
|
+
should "raise HttpError for an invalid request" do
|
90
|
+
@wrapped.expects(:get).raises(RestClient::Unauthorized)
|
91
|
+
assert_raise(HttpError) { @resource.get }
|
92
|
+
end
|
93
|
+
|
94
|
+
should "raise HttpError when connection cannot be established" do
|
95
|
+
@wrapped.expects(:get).raises(Errno::ECONNABORTED)
|
96
|
+
assert_raise(HttpError) { @resource.get }
|
97
|
+
end
|
98
|
+
|
99
|
+
should "raise HttpError when host cannot be resolved" do
|
100
|
+
@wrapped.expects(:get).raises(SocketError)
|
101
|
+
assert_raise(HttpError) { @resource.get }
|
102
|
+
end
|
103
|
+
|
104
|
+
should "retry connection upon connection reset" do
|
105
|
+
retrying_calls = sequence("Retrying Resource calls")
|
106
|
+
@wrapped.expects(:get).in_sequence(retrying_calls).raises(Errno::ECONNRESET)
|
107
|
+
@wrapped.expects(:get).in_sequence(retrying_calls)
|
108
|
+
@io.expects(:warn).with("Could not connect -- retrying in 4 seconds")
|
109
|
+
@resource.get
|
110
|
+
end
|
111
|
+
|
112
|
+
should "retry connection a maximum of certain number of times" do
|
113
|
+
retrying_calls = sequence("Retrying Resource calls")
|
114
|
+
io_calls = sequence("IO")
|
115
|
+
Resource::MAX_RETRIES.times do
|
116
|
+
@wrapped.expects(:get).in_sequence(retrying_calls).raises(Errno::ECONNRESET)
|
117
|
+
end
|
118
|
+
(Resource::MAX_RETRIES - 1).times do
|
119
|
+
@io.expects(:warn).in_sequence(io_calls)
|
120
|
+
end
|
121
|
+
assert_raise(HttpError) { @resource.get }
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
end
|
127
|
+
end
|
data/test/startup_config_test.rb
CHANGED
@@ -9,21 +9,32 @@ class StartupConfigTest < Test::Unit::TestCase
|
|
9
9
|
context "upon initialization" do
|
10
10
|
should "require at least one supported command" do
|
11
11
|
assert_raise(ArgumentError) { StartupConfig.new([]) }
|
12
|
-
assert_nothing_raised { StartupConfig.new([:
|
12
|
+
assert_nothing_raised { StartupConfig.new([:cmd], :cmd) }
|
13
|
+
end
|
14
|
+
|
15
|
+
should "require the default command to be a supported command" do
|
16
|
+
assert_raise(ArgumentError) { StartupConfig.new([:cmd_a], :cmd_b) }
|
17
|
+
assert_nothing_raised { StartupConfig.new([:cmd_a], :cmd_a) }
|
18
|
+
end
|
19
|
+
|
20
|
+
should "allow passing default options" do
|
21
|
+
opts = {:opt => "foo"}
|
22
|
+
config = StartupConfig.new([:cmd_a], :cmd_a, opts)
|
23
|
+
assert_equal opts, config.options
|
13
24
|
end
|
14
25
|
end
|
15
26
|
|
16
27
|
context "at runtime" do
|
17
28
|
setup do
|
18
|
-
@config = StartupConfig.new([:default_action, :another_action])
|
29
|
+
@config = StartupConfig.new([:default_action, :another_action], :default_action, {:defopt => 42})
|
19
30
|
end
|
20
31
|
|
21
|
-
should "use the
|
32
|
+
should "use the default command when given no command as a cmdline argument" do
|
22
33
|
@config.parse
|
23
34
|
assert_equal :default_action, @config.command
|
24
35
|
end
|
25
36
|
|
26
|
-
should "
|
37
|
+
should "pass supported commands" do
|
27
38
|
@config.parse(%w{default_action}) { |args| {} }
|
28
39
|
assert_equal :default_action, @config.command
|
29
40
|
|
@@ -31,53 +42,67 @@ class StartupConfigTest < Test::Unit::TestCase
|
|
31
42
|
assert_equal :another_action, @config.command
|
32
43
|
end
|
33
44
|
|
34
|
-
should "
|
35
|
-
|
36
|
-
|
37
|
-
{:opt => "foo"}
|
45
|
+
should "raise ArgumentError if given command is not supported" do
|
46
|
+
assert_raise(ArgumentError) do
|
47
|
+
@config.parse(%w{unknown_action}) { |args| {} }
|
38
48
|
end
|
39
|
-
assert_equal({:opt => "foo"}, @config.options)
|
40
|
-
assert_equal :another_action, @config.command
|
41
|
-
assert_equal %w{left overs}, @config.args
|
42
49
|
end
|
43
50
|
|
44
|
-
context "when given
|
51
|
+
context "when given cmdline args and no config file" do
|
45
52
|
setup do
|
46
|
-
@
|
53
|
+
@cmd_args = %w{--opt bar --another_opt baz another_action left overs}
|
54
|
+
@config.parse(@cmd_args) do |args|
|
55
|
+
args.slice!(0..3)
|
56
|
+
{:defopt => 56, :nopt => "baz"}
|
57
|
+
end
|
47
58
|
end
|
48
59
|
|
49
60
|
should "have the parsed option defined" do
|
50
|
-
assert_equal
|
61
|
+
assert_equal "baz", @config.options[:nopt]
|
62
|
+
end
|
63
|
+
|
64
|
+
should "override default options with the options given as cmdline args" do
|
65
|
+
assert_equal 56, @config.options[:defopt]
|
66
|
+
end
|
67
|
+
|
68
|
+
should "parse cmdline args before the command" do
|
69
|
+
assert_equal({:defopt => 56, :nopt => "baz"}, @config.options)
|
70
|
+
end
|
71
|
+
|
72
|
+
should "identify the next argument after cmdline args as the command" do
|
73
|
+
assert_equal :another_action, @config.command
|
74
|
+
end
|
75
|
+
|
76
|
+
should "leave remaining args to be consumed by the command" do
|
77
|
+
assert_equal %w{left overs}, @cmd_args
|
51
78
|
end
|
52
79
|
end
|
53
80
|
|
54
|
-
context "when given cmdline args and
|
81
|
+
context "when given no cmdline args and a config file" do
|
55
82
|
setup do
|
56
|
-
@config.parse(
|
57
|
-
args.clear
|
58
|
-
{:opt => "foo"}
|
59
|
-
end
|
83
|
+
@config.parse([], TEST_CONFIG_FILE)
|
60
84
|
end
|
61
85
|
|
62
86
|
should "have the parsed option defined" do
|
63
|
-
assert_equal
|
87
|
+
assert_equal false, @config.options[:colors]
|
88
|
+
end
|
89
|
+
|
90
|
+
should "override default options with the options given from the config file" do
|
91
|
+
assert_equal 78, @config.options[:defopt]
|
64
92
|
end
|
65
93
|
end
|
66
94
|
|
67
95
|
context "when given an option both as a cmdline option and in a config file" do
|
68
96
|
setup do
|
69
|
-
@config.parse(%w{--
|
97
|
+
@config.parse(%w{--colors}, TEST_CONFIG_FILE) do |args|
|
70
98
|
args.clear
|
71
|
-
{:
|
99
|
+
{:defopt => 56, :colors => true}
|
72
100
|
end
|
73
101
|
end
|
74
102
|
|
75
103
|
should "the command line option should override the config file option" do
|
76
|
-
assert_equal true, @config.options[:
|
77
|
-
|
78
|
-
|
79
|
-
should "have nil for an undefined option" do
|
80
|
-
assert_nil @config.options[:num_statuses]
|
104
|
+
assert_equal true, @config.options[:colors]
|
105
|
+
assert_equal 56, @config.options[:defopt]
|
81
106
|
end
|
82
107
|
end
|
83
108
|
end
|
data/test/test_helper.rb
CHANGED
@@ -5,33 +5,48 @@ require "mocha"
|
|
5
5
|
|
6
6
|
module Tweetwine
|
7
7
|
module TestHelpers
|
8
|
-
def
|
9
|
-
|
8
|
+
def create_test_twitter_status_records_from_rest_api(*internal_records)
|
9
|
+
twitter_records = internal_records.map do |internal_record|
|
10
10
|
{
|
11
|
-
"user" => { "screen_name" =>
|
12
|
-
"created_at" =>
|
13
|
-
"text" =>
|
14
|
-
"in_reply_to_screen_name" =>
|
11
|
+
"user" => { "screen_name" => internal_record[:from_user] },
|
12
|
+
"created_at" => internal_record[:created_at],
|
13
|
+
"text" => internal_record[:status],
|
14
|
+
"in_reply_to_screen_name" => internal_record[:to_user]
|
15
15
|
}
|
16
16
|
end
|
17
|
-
[
|
17
|
+
[twitter_records, internal_records]
|
18
18
|
end
|
19
19
|
|
20
|
-
def
|
21
|
-
|
22
|
-
|
23
|
-
if
|
24
|
-
|
20
|
+
def create_test_twitter_user_records_from_rest_api(*internal_records)
|
21
|
+
twitter_records = internal_records.map do |internal_record|
|
22
|
+
twitter_record = { "screen_name" => internal_record[:from_user] }
|
23
|
+
if internal_record[:status]
|
24
|
+
twitter_record.merge!({
|
25
25
|
"status" => {
|
26
|
-
"created_at" =>
|
27
|
-
"text" =>
|
28
|
-
"in_reply_to_screen_name" =>
|
26
|
+
"created_at" => internal_record[:created_at],
|
27
|
+
"text" => internal_record[:status],
|
28
|
+
"in_reply_to_screen_name" => internal_record[:to_user],
|
29
29
|
}
|
30
30
|
})
|
31
31
|
end
|
32
|
-
|
32
|
+
twitter_record
|
33
33
|
end
|
34
|
-
[
|
34
|
+
[twitter_records, internal_records]
|
35
|
+
end
|
36
|
+
|
37
|
+
def create_test_twitter_records_from_search_api(*internal_records)
|
38
|
+
twitter_search_records = internal_records.map do |internal_record|
|
39
|
+
{
|
40
|
+
"from_user" => internal_record[:from_user],
|
41
|
+
"created_at" => internal_record[:created_at],
|
42
|
+
"text" => internal_record[:status],
|
43
|
+
"to_user" => internal_record[:to_user]
|
44
|
+
}
|
45
|
+
end
|
46
|
+
twitter_records = {
|
47
|
+
"results" => twitter_search_records
|
48
|
+
}
|
49
|
+
[twitter_records, internal_records]
|
35
50
|
end
|
36
51
|
end
|
37
52
|
end
|