kronk 1.4.0 → 1.5.0
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/.gemtest +0 -0
- data/History.rdoc +22 -0
- data/Manifest.txt +15 -6
- data/README.rdoc +5 -6
- data/Rakefile +5 -5
- data/lib/kronk.rb +164 -194
- data/lib/kronk/cmd.rb +188 -74
- data/lib/kronk/constants.rb +90 -0
- data/lib/kronk/data_renderer.rb +146 -0
- data/lib/kronk/diff.rb +4 -92
- data/lib/kronk/path/transaction.rb +2 -0
- data/lib/kronk/player.rb +233 -0
- data/lib/kronk/player/benchmark.rb +261 -0
- data/lib/kronk/player/input_reader.rb +54 -0
- data/lib/kronk/player/output.rb +49 -0
- data/lib/kronk/player/request_parser.rb +24 -0
- data/lib/kronk/player/stream.rb +50 -0
- data/lib/kronk/player/suite.rb +123 -0
- data/lib/kronk/plist_parser.rb +4 -0
- data/lib/kronk/request.rb +265 -241
- data/lib/kronk/response.rb +330 -149
- data/lib/kronk/test/assertions.rb +2 -2
- data/lib/kronk/xml_parser.rb +7 -1
- data/test/mocks/cookies.yml +32 -0
- data/test/mocks/get_request.txt +6 -0
- data/test/test_assertions.rb +6 -6
- data/test/test_cmd.rb +708 -0
- data/test/test_diff.rb +210 -75
- data/test/test_helper.rb +140 -0
- data/test/test_helper_methods.rb +4 -4
- data/test/test_input_reader.rb +103 -0
- data/test/test_kronk.rb +142 -141
- data/test/test_player.rb +589 -0
- data/test/test_request.rb +147 -212
- data/test/test_request_parser.rb +31 -0
- data/test/test_response.rb +206 -15
- metadata +41 -74
- data/bin/yzma +0 -13
- data/lib/kronk/data_set.rb +0 -144
- data/lib/yzma.rb +0 -174
- data/lib/yzma/randomizer.rb +0 -54
- data/lib/yzma/report.rb +0 -47
- data/test/test_data_set.rb +0 -213
@@ -83,8 +83,8 @@ class Kronk
|
|
83
83
|
# Supports all options of Kronk.compare.
|
84
84
|
|
85
85
|
def assert_equal_responses uri1, uri2, options={}
|
86
|
-
resp1 = Kronk.
|
87
|
-
resp2 = Kronk.
|
86
|
+
resp1 = Kronk.retrieve(uri1, options).stringify options
|
87
|
+
resp2 = Kronk.retrieve(uri2, options).stringify options
|
88
88
|
|
89
89
|
assert_equal resp1, resp2
|
90
90
|
end
|
data/lib/kronk/xml_parser.rb
CHANGED
@@ -10,7 +10,13 @@ class Kronk
|
|
10
10
|
# loaded if String#pluralize is not defined.
|
11
11
|
|
12
12
|
def self.require_gems
|
13
|
-
|
13
|
+
begin
|
14
|
+
require 'nokogiri'
|
15
|
+
rescue LoadError => e
|
16
|
+
raise unless e.message =~ /-- nokogiri/
|
17
|
+
raise MissingDependency, "Please install the nokogiri gem and try again"
|
18
|
+
end
|
19
|
+
|
14
20
|
|
15
21
|
return if "".respond_to?(:pluralize)
|
16
22
|
|
@@ -0,0 +1,32 @@
|
|
1
|
+
--- !ruby/object:CookieJar::Jar
|
2
|
+
domains:
|
3
|
+
rubygems.org:
|
4
|
+
/:
|
5
|
+
remember_token: !ruby/object:CookieJar::Cookie
|
6
|
+
comment:
|
7
|
+
comment_url:
|
8
|
+
created_at: 2010-12-12 15:51:53.850373 -08:00
|
9
|
+
discard: false
|
10
|
+
domain: rubygems.org
|
11
|
+
expiry: 2011-12-12 15:51:56 -08:00
|
12
|
+
http_only: false
|
13
|
+
name: remember_token
|
14
|
+
path: /
|
15
|
+
ports:
|
16
|
+
secure: false
|
17
|
+
value: xxxxxxxxxxxxxxxxxxxxxxx
|
18
|
+
version: 0
|
19
|
+
_test_session: !ruby/object:CookieJar::Cookie
|
20
|
+
comment:
|
21
|
+
comment_url:
|
22
|
+
created_at: 2010-12-12 16:01:31.903690 -08:00
|
23
|
+
discard: false
|
24
|
+
domain: rubygems.org
|
25
|
+
expiry:
|
26
|
+
http_only: true
|
27
|
+
name: _test_session
|
28
|
+
path: /
|
29
|
+
ports:
|
30
|
+
secure: false
|
31
|
+
value: XXXXXXXXXXXXXXXXXXXXXXXX
|
32
|
+
version: 0
|
data/test/test_assertions.rb
CHANGED
@@ -59,9 +59,9 @@ class TestAssertions < Test::Unit::TestCase
|
|
59
59
|
|
60
60
|
def test_assert_equal_responses
|
61
61
|
io = StringIO.new mock_resp("200_response.json")
|
62
|
-
mock_resp = Kronk::Response.
|
62
|
+
mock_resp = Kronk::Response.new io
|
63
63
|
|
64
|
-
Kronk
|
64
|
+
Kronk.expects(:retrieve).times(2).
|
65
65
|
with("host.com", :foo => "bar").returns mock_resp
|
66
66
|
|
67
67
|
assert_equal_responses "host.com", "host.com", :foo => "bar"
|
@@ -69,16 +69,16 @@ class TestAssertions < Test::Unit::TestCase
|
|
69
69
|
|
70
70
|
|
71
71
|
def test_assert_equal_responses_failure
|
72
|
-
mock_resp1 = Kronk::Response.
|
72
|
+
mock_resp1 = Kronk::Response.new \
|
73
73
|
StringIO.new mock_resp("200_response.json")
|
74
74
|
|
75
|
-
mock_resp2 = Kronk::Response.
|
75
|
+
mock_resp2 = Kronk::Response.new \
|
76
76
|
StringIO.new mock_resp("301_response.txt")
|
77
77
|
|
78
|
-
Kronk
|
78
|
+
Kronk.expects(:retrieve).
|
79
79
|
with("host1.com", :foo => "bar").returns mock_resp1
|
80
80
|
|
81
|
-
Kronk
|
81
|
+
Kronk.expects(:retrieve).
|
82
82
|
with("host2.com", :foo => "bar").returns mock_resp2
|
83
83
|
|
84
84
|
left = Kronk::Diff.ordered_data_string mock_resp1.selective_data
|
data/test/test_cmd.rb
ADDED
@@ -0,0 +1,708 @@
|
|
1
|
+
require 'test/test_helper'
|
2
|
+
|
3
|
+
class TestCmd < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_irb
|
6
|
+
with_irb_mock do
|
7
|
+
resp = Kronk::Response.new mock_resp("200_response.json")
|
8
|
+
|
9
|
+
assert !Kronk::Cmd.irb(resp)
|
10
|
+
|
11
|
+
assert_equal resp, $http_response
|
12
|
+
assert_equal resp.parsed_body, $response
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
|
17
|
+
def test_irb_no_parser
|
18
|
+
with_irb_mock do
|
19
|
+
resp = Kronk::Response.new mock_200_response
|
20
|
+
Kronk::Cmd.irb resp
|
21
|
+
assert_equal resp, $http_response
|
22
|
+
assert_equal resp.body, $response
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
def test_load_requires
|
28
|
+
assert Kronk.config[:requires].empty?
|
29
|
+
mock_require 'foo'
|
30
|
+
mock_require 'bar'
|
31
|
+
|
32
|
+
Kronk::Cmd.load_requires ["foo", "bar"]
|
33
|
+
|
34
|
+
assert_require 'foo'
|
35
|
+
assert_require 'bar'
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
def test_load_requires_from_config
|
40
|
+
Kronk.config[:requires] = ['foo', 'bar']
|
41
|
+
mock_require 'foo'
|
42
|
+
mock_require 'bar'
|
43
|
+
|
44
|
+
Kronk::Cmd.load_requires
|
45
|
+
|
46
|
+
assert_require 'foo'
|
47
|
+
assert_require 'bar'
|
48
|
+
Kronk.config[:requires] = []
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
def test_load_requires_from_config_and_args
|
53
|
+
Kronk.config[:requires] = ['foo', 'bar']
|
54
|
+
|
55
|
+
mock_require 'foobar'
|
56
|
+
mock_require 'foo'
|
57
|
+
mock_require 'bar'
|
58
|
+
|
59
|
+
Kronk::Cmd.load_requires ['foobar']
|
60
|
+
|
61
|
+
assert_require 'foobar'
|
62
|
+
assert_require 'foo'
|
63
|
+
assert_require 'bar'
|
64
|
+
Kronk.config[:requires] = []
|
65
|
+
end
|
66
|
+
|
67
|
+
|
68
|
+
def test_make_config_file
|
69
|
+
File.expects(:directory?).with(Kronk::CONFIG_DIR).returns false
|
70
|
+
Dir.expects(:mkdir).with Kronk::CONFIG_DIR
|
71
|
+
|
72
|
+
mock_file = StringIO.new
|
73
|
+
File.expects(:open).with(Kronk::DEFAULT_CONFIG_FILE, "w+").yields mock_file
|
74
|
+
|
75
|
+
Kronk::Cmd.make_config_file
|
76
|
+
mock_file.rewind
|
77
|
+
|
78
|
+
assert_equal Kronk::DEFAULT_CONFIG.to_yaml, mock_file.read
|
79
|
+
end
|
80
|
+
|
81
|
+
|
82
|
+
def test_make_config_file_dir_exists
|
83
|
+
File.expects(:directory?).with(Kronk::CONFIG_DIR).returns true
|
84
|
+
Dir.expects(:mkdir).with(Kronk::CONFIG_DIR).times(0)
|
85
|
+
|
86
|
+
mock_file = StringIO.new
|
87
|
+
File.expects(:open).with(Kronk::DEFAULT_CONFIG_FILE, "w+").yields mock_file
|
88
|
+
|
89
|
+
Kronk::Cmd.make_config_file
|
90
|
+
mock_file.rewind
|
91
|
+
|
92
|
+
assert_equal Kronk::DEFAULT_CONFIG.to_yaml, mock_file.read
|
93
|
+
end
|
94
|
+
|
95
|
+
|
96
|
+
def test_parse_data_path_args
|
97
|
+
opts = {}
|
98
|
+
argv = %w{opt1 opt2 -- path1 path2 -path3}
|
99
|
+
Kronk::Cmd.parse_data_path_args opts, argv
|
100
|
+
|
101
|
+
assert_equal %w{path1 path2}, opts[:only_data]
|
102
|
+
assert_equal %w{path3}, opts[:ignore_data]
|
103
|
+
end
|
104
|
+
|
105
|
+
|
106
|
+
def test_parse_data_path_args_no_paths
|
107
|
+
opts = {}
|
108
|
+
argv = %w{opt1 opt2 path1 path2 -path3}
|
109
|
+
Kronk::Cmd.parse_data_path_args opts, argv
|
110
|
+
|
111
|
+
assert_nil opts[:only_data]
|
112
|
+
assert_nil opts[:ignore_data]
|
113
|
+
end
|
114
|
+
|
115
|
+
|
116
|
+
def test_query_password
|
117
|
+
$stderr.expects(:<<).with "Password: "
|
118
|
+
$stdin.expects(:gets).returns "mock_password\n"
|
119
|
+
$stderr.expects(:<<).with "\n"
|
120
|
+
|
121
|
+
Kronk::Cmd.query_password
|
122
|
+
end
|
123
|
+
|
124
|
+
|
125
|
+
def test_query_password_custom
|
126
|
+
$stderr.expects(:<<).with "SAY IT: "
|
127
|
+
$stdin.expects(:gets).returns "mock_password\n"
|
128
|
+
$stderr.expects(:<<).with "\n"
|
129
|
+
|
130
|
+
Kronk::Cmd.query_password "SAY IT:"
|
131
|
+
end
|
132
|
+
|
133
|
+
|
134
|
+
def test_parse_args_diff_format_mapping
|
135
|
+
with_config Hash.new do
|
136
|
+
opts = Kronk::Cmd.parse_args %w{uri --ascii}
|
137
|
+
assert_equal :ascii_diff, Kronk.config[:diff_format]
|
138
|
+
|
139
|
+
opts = Kronk::Cmd.parse_args %w{uri --color}
|
140
|
+
assert_equal :color_diff, Kronk.config[:diff_format]
|
141
|
+
|
142
|
+
opts = Kronk::Cmd.parse_args %w{uri --format color}
|
143
|
+
assert_equal 'color', Kronk.config[:diff_format]
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
|
148
|
+
def test_parse_args_completion
|
149
|
+
with_config Hash.new do
|
150
|
+
file = File.join(File.dirname(__FILE__), "../script/kronk_completion")
|
151
|
+
$stdout.expects(:puts).with File.expand_path(file)
|
152
|
+
|
153
|
+
assert_exit 2 do
|
154
|
+
Kronk::Cmd.parse_args %w{--completion}
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
|
160
|
+
def test_parse_args_config
|
161
|
+
with_config Hash.new do
|
162
|
+
YAML.expects(:load_file).with("foobar").returns :foo => "bar"
|
163
|
+
Kronk::Cmd.parse_args %w{uri --config foobar}
|
164
|
+
assert_equal "bar", Kronk.config[:foo]
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
|
169
|
+
def test_parse_args_kronk_configs
|
170
|
+
with_config Hash.new do
|
171
|
+
Kronk::Cmd.parse_args %w{uri -q -l --no-opts -V -t 1234 --ruby}
|
172
|
+
assert Kronk.config[:brief]
|
173
|
+
assert Kronk.config[:show_lines]
|
174
|
+
assert Kronk.config[:no_uri_options]
|
175
|
+
assert Kronk.config[:verbose]
|
176
|
+
assert_equal 'ruby', Kronk.config[:render_lang]
|
177
|
+
assert_equal 1234, Kronk.config[:timeout]
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
|
182
|
+
def test_parse_args_headers
|
183
|
+
opts = Kronk::Cmd.parse_args %w{uri -i FOO -i BAR -iTWO,PART}
|
184
|
+
assert_equal %w{FOO BAR TWO PART}, opts[:with_headers]
|
185
|
+
assert_equal false, opts[:no_body]
|
186
|
+
|
187
|
+
opts = Kronk::Cmd.parse_args %w{uri -I}
|
188
|
+
assert_equal true, opts[:with_headers]
|
189
|
+
assert_equal true, opts[:no_body]
|
190
|
+
|
191
|
+
opts = Kronk::Cmd.parse_args %w{uri -I FOO -I BAR -ITWO,PART}
|
192
|
+
assert_equal %w{FOO BAR TWO PART}, opts[:with_headers]
|
193
|
+
assert_equal true, opts[:no_body]
|
194
|
+
|
195
|
+
opts = Kronk::Cmd.parse_args %w{uri -i}
|
196
|
+
assert_equal true, opts[:with_headers]
|
197
|
+
assert_equal false, opts[:no_body]
|
198
|
+
end
|
199
|
+
|
200
|
+
|
201
|
+
def test_parse_args_kronk_options
|
202
|
+
opts = Kronk::Cmd.parse_args %w{uri1 uri2 --indicies --irb -P FOO
|
203
|
+
--prev -R --struct -r lib1,lib2 -rlib3}
|
204
|
+
|
205
|
+
assert_equal [Kronk.config[:cache_file], "uri1"], opts[:uris]
|
206
|
+
assert_equal true, opts[:keep_indicies]
|
207
|
+
assert_equal true, opts[:irb]
|
208
|
+
assert_equal true, opts[:raw]
|
209
|
+
assert_equal true, opts[:struct]
|
210
|
+
assert_equal %w{lib1 lib2 lib3}, opts[:requires]
|
211
|
+
assert_equal "FOO", opts[:parser]
|
212
|
+
end
|
213
|
+
|
214
|
+
|
215
|
+
def test_parse_args_player_options
|
216
|
+
opts = Kronk::Cmd.parse_args %w{uri -c 2 -n 100 -o}
|
217
|
+
assert_equal 2, opts[:player].concurrency
|
218
|
+
assert_equal 100, opts[:player].number
|
219
|
+
assert_equal Kronk::Player::Stream, opts[:player].output.class
|
220
|
+
|
221
|
+
opts = Kronk::Cmd.parse_args %w{uri -o benchmark}
|
222
|
+
assert_equal Kronk::Player::Benchmark, opts[:player].output.class
|
223
|
+
end
|
224
|
+
|
225
|
+
|
226
|
+
def test_parse_args_player_stdin
|
227
|
+
$stdin.expects(:tty?).returns(false).times(6)
|
228
|
+
|
229
|
+
opts = Kronk::Cmd.parse_args %w{uri -p}
|
230
|
+
assert_equal $stdin, opts[:player].input.io
|
231
|
+
assert_equal %w{uri}, opts[:uris]
|
232
|
+
|
233
|
+
opts = Kronk::Cmd.parse_args %w{uri --benchmark}
|
234
|
+
assert_equal $stdin, opts[:player].input.io
|
235
|
+
assert_equal %w{uri}, opts[:uris]
|
236
|
+
assert_equal Kronk::Player::Benchmark, opts[:player].output.class
|
237
|
+
|
238
|
+
opts = Kronk::Cmd.parse_args %w{uri --stream}
|
239
|
+
assert_equal $stdin, opts[:player].input.io
|
240
|
+
assert_equal %w{uri}, opts[:uris]
|
241
|
+
assert_equal Kronk::Player::Stream, opts[:player].output.class
|
242
|
+
end
|
243
|
+
|
244
|
+
|
245
|
+
def test_parse_args_player_file
|
246
|
+
mock_file = StringIO.new "mock_file"
|
247
|
+
File.expects(:open).with("mock_file", "r").times(3).returns mock_file
|
248
|
+
|
249
|
+
opts = Kronk::Cmd.parse_args %w{uri -p mock_file}
|
250
|
+
assert_equal mock_file, opts[:player].input.io
|
251
|
+
|
252
|
+
opts = Kronk::Cmd.parse_args %w{uri --benchmark mock_file}
|
253
|
+
assert_equal mock_file, opts[:player].input.io
|
254
|
+
assert_equal Kronk::Player::Benchmark, opts[:player].output.class
|
255
|
+
|
256
|
+
opts = Kronk::Cmd.parse_args %w{uri --stream mock_file}
|
257
|
+
assert_equal mock_file, opts[:player].input.io
|
258
|
+
assert_equal Kronk::Player::Stream, opts[:player].output.class
|
259
|
+
end
|
260
|
+
|
261
|
+
|
262
|
+
def test_parse_args_clear_cookies
|
263
|
+
Kronk.cookie_jar.instance_variable_set "@domains", {"foo" => "bar"}
|
264
|
+
|
265
|
+
Kronk::Cmd.parse_args %w{uri --clear-cookies}
|
266
|
+
assert Kronk.cookie_jar.instance_variable_get("@domains").empty?
|
267
|
+
|
268
|
+
Kronk.instance_variable_set "@cookie_jar", nil
|
269
|
+
end
|
270
|
+
|
271
|
+
|
272
|
+
def test_parse_args_data
|
273
|
+
opts = Kronk::Cmd.parse_args %w{uri -d mock_data}
|
274
|
+
assert_equal "mock_data", opts[:data]
|
275
|
+
assert_equal "POST", opts[:http_method]
|
276
|
+
|
277
|
+
opts = Kronk::Cmd.parse_args %w{uri -X PUT -d mock_data}
|
278
|
+
assert_equal "mock_data", opts[:data]
|
279
|
+
assert_equal "PUT", opts[:http_method]
|
280
|
+
end
|
281
|
+
|
282
|
+
|
283
|
+
def test_parse_args_headers
|
284
|
+
opts = Kronk::Cmd.parse_args %w{uri -H NilHeader -H FOO:bar -H Test:\ foo}
|
285
|
+
expected = {
|
286
|
+
"NilHeader" => "",
|
287
|
+
"FOO" => "bar",
|
288
|
+
"Test" => "foo"
|
289
|
+
}
|
290
|
+
|
291
|
+
assert_equal expected, opts[:headers]
|
292
|
+
end
|
293
|
+
|
294
|
+
|
295
|
+
def test_parse_args_http_options
|
296
|
+
opts = Kronk::Cmd.parse_args %w{uri -A foo -L --no-cookies -? bar
|
297
|
+
--suff /tail -X PUT -x example.com:2000}
|
298
|
+
|
299
|
+
assert_equal "foo", opts[:user_agent]
|
300
|
+
assert_equal true, opts[:follow_redirects]
|
301
|
+
assert_equal true, opts[:no_cookies]
|
302
|
+
assert_equal "bar", opts[:query]
|
303
|
+
assert_equal "/tail", opts[:uri_suffix]
|
304
|
+
assert_equal "PUT", opts[:http_method]
|
305
|
+
assert_equal({:address => "example.com", :port => "2000"}, opts[:proxy])
|
306
|
+
|
307
|
+
opts = Kronk::Cmd.parse_args %w{uri -L 3}
|
308
|
+
assert_equal 3, opts[:follow_redirects]
|
309
|
+
end
|
310
|
+
|
311
|
+
|
312
|
+
def test_parse_args_auth_http_options
|
313
|
+
Kronk::Cmd.expects(:query_password).with("Server password:").returns "svr"
|
314
|
+
Kronk::Cmd.expects(:query_password).with("Proxy password:").returns "prox"
|
315
|
+
|
316
|
+
opts = Kronk::Cmd.parse_args %w{uri -u svruser -U proxuser}
|
317
|
+
assert_equal({:username => "svruser", :password => "svr"}, opts[:auth])
|
318
|
+
assert_equal({:username => "proxuser", :password => "prox"}, opts[:proxy])
|
319
|
+
|
320
|
+
Kronk::Cmd.expects(:query_password).with("Server password:").never
|
321
|
+
Kronk::Cmd.expects(:query_password).with("Proxy password:").never
|
322
|
+
|
323
|
+
opts = Kronk::Cmd.parse_args %w{uri -u svruser:svr2 -U proxuser:prox2}
|
324
|
+
assert_equal({:username => "svruser", :password => "svr2"}, opts[:auth])
|
325
|
+
assert_equal({:username => "proxuser", :password => "prox2"}, opts[:proxy])
|
326
|
+
end
|
327
|
+
|
328
|
+
|
329
|
+
def test_parse_args_paths
|
330
|
+
opts = Kronk::Cmd.parse_args %w{uri -- path1 path2 -path3}
|
331
|
+
assert_equal %w{path3}, opts[:ignore_data]
|
332
|
+
assert_equal %w{path1 path2}, opts[:only_data]
|
333
|
+
end
|
334
|
+
|
335
|
+
|
336
|
+
def test_parse_args_uris
|
337
|
+
opts = Kronk::Cmd.parse_args %w{uri1 uri2 uri3 uri4}
|
338
|
+
assert_equal %w{uri1 uri2}, opts[:uris]
|
339
|
+
end
|
340
|
+
|
341
|
+
|
342
|
+
def test_parse_args_uris_with_io
|
343
|
+
$stdin.expects(:tty?).returns(false)
|
344
|
+
$stdin.expects(:read).returns("MOCK RESPONSE")
|
345
|
+
|
346
|
+
opts = Kronk::Cmd.parse_args %w{uri1 uri2}
|
347
|
+
assert_equal 2, opts[:uris].length
|
348
|
+
assert_equal "uri1", opts[:uris][1]
|
349
|
+
assert_equal StringIO, opts[:uris][0].class
|
350
|
+
assert_equal "MOCK RESPONSE", opts[:uris][0].read
|
351
|
+
end
|
352
|
+
|
353
|
+
|
354
|
+
def test_parse_args_uris_with_tty
|
355
|
+
$stdin.expects(:tty?).returns(true)
|
356
|
+
opts = Kronk::Cmd.parse_args %w{uri1}
|
357
|
+
assert_equal %w{uri1}, opts[:uris]
|
358
|
+
end
|
359
|
+
|
360
|
+
|
361
|
+
def test_parse_args_uris_from_cache
|
362
|
+
File.expects(:file?).with(Kronk.config[:cache_file]).returns true
|
363
|
+
Kronk::Cmd.expects(:verbose).with("No URI specified - using kronk cache")
|
364
|
+
|
365
|
+
opts = Kronk::Cmd.parse_args %w{}
|
366
|
+
assert_equal [Kronk.config[:cache_file]], opts[:uris]
|
367
|
+
end
|
368
|
+
|
369
|
+
|
370
|
+
def test_parse_args_uris_missing
|
371
|
+
File.expects(:file?).with(Kronk.config[:cache_file]).returns false
|
372
|
+
|
373
|
+
$stderr.expects(:puts).with "\nError: You must enter at least one URI"
|
374
|
+
$stderr.expects(:puts).with "See 'kronk --help' for usage\n\n"
|
375
|
+
|
376
|
+
assert_exit 2 do
|
377
|
+
opts = Kronk::Cmd.parse_args %w{}
|
378
|
+
end
|
379
|
+
end
|
380
|
+
|
381
|
+
|
382
|
+
def test_run_compare
|
383
|
+
Kronk.expects(:load_config)
|
384
|
+
expect_compare_output mock_200_response
|
385
|
+
|
386
|
+
file = File.join(File.dirname(__FILE__), "mocks/200_response.txt")
|
387
|
+
file = File.expand_path file
|
388
|
+
|
389
|
+
Kronk::Cmd.run [file, file]
|
390
|
+
end
|
391
|
+
|
392
|
+
|
393
|
+
def test_run_compare_diff
|
394
|
+
Kronk.expects(:load_config)
|
395
|
+
expect_compare_output mock_200_response, mock_302_response
|
396
|
+
|
397
|
+
file1 = File.join(File.dirname(__FILE__), "mocks/200_response.txt")
|
398
|
+
file2 = File.join(File.dirname(__FILE__), "mocks/302_response.txt")
|
399
|
+
file1 = File.expand_path file1
|
400
|
+
file2 = File.expand_path file2
|
401
|
+
|
402
|
+
assert_exit 1 do
|
403
|
+
Kronk::Cmd.run [file1, file2]
|
404
|
+
end
|
405
|
+
end
|
406
|
+
|
407
|
+
|
408
|
+
def test_run_request
|
409
|
+
Kronk.expects(:load_config)
|
410
|
+
expect_request_output mock_200_response
|
411
|
+
|
412
|
+
file = File.join(File.dirname(__FILE__), "mocks/200_response.txt")
|
413
|
+
file = File.expand_path file
|
414
|
+
|
415
|
+
Kronk::Cmd.run [file]
|
416
|
+
end
|
417
|
+
|
418
|
+
|
419
|
+
def test_run_request_not_200
|
420
|
+
Kronk.expects(:load_config)
|
421
|
+
expect_request_output mock_302_response
|
422
|
+
|
423
|
+
file = File.join(File.dirname(__FILE__), "mocks/302_response.txt")
|
424
|
+
file = File.expand_path file
|
425
|
+
|
426
|
+
assert_exit 1 do
|
427
|
+
Kronk::Cmd.run [file]
|
428
|
+
end
|
429
|
+
end
|
430
|
+
|
431
|
+
|
432
|
+
def test_run_caught_errors
|
433
|
+
errs = {
|
434
|
+
Kronk::Exception => "Kronk::Exception",
|
435
|
+
Kronk::Response::MissingParser => "Kronk::Response::MissingParser",
|
436
|
+
Errno::ECONNRESET => "Connection reset by peer"
|
437
|
+
}
|
438
|
+
|
439
|
+
errs.each do |err, msg|
|
440
|
+
Kronk.expects(:load_config)
|
441
|
+
expect_error_output msg
|
442
|
+
Kronk::Cmd.expects(:request).raises(err)
|
443
|
+
|
444
|
+
assert_exit 2 do
|
445
|
+
Kronk::Cmd.run ["foobar"]
|
446
|
+
end
|
447
|
+
end
|
448
|
+
end
|
449
|
+
|
450
|
+
|
451
|
+
def test_run_no_config_file
|
452
|
+
Kronk.expects(:load_config).raises Errno::ENOENT
|
453
|
+
Kronk::Cmd.expects(:make_config_file)
|
454
|
+
|
455
|
+
expect_error_output "No config file was found.\n" +
|
456
|
+
"Created default config in #{Kronk::DEFAULT_CONFIG_FILE}\n" +
|
457
|
+
"Edit file if necessary and try again.\n"
|
458
|
+
|
459
|
+
assert_exit 2 do
|
460
|
+
Kronk::Cmd.run ["foobar"]
|
461
|
+
end
|
462
|
+
end
|
463
|
+
|
464
|
+
|
465
|
+
def test_compare
|
466
|
+
io1 = StringIO.new(mock_200_response)
|
467
|
+
io2 = StringIO.new(mock_200_response)
|
468
|
+
|
469
|
+
expect_compare_output mock_200_response
|
470
|
+
|
471
|
+
assert Kronk::Cmd.compare(io1, io2), "Expected no diff to succeed"
|
472
|
+
end
|
473
|
+
|
474
|
+
|
475
|
+
def test_compare_failed
|
476
|
+
io1 = StringIO.new(mock_200_response)
|
477
|
+
io2 = StringIO.new(mock_302_response)
|
478
|
+
expect_compare_output mock_200_response, mock_302_response
|
479
|
+
|
480
|
+
assert !Kronk::Cmd.compare(io1, io2), "Expected diffs to fail"
|
481
|
+
end
|
482
|
+
|
483
|
+
|
484
|
+
def test_request
|
485
|
+
io = StringIO.new(mock_200_response)
|
486
|
+
expect_request_output mock_200_response
|
487
|
+
|
488
|
+
assert Kronk::Cmd.request(io), "Expected 200 response to succeed"
|
489
|
+
end
|
490
|
+
|
491
|
+
|
492
|
+
def test_request_failed
|
493
|
+
io = StringIO.new(mock_302_response)
|
494
|
+
expect_request_output mock_302_response
|
495
|
+
|
496
|
+
assert !Kronk::Cmd.request(io), "Expected 302 response to fail"
|
497
|
+
end
|
498
|
+
|
499
|
+
|
500
|
+
def test_render_with_irb
|
501
|
+
kronk = Kronk.new
|
502
|
+
io1 = StringIO.new(mock_200_response)
|
503
|
+
io2 = StringIO.new(mock_200_response)
|
504
|
+
|
505
|
+
kronk.compare io1, io2
|
506
|
+
$stdout.expects(:puts).with(kronk.diff.formatted).never
|
507
|
+
|
508
|
+
with_irb_mock do
|
509
|
+
assert !Kronk::Cmd.render(kronk, :irb => true),
|
510
|
+
"Expected IRB rendering to return false"
|
511
|
+
end
|
512
|
+
end
|
513
|
+
|
514
|
+
|
515
|
+
def test_render_with_diff
|
516
|
+
kronk = Kronk.new
|
517
|
+
io1 = StringIO.new(mock_200_response)
|
518
|
+
io2 = StringIO.new(mock_200_response)
|
519
|
+
|
520
|
+
kronk.compare io1, io2
|
521
|
+
expect_compare_output mock_200_response, :times => 2
|
522
|
+
|
523
|
+
assert_equal Kronk::Cmd.render_diff(kronk.diff),
|
524
|
+
Kronk::Cmd.render(kronk, {})
|
525
|
+
end
|
526
|
+
|
527
|
+
|
528
|
+
def test_render_with_response
|
529
|
+
kronk = Kronk.new
|
530
|
+
io = StringIO.new(mock_200_response)
|
531
|
+
|
532
|
+
kronk.retrieve io
|
533
|
+
expect_request_output mock_200_response, :times => 2
|
534
|
+
|
535
|
+
assert_equal Kronk::Cmd.render_response(kronk.response),
|
536
|
+
Kronk::Cmd.render(kronk, {})
|
537
|
+
end
|
538
|
+
|
539
|
+
|
540
|
+
def test_render_diff
|
541
|
+
kronk = Kronk.new
|
542
|
+
io1 = StringIO.new(mock_200_response)
|
543
|
+
io2 = StringIO.new(mock_200_response)
|
544
|
+
|
545
|
+
kronk.compare io1, io2
|
546
|
+
|
547
|
+
$stdout.expects(:puts).with kronk.diff.formatted
|
548
|
+
$stdout.expects(:puts).with("Found 0 diff(s).").never
|
549
|
+
|
550
|
+
assert Kronk::Cmd.render_diff(kronk.diff), "Expected no diff to succeed"
|
551
|
+
end
|
552
|
+
|
553
|
+
|
554
|
+
def test_render_diff_verbose_failed
|
555
|
+
kronk = Kronk.new
|
556
|
+
io1 = StringIO.new(mock_200_response)
|
557
|
+
io2 = StringIO.new(mock_302_response)
|
558
|
+
|
559
|
+
kronk.compare io1, io2
|
560
|
+
|
561
|
+
$stdout.expects(:puts).with kronk.diff.formatted
|
562
|
+
$stdout.expects(:puts).with "Found 1 diff(s)."
|
563
|
+
|
564
|
+
with_config :verbose => true do
|
565
|
+
assert !Kronk::Cmd.render_diff(kronk.diff), "Expected diffs to fail"
|
566
|
+
end
|
567
|
+
end
|
568
|
+
|
569
|
+
|
570
|
+
def test_render_diff_verbose
|
571
|
+
kronk = Kronk.new
|
572
|
+
io1 = StringIO.new(mock_200_response)
|
573
|
+
io2 = StringIO.new(mock_200_response)
|
574
|
+
|
575
|
+
kronk.compare io1, io2
|
576
|
+
|
577
|
+
$stdout.expects(:puts).with kronk.diff.formatted
|
578
|
+
$stdout.expects(:puts).with "Found 0 diff(s)."
|
579
|
+
|
580
|
+
with_config :verbose => true do
|
581
|
+
assert Kronk::Cmd.render_diff(kronk.diff), "Expected no diff to succeed"
|
582
|
+
end
|
583
|
+
end
|
584
|
+
|
585
|
+
|
586
|
+
def test_render_diff_brief
|
587
|
+
kronk = Kronk.new
|
588
|
+
io1 = StringIO.new(mock_200_response)
|
589
|
+
io2 = StringIO.new(mock_200_response)
|
590
|
+
|
591
|
+
kronk.compare io1, io2
|
592
|
+
|
593
|
+
$stdout.expects(:puts).with(kronk.diff.formatted).never
|
594
|
+
$stdout.expects(:puts).with "Found 0 diff(s)."
|
595
|
+
|
596
|
+
with_config :brief => true do
|
597
|
+
assert Kronk::Cmd.render_diff(kronk.diff), "Expected no diff to succeed"
|
598
|
+
end
|
599
|
+
end
|
600
|
+
|
601
|
+
|
602
|
+
def test_render_response
|
603
|
+
kronk = Kronk.new
|
604
|
+
kronk.retrieve StringIO.new(mock_200_response)
|
605
|
+
|
606
|
+
$stdout.expects(:puts).with kronk.response.stringify
|
607
|
+
assert Kronk::Cmd.render_response(kronk.response),
|
608
|
+
"Expected render_response success for 200"
|
609
|
+
end
|
610
|
+
|
611
|
+
|
612
|
+
def test_render_response_lines
|
613
|
+
with_config :show_lines => true do
|
614
|
+
kronk = Kronk.new
|
615
|
+
kronk.retrieve StringIO.new(mock_200_response)
|
616
|
+
|
617
|
+
expected = Kronk::Diff.insert_line_nums kronk.response.stringify
|
618
|
+
$stdout.expects(:puts).with expected
|
619
|
+
|
620
|
+
assert Kronk::Cmd.render_response(kronk.response),
|
621
|
+
"Expected render_response success"
|
622
|
+
end
|
623
|
+
end
|
624
|
+
|
625
|
+
|
626
|
+
def test_render_response_verbose
|
627
|
+
with_config :verbose => true do
|
628
|
+
kronk = Kronk.new
|
629
|
+
io = StringIO.new(mock_200_response)
|
630
|
+
|
631
|
+
$stdout.expects(:<<).with "Reading IO #{io}\n"
|
632
|
+
kronk.retrieve io
|
633
|
+
|
634
|
+
expected = kronk.response.stringify
|
635
|
+
$stdout.expects(:puts).with expected
|
636
|
+
$stdout.expects(:<<).with "\nResp. Time: #{kronk.response.time.to_f}\n"
|
637
|
+
|
638
|
+
assert Kronk::Cmd.render_response(kronk.response),
|
639
|
+
"Expected render_response success"
|
640
|
+
end
|
641
|
+
end
|
642
|
+
|
643
|
+
|
644
|
+
def test_render_response_failed
|
645
|
+
kronk = Kronk.new
|
646
|
+
kronk.retrieve StringIO.new(mock_302_response)
|
647
|
+
|
648
|
+
$stdout.expects(:puts).with kronk.response.stringify
|
649
|
+
assert !Kronk::Cmd.render_response(kronk.response),
|
650
|
+
"Expected render_response to fail on 302"
|
651
|
+
end
|
652
|
+
|
653
|
+
|
654
|
+
def test_error
|
655
|
+
msg = "OH NOES!"
|
656
|
+
$stderr.expects(:puts).with("\nError: #{msg}").twice
|
657
|
+
Kronk::Cmd.error msg, "This is bad!"
|
658
|
+
Kronk::Cmd.error msg
|
659
|
+
end
|
660
|
+
|
661
|
+
|
662
|
+
def test_error_verbose
|
663
|
+
msg = "OH NOES!"
|
664
|
+
$stderr.expects(:puts).with "\nError: #{msg}"
|
665
|
+
$stderr.expects(:puts).with "This is bad!"
|
666
|
+
|
667
|
+
with_config :verbose => true do
|
668
|
+
Kronk::Cmd.error msg, "This is bad!"
|
669
|
+
end
|
670
|
+
end
|
671
|
+
|
672
|
+
|
673
|
+
def test_verbose
|
674
|
+
msg = "BLAH BLAH BLAH"
|
675
|
+
|
676
|
+
with_config :verbose => true do
|
677
|
+
$stdout.expects(:<<).with "#{msg}\n"
|
678
|
+
Kronk::Cmd.verbose msg
|
679
|
+
end
|
680
|
+
|
681
|
+
with_config :verbose => false do
|
682
|
+
$stdout.expects(:<<).with("#{msg}\n").times(0)
|
683
|
+
Kronk::Cmd.verbose msg
|
684
|
+
end
|
685
|
+
end
|
686
|
+
|
687
|
+
|
688
|
+
def test_warn
|
689
|
+
msg = "OH NOES!"
|
690
|
+
$stderr.expects(:<<).with "Warning: #{msg}\n"
|
691
|
+
Kronk::Cmd.warn msg
|
692
|
+
end
|
693
|
+
|
694
|
+
|
695
|
+
def test_windows?
|
696
|
+
old_rb_platform = $RUBY_PLATFORM
|
697
|
+
$RUBY_PLATFORM = "something"
|
698
|
+
|
699
|
+
assert !Kronk::Cmd.windows?, "Expected non-windows platform"
|
700
|
+
|
701
|
+
%w{mswin mswindows mingw mingwin cygwin}.each do |platform|
|
702
|
+
$RUBY_PLATFORM = platform
|
703
|
+
assert Kronk::Cmd.windows?, "Expected windows platform"
|
704
|
+
end
|
705
|
+
|
706
|
+
$RUBY_PLATFORM = old_rb_platform
|
707
|
+
end
|
708
|
+
end
|