kronk 1.4.0 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
data/test/test_helper_methods.rb
CHANGED
@@ -7,8 +7,8 @@ class TestHelperMethods < Test::Unit::TestCase
|
|
7
7
|
def setup
|
8
8
|
io = StringIO.new mock_resp("200_response.json")
|
9
9
|
@json = JSON.parse mock_resp("200_response.json").split("\r\n\r\n")[1]
|
10
|
-
@mock_resp = Kronk::Response.
|
11
|
-
@mock_resp2 = Kronk::Response.
|
10
|
+
@mock_resp = Kronk::Response.new io
|
11
|
+
@mock_resp2 = Kronk::Response.new \
|
12
12
|
StringIO.new mock_resp("200_response.json")
|
13
13
|
|
14
14
|
Kronk::Request.stubs(:retrieve).returns @mock_resp
|
@@ -134,7 +134,7 @@ class TestHelperMethods < Test::Unit::TestCase
|
|
134
134
|
|
135
135
|
|
136
136
|
def test_retrieve_unparsable
|
137
|
-
mock_resp = Kronk::Response.
|
137
|
+
mock_resp = Kronk::Response.new StringIO.new(mock_200_response)
|
138
138
|
|
139
139
|
Kronk::Request.expects(:retrieve).
|
140
140
|
with("host.com", :foo => "bar").returns mock_resp
|
@@ -152,7 +152,7 @@ class TestHelperMethods < Test::Unit::TestCase
|
|
152
152
|
|
153
153
|
|
154
154
|
def test_retrieve_two_unparsable
|
155
|
-
mock_resp = Kronk::Response.
|
155
|
+
mock_resp = Kronk::Response.new StringIO.new(mock_200_response)
|
156
156
|
|
157
157
|
Kronk::Request.expects(:retrieve).
|
158
158
|
with("host1.com", :foo => "bar").returns mock_resp
|
@@ -0,0 +1,103 @@
|
|
1
|
+
require 'test/test_helper'
|
2
|
+
|
3
|
+
class TestInputReader < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@input = Kronk::Player::InputReader.new "/path1\n/path2\n/path3\n"
|
7
|
+
end
|
8
|
+
|
9
|
+
|
10
|
+
def test_init
|
11
|
+
input = Kronk::Player::InputReader.new "foobar"
|
12
|
+
assert_equal StringIO, input.io.class
|
13
|
+
assert_equal Kronk::Player::RequestParser, input.parser
|
14
|
+
assert_equal [], input.buffer
|
15
|
+
|
16
|
+
|
17
|
+
File.open("test/mocks/200_response.txt") do |file|
|
18
|
+
input = Kronk::Player::InputReader.new file, "mock parser"
|
19
|
+
assert_equal file, input.io
|
20
|
+
assert_equal "mock parser", input.parser
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
def test_get_next
|
26
|
+
(1..3).each do |num|
|
27
|
+
expected = {
|
28
|
+
:uri_suffix => "/path#{num}"
|
29
|
+
}
|
30
|
+
assert_equal expected, @input.get_next
|
31
|
+
end
|
32
|
+
|
33
|
+
assert_nil @input.get_next
|
34
|
+
assert @input.eof?
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
def test_get_next_full_http_request
|
39
|
+
expected = {
|
40
|
+
:headers => {
|
41
|
+
"Accept" => "*/*",
|
42
|
+
"User-Agent" => "Kronk/1.5.0 (http://github.com/yaksnrainbows/kronk)",
|
43
|
+
"Authorization" => "Basic Ym9iOmZvb2Jhcg=="
|
44
|
+
},
|
45
|
+
:http_method => "GET",
|
46
|
+
:uri_suffix => "/path",
|
47
|
+
:host => "example.com:80",
|
48
|
+
}
|
49
|
+
|
50
|
+
File.open("test/mocks/get_request.txt") do |file|
|
51
|
+
@input = Kronk::Player::InputReader.new file
|
52
|
+
|
53
|
+
assert_equal expected, @input.get_next
|
54
|
+
assert_nil @input.get_next
|
55
|
+
assert @input.eof?
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
def test_get_next_multiple_http_requests
|
61
|
+
expected = {
|
62
|
+
:headers => {
|
63
|
+
"Accept" => "*/*",
|
64
|
+
"User-Agent" => "Kronk/1.5.0 (http://github.com/yaksnrainbows/kronk)",
|
65
|
+
"Authorization" => "Basic Ym9iOmZvb2Jhcg=="
|
66
|
+
},
|
67
|
+
:http_method => "GET",
|
68
|
+
:uri_suffix => "/path",
|
69
|
+
:host => "example.com:80",
|
70
|
+
}
|
71
|
+
|
72
|
+
req_str = File.read("test/mocks/get_request.txt") * 5
|
73
|
+
|
74
|
+
@input = Kronk::Player::InputReader.new req_str
|
75
|
+
|
76
|
+
5.times do
|
77
|
+
assert_equal expected, @input.get_next
|
78
|
+
end
|
79
|
+
|
80
|
+
assert_nil @input.get_next
|
81
|
+
assert @input.eof?
|
82
|
+
end
|
83
|
+
|
84
|
+
|
85
|
+
def test_eof
|
86
|
+
assert !@input.eof?
|
87
|
+
|
88
|
+
old_io, @input.io = @input.io, nil
|
89
|
+
assert @input.eof?
|
90
|
+
|
91
|
+
@input.io = old_io
|
92
|
+
@input.io.close
|
93
|
+
assert @input.eof?
|
94
|
+
|
95
|
+
@input.io.reopen
|
96
|
+
@input.io.read
|
97
|
+
assert @input.io.eof?
|
98
|
+
assert @input.eof?
|
99
|
+
|
100
|
+
@input.buffer << "test"
|
101
|
+
assert !@input.eof?
|
102
|
+
end
|
103
|
+
end
|
data/test/test_kronk.rb
CHANGED
@@ -13,6 +13,7 @@ class TestKronk < Test::Unit::TestCase
|
|
13
13
|
:cache_file => Kronk::DEFAULT_CACHE_FILE,
|
14
14
|
:cookies_file => Kronk::DEFAULT_COOKIES_FILE,
|
15
15
|
:history_file => Kronk::DEFAULT_HISTORY_FILE,
|
16
|
+
:indentation => 1,
|
16
17
|
:default_host => "http://localhost:3000",
|
17
18
|
:diff_format => :ascii_diff,
|
18
19
|
:show_lines => false,
|
@@ -36,6 +37,7 @@ class TestKronk < Test::Unit::TestCase
|
|
36
37
|
:cache_file => Kronk::DEFAULT_CACHE_FILE,
|
37
38
|
:cookies_file => Kronk::DEFAULT_COOKIES_FILE,
|
38
39
|
:history_file => Kronk::DEFAULT_HISTORY_FILE,
|
40
|
+
:indentation => 1,
|
39
41
|
:show_lines => false,
|
40
42
|
:use_cookies => true,
|
41
43
|
:requires => [],
|
@@ -49,6 +51,11 @@ class TestKronk < Test::Unit::TestCase
|
|
49
51
|
|
50
52
|
Kronk.load_config
|
51
53
|
|
54
|
+
YAML.expects(:load_file).with("foobar").
|
55
|
+
returns mock_config
|
56
|
+
|
57
|
+
Kronk.load_config "foobar"
|
58
|
+
|
52
59
|
expected = {
|
53
60
|
:content_types => {
|
54
61
|
'soap' => "SOAPParser",
|
@@ -62,6 +69,7 @@ class TestKronk < Test::Unit::TestCase
|
|
62
69
|
:cache_file => Kronk::DEFAULT_CACHE_FILE,
|
63
70
|
:cookies_file => Kronk::DEFAULT_COOKIES_FILE,
|
64
71
|
:history_file => Kronk::DEFAULT_HISTORY_FILE,
|
72
|
+
:indentation => 1,
|
65
73
|
:requires => [],
|
66
74
|
:show_lines => false,
|
67
75
|
:use_cookies => true,
|
@@ -76,17 +84,6 @@ class TestKronk < Test::Unit::TestCase
|
|
76
84
|
end
|
77
85
|
|
78
86
|
|
79
|
-
def test_make_config_file
|
80
|
-
file = mock 'file'
|
81
|
-
file.expects(:<<).with Kronk::DEFAULT_CONFIG.to_yaml
|
82
|
-
File.expects(:directory?).with(Kronk::CONFIG_DIR).returns false
|
83
|
-
Dir.expects(:mkdir).with Kronk::CONFIG_DIR
|
84
|
-
File.expects(:open).with(Kronk::DEFAULT_CONFIG_FILE, "w+").yields file
|
85
|
-
|
86
|
-
Kronk.make_config_file
|
87
|
-
end
|
88
|
-
|
89
|
-
|
90
87
|
def test_parser_for
|
91
88
|
assert_equal JSON, Kronk.parser_for('json')
|
92
89
|
assert_equal Kronk::XMLParser, Kronk.parser_for('xml')
|
@@ -94,25 +91,34 @@ class TestKronk < Test::Unit::TestCase
|
|
94
91
|
end
|
95
92
|
|
96
93
|
|
97
|
-
def
|
98
|
-
|
99
|
-
Kronk.config[:
|
94
|
+
def test_history
|
95
|
+
Kronk.instance_variable_set "@history", nil
|
96
|
+
File.expects(:file?).with(Kronk.config[:history_file]).returns true
|
97
|
+
File.expects(:read).with(Kronk.config[:history_file]).
|
98
|
+
returns "history1\nhistory2"
|
99
|
+
|
100
|
+
assert_equal %w{history1 history2}, Kronk.history
|
101
|
+
end
|
100
102
|
|
101
|
-
assert_raises LoadError do
|
102
|
-
Kronk.load_requires
|
103
|
-
end
|
104
103
|
|
105
|
-
|
104
|
+
def test_history_no_file
|
105
|
+
Kronk.instance_variable_set "@history", nil
|
106
|
+
File.expects(:file?).with(Kronk.config[:history_file]).returns false
|
107
|
+
File.expects(:read).with(Kronk.config[:history_file]).never
|
108
|
+
|
109
|
+
assert_equal [], Kronk.history
|
106
110
|
end
|
107
111
|
|
108
112
|
|
109
|
-
def
|
110
|
-
|
111
|
-
|
113
|
+
def test_save_history
|
114
|
+
Kronk.instance_variable_set "@history", %w{hist1 hist2 hist1 hist3}
|
115
|
+
file = StringIO.new
|
116
|
+
File.expects(:open).with(Kronk.config[:history_file], "w").yields file
|
112
117
|
|
113
|
-
|
118
|
+
Kronk.save_history
|
114
119
|
|
115
|
-
|
120
|
+
file.rewind
|
121
|
+
assert_equal "hist1\nhist2\nhist3", file.read
|
116
122
|
end
|
117
123
|
|
118
124
|
|
@@ -126,18 +132,18 @@ class TestKronk < Test::Unit::TestCase
|
|
126
132
|
end
|
127
133
|
|
128
134
|
|
129
|
-
def
|
135
|
+
def test_options_for_uri
|
130
136
|
with_uri_options do
|
131
137
|
assert_equal mock_uri_options['example'],
|
132
|
-
Kronk.
|
138
|
+
Kronk.new.options_for_uri("http://example.com/path")
|
133
139
|
|
134
140
|
assert_equal Hash.new,
|
135
|
-
Kronk.
|
141
|
+
Kronk.new.options_for_uri("http://thing.com/path")
|
136
142
|
end
|
137
143
|
end
|
138
144
|
|
139
145
|
|
140
|
-
def
|
146
|
+
def test_options_for_uri_query
|
141
147
|
data = {
|
142
148
|
"add" => "this",
|
143
149
|
"foo" => {
|
@@ -156,22 +162,22 @@ class TestKronk < Test::Unit::TestCase
|
|
156
162
|
}
|
157
163
|
|
158
164
|
%w{uri_query hash_query}.each do |qtype|
|
159
|
-
opts = Kronk.
|
160
|
-
|
165
|
+
opts = Kronk.new(:query => data, :data => data).
|
166
|
+
options_for_uri("http://#{qtype}.com")
|
161
167
|
|
162
168
|
assert_equal expected, opts
|
163
169
|
end
|
164
170
|
|
165
|
-
opts = Kronk.
|
171
|
+
opts = Kronk.new.options_for_uri("http://uri_query.com")
|
166
172
|
assert_equal mock_uri_options['uri_query'], opts
|
167
173
|
end
|
168
174
|
end
|
169
175
|
|
170
176
|
|
171
|
-
def
|
177
|
+
def test_options_for_uri_headers
|
172
178
|
with_uri_options do
|
173
|
-
opts = Kronk.
|
174
|
-
|
179
|
+
opts = Kronk.new(:headers => {'hdr2' => 2, 'hdr3' => 3}).
|
180
|
+
options_for_uri("http://headers.example.com")
|
175
181
|
|
176
182
|
expected = {
|
177
183
|
:headers => {
|
@@ -187,10 +193,10 @@ class TestKronk < Test::Unit::TestCase
|
|
187
193
|
end
|
188
194
|
|
189
195
|
|
190
|
-
def
|
196
|
+
def test_options_for_uri_auth
|
191
197
|
with_uri_options do
|
192
|
-
opts = Kronk.
|
193
|
-
|
198
|
+
opts = Kronk.new(:auth => {:username => "bob"}).
|
199
|
+
options_for_uri("http://auth.example.com")
|
194
200
|
|
195
201
|
expected = {
|
196
202
|
:auth => {
|
@@ -205,7 +211,7 @@ class TestKronk < Test::Unit::TestCase
|
|
205
211
|
end
|
206
212
|
|
207
213
|
|
208
|
-
def
|
214
|
+
def test_options_for_uri_proxy
|
209
215
|
with_uri_options do
|
210
216
|
expected = {
|
211
217
|
:proxy => {
|
@@ -216,20 +222,20 @@ class TestKronk < Test::Unit::TestCase
|
|
216
222
|
}
|
217
223
|
}
|
218
224
|
|
219
|
-
opts = Kronk.
|
220
|
-
|
225
|
+
opts = Kronk.new(:proxy => "proxy.com").
|
226
|
+
options_for_uri("http://proxy.com")
|
221
227
|
|
222
228
|
assert_equal expected, opts
|
223
229
|
|
224
|
-
opts = Kronk.
|
225
|
-
|
230
|
+
opts = Kronk.new(:proxy => {:address => "proxy.com"}).
|
231
|
+
options_for_uri("http://proxy.com")
|
226
232
|
|
227
233
|
assert_equal expected, opts
|
228
234
|
end
|
229
235
|
end
|
230
236
|
|
231
237
|
|
232
|
-
def
|
238
|
+
def test_options_for_uri_str_proxy
|
233
239
|
with_uri_options do
|
234
240
|
expected = {
|
235
241
|
:proxy => {
|
@@ -239,24 +245,24 @@ class TestKronk < Test::Unit::TestCase
|
|
239
245
|
}
|
240
246
|
}
|
241
247
|
|
242
|
-
opts = Kronk.
|
243
|
-
|
248
|
+
opts = Kronk.new(:proxy => {:username => "user", :password => "pass"}).
|
249
|
+
options_for_uri("http://strprox.com")
|
244
250
|
|
245
251
|
assert_equal expected, opts
|
246
252
|
|
247
|
-
opts = Kronk.
|
248
|
-
|
253
|
+
opts = Kronk.new(:proxy => "proxy.com").
|
254
|
+
options_for_uri("http://strprox.com")
|
249
255
|
|
250
256
|
assert_equal "proxy.com", opts[:proxy]
|
251
257
|
end
|
252
258
|
end
|
253
259
|
|
254
260
|
|
255
|
-
def
|
261
|
+
def test_options_for_uri_with_headers
|
256
262
|
with_uri_options do
|
257
263
|
%w{withhdrs withstrhdrs withtruehdrs}.each do |type|
|
258
|
-
opts = Kronk.
|
259
|
-
|
264
|
+
opts = Kronk.new(:with_headers => true).
|
265
|
+
options_for_uri "http://#{type}.com"
|
260
266
|
|
261
267
|
assert_equal true, opts[:with_headers]
|
262
268
|
end
|
@@ -264,39 +270,34 @@ class TestKronk < Test::Unit::TestCase
|
|
264
270
|
end
|
265
271
|
|
266
272
|
|
267
|
-
def
|
273
|
+
def test_options_for_uri_with_headers_arr
|
268
274
|
with_uri_options do
|
269
275
|
%w{withhdrs withstrhdrs}.each do |type|
|
270
|
-
opts = Kronk.
|
271
|
-
|
276
|
+
opts = Kronk.new(:with_headers => %w{hdr2 hdr3}).
|
277
|
+
options_for_uri "http://#{type}.com"
|
272
278
|
|
273
279
|
assert_equal %w{hdr1 hdr2 hdr3}.sort, opts[:with_headers].sort
|
274
280
|
end
|
275
281
|
|
276
|
-
opts = Kronk.
|
277
|
-
|
282
|
+
opts = Kronk.new(:with_headers => %w{hdr2 hdr3}).
|
283
|
+
options_for_uri "http://withtruehdrs.com"
|
278
284
|
|
279
285
|
assert_equal %w{hdr2 hdr3}, opts[:with_headers]
|
280
286
|
end
|
281
287
|
end
|
282
288
|
|
283
289
|
|
284
|
-
def
|
290
|
+
def test_options_for_uri_data_paths
|
285
291
|
expected = {
|
286
|
-
:only_data
|
287
|
-
:
|
288
|
-
:ignore_data => "ign1",
|
289
|
-
:ignore_data_with => %w{ign2 ign3}
|
292
|
+
:only_data => %w{path1 path2 path3},
|
293
|
+
:ignore_data => "ign1",
|
290
294
|
}
|
291
295
|
|
292
296
|
with_uri_options do
|
293
|
-
opts = Kronk.
|
294
|
-
|
295
|
-
:only_data_with => "only2",
|
296
|
-
:ignore_data_with => %w{ign2 ign3}
|
297
|
+
opts = Kronk.new(:only_data => %w{path2 path3}).
|
298
|
+
options_for_uri "http://focus_data.com"
|
297
299
|
|
298
300
|
opts[:only_data].sort!
|
299
|
-
opts[:only_data_with].sort!
|
300
301
|
|
301
302
|
assert_equal expected, opts
|
302
303
|
end
|
@@ -309,11 +310,11 @@ class TestKronk < Test::Unit::TestCase
|
|
309
310
|
:with_headers => true,
|
310
311
|
:raw => true
|
311
312
|
|
312
|
-
resp1 = Kronk
|
313
|
+
resp1 = Kronk.retrieve "test/mocks/200_response.json",
|
313
314
|
:with_headers => true,
|
314
315
|
:raw => true
|
315
316
|
|
316
|
-
resp2 = Kronk
|
317
|
+
resp2 = Kronk.retrieve "test/mocks/200_response.xml",
|
317
318
|
:with_headers => true,
|
318
319
|
:raw => true
|
319
320
|
|
@@ -361,6 +362,7 @@ class TestKronk < Test::Unit::TestCase
|
|
361
362
|
|
362
363
|
|
363
364
|
def test_clear_cookies
|
365
|
+
Kronk.instance_variable_set "@cookie_jar", nil
|
364
366
|
mock_cookie_jar = YAML.load_file("test/mocks/cookies.yml")
|
365
367
|
|
366
368
|
File.expects(:file?).with(Kronk::DEFAULT_COOKIES_FILE).returns true
|
@@ -385,10 +387,10 @@ class TestKronk < Test::Unit::TestCase
|
|
385
387
|
"test/mocks/200_response.xml",
|
386
388
|
:with_headers => true
|
387
389
|
|
388
|
-
resp1 = Kronk
|
390
|
+
resp1 = Kronk.retrieve "test/mocks/200_response.json",
|
389
391
|
:with_headers => true
|
390
392
|
|
391
|
-
resp2 = Kronk
|
393
|
+
resp2 = Kronk.retrieve "test/mocks/200_response.xml",
|
392
394
|
:with_headers => true
|
393
395
|
|
394
396
|
exp_diff = Kronk::Diff.new_from_data \
|
@@ -399,103 +401,103 @@ class TestKronk < Test::Unit::TestCase
|
|
399
401
|
end
|
400
402
|
|
401
403
|
|
402
|
-
def
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
"general_info" => "<p>A Paint Your Own Pottery Studios..</p>",
|
417
|
-
"op_hours" => "Fri 1pm-7pm, Sat 10am-6pm, Sun 1pm-4pm, Appointments Available",
|
418
|
-
"payment_text" => "DISCOVER, AMEX, VISA, MASTERCARD",
|
419
|
-
"slogan" => "<p>Pottery YOU dress up</p>"
|
420
|
-
},
|
421
|
-
"distance" => 0.0,
|
422
|
-
"has_detail_page" => true,
|
423
|
-
"headings" => [
|
424
|
-
"Pottery"
|
425
|
-
],
|
426
|
-
"id" => "1234",
|
427
|
-
"impression_id" => "mock_iid",
|
428
|
-
"improvable" => true,
|
429
|
-
"latitude" => 42.882561,
|
430
|
-
"listing_id" => "1234",
|
431
|
-
"listing_type" => "free",
|
432
|
-
"longitude" => -85.759586,
|
433
|
-
"mappable" => true,
|
434
|
-
"name" => "Naked Plates",
|
435
|
-
"omit_address" => false,
|
436
|
-
"omit_phone" => false,
|
437
|
-
"phone" => "6168055326",
|
438
|
-
"rateable" => true,
|
439
|
-
"rating_count" => 0,
|
440
|
-
"red_listing" => false,
|
441
|
-
"state" => "MI",
|
442
|
-
"website" => "http://example.com",
|
443
|
-
"year_established" => "1996",
|
444
|
-
"zip" => "49418"
|
445
|
-
},
|
446
|
-
"original_request" => {
|
447
|
-
"id" => "1234"
|
448
|
-
},
|
449
|
-
"request_id" => "mock_rid"
|
450
|
-
}
|
451
|
-
STR
|
452
|
-
assert_equal expected.strip, str
|
404
|
+
def test_follow_redirect_infinite
|
405
|
+
res = Kronk::Response.new mock_301_response
|
406
|
+
req = Kronk::Request.new "http://www.google.com/"
|
407
|
+
req.stubs(:retrieve).returns res
|
408
|
+
|
409
|
+
Kronk::Request.stubs(:new).with("http://www.google.com/",{}).returns req
|
410
|
+
Kronk::Request.expects(:new).
|
411
|
+
with("http://www.google.com/", :follow_redirects => true).returns req
|
412
|
+
|
413
|
+
assert_raises Timeout::Error do
|
414
|
+
timeout(2) do
|
415
|
+
Kronk.retrieve "http://www.google.com/", :follow_redirects => true
|
416
|
+
end
|
417
|
+
end
|
453
418
|
end
|
454
419
|
|
455
420
|
|
456
|
-
def
|
457
|
-
|
458
|
-
|
459
|
-
|
421
|
+
def test_num_follow_redirect
|
422
|
+
res = Kronk::Response.new mock_301_response
|
423
|
+
req = Kronk::Request.new "http://www.google.com/"
|
424
|
+
req.stubs(:retrieve).returns res
|
425
|
+
|
426
|
+
Kronk::Request.expects(:new).
|
427
|
+
with("http://www.google.com/",{}).returns(req).times(3)
|
428
|
+
|
429
|
+
Kronk::Request.expects(:new).
|
430
|
+
with("http://www.google.com/", :follow_redirects => 3).returns req
|
431
|
+
|
432
|
+
Kronk.retrieve "http://www.google.com/", :follow_redirects => 3
|
460
433
|
end
|
461
434
|
|
462
435
|
|
463
|
-
def
|
464
|
-
|
465
|
-
|
436
|
+
def test_follow_redirect_no_redirect
|
437
|
+
res = Kronk::Response.new mock_200_response
|
438
|
+
req = Kronk::Request.new "http://www.google.com/"
|
439
|
+
req.stubs(:retrieve).returns res
|
440
|
+
|
441
|
+
Kronk::Request.expects(:new).with("http://www.google.com/",{}).never
|
442
|
+
Kronk::Request.expects(:new).
|
443
|
+
with("http://www.google.com/", :follow_redirects => true).returns req
|
444
|
+
|
445
|
+
Kronk.retrieve "http://www.google.com/", :follow_redirects => true
|
446
|
+
end
|
466
447
|
|
467
|
-
expected = JSON.parse \
|
468
|
-
File.read("test/mocks/200_response.json").split("\r\n\r\n")[1]
|
469
448
|
|
470
|
-
|
449
|
+
def test_do_not_follow_redirect
|
450
|
+
res = Kronk::Response.new mock_302_response
|
451
|
+
req = Kronk::Request.new "http://www.google.com/"
|
452
|
+
req.stubs(:retrieve).returns res
|
471
453
|
|
472
|
-
|
454
|
+
Kronk::Request.expects(:new).with("http://www.google.com/",{}).never
|
455
|
+
Kronk::Request.expects(:new).
|
456
|
+
with("http://www.google.com/", :follow_redirects => false).returns req
|
457
|
+
|
458
|
+
Kronk.retrieve "http://www.google.com/", :follow_redirects => false
|
473
459
|
end
|
474
460
|
|
475
461
|
|
476
|
-
def
|
477
|
-
|
462
|
+
def test_compare_data_inst
|
463
|
+
kronk = Kronk.new :with_headers => true
|
464
|
+
diff = kronk.compare "test/mocks/200_response.json",
|
465
|
+
"test/mocks/200_response.xml"
|
466
|
+
|
467
|
+
json_resp = Kronk::Response.new(File.read("test/mocks/200_response.json"))
|
468
|
+
xml_resp = Kronk::Response.new(File.read("test/mocks/200_response.xml"))
|
478
469
|
|
479
|
-
|
470
|
+
assert_equal xml_resp.raw, kronk.response.raw
|
471
|
+
assert_equal xml_resp.raw, kronk.responses.last.raw
|
472
|
+
assert_equal json_resp.raw, kronk.responses.first.raw
|
473
|
+
assert_equal 2, kronk.responses.length
|
474
|
+
assert_equal diff, kronk.diff
|
480
475
|
|
481
|
-
|
476
|
+
resp1 = kronk.retrieve "test/mocks/200_response.xml"
|
477
|
+
resp2 = kronk.retrieve "test/mocks/200_response.json"
|
478
|
+
|
479
|
+
assert_equal json_resp.raw, kronk.response.raw
|
480
|
+
assert_equal json_resp.raw, kronk.responses.last.raw
|
481
|
+
assert_equal 1, kronk.responses.length
|
482
|
+
assert_equal nil, kronk.diff
|
483
|
+
|
484
|
+
exp_diff = Kronk::Diff.new_from_data \
|
485
|
+
resp2.selective_data(:with_headers => true),
|
486
|
+
resp1.selective_data(:with_headers => true)
|
487
|
+
|
488
|
+
assert_equal exp_diff.formatted, diff.formatted
|
482
489
|
end
|
483
490
|
|
484
491
|
|
485
492
|
def test_parse_data_path_args
|
486
493
|
options = {}
|
487
|
-
argv = %w{this is --argv -- one -two -- -three four
|
488
|
-
|
489
|
-
Kronk::Cmd.expects(:warn).times(2)
|
494
|
+
argv = %w{this is --argv -- one -two -- -three four}
|
490
495
|
|
491
496
|
options = Kronk::Cmd.parse_data_path_args options, argv
|
492
497
|
|
493
498
|
assert_equal %w{one four}, options[:only_data]
|
494
499
|
assert_equal %w{two - three}, options[:ignore_data]
|
495
500
|
|
496
|
-
assert_equal %w{parents}, options[:only_data_with]
|
497
|
-
assert_equal %w{not_parents}, options[:ignore_data_with]
|
498
|
-
|
499
501
|
assert_equal %w{this is --argv}, argv
|
500
502
|
end
|
501
503
|
|
@@ -558,7 +560,6 @@ STR
|
|
558
560
|
},
|
559
561
|
'focus_data' => {
|
560
562
|
:only_data => %w{path1 path2},
|
561
|
-
:only_data_with => "only1",
|
562
563
|
:ignore_data => "ign1"
|
563
564
|
}
|
564
565
|
}
|