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/test/test_request.rb CHANGED
@@ -2,173 +2,129 @@ require 'test/test_helper'
2
2
 
3
3
  class TestRequest < Test::Unit::TestCase
4
4
 
5
- def test_follow_redirect
6
- resp = mock "resp"
7
- resp.expects(:[]).with("Location").returns "http://example.com"
5
+ def test_parse
6
+ raw = "POST /foobar\r\nAccept: json\r\nHost: example.com\r\n\r\nfoo=bar"
7
+ req = Kronk::Request.parse(raw)
8
8
 
9
- options = {:follow_redirects => true, :http_method => :get}
10
- Kronk::Request.expects(:retrieve_uri).with("http://example.com", options)
11
-
12
- Kronk::Request.follow_redirect resp, options
9
+ assert_equal Kronk::Request, req.class
10
+ assert_equal URI.parse("http://example.com/foobar"), req.uri
11
+ assert_equal "json", req.headers['Accept']
12
+ assert_equal "foo=bar", req.body
13
13
  end
14
14
 
15
15
 
16
- def test_num_follow_redirect
17
- resp = mock "resp"
18
- resp.expects(:[]).with("Location").returns "http://example.com"
19
-
20
- options = {:follow_redirects => 1}
21
- Kronk::Request.expects(:retrieve_uri).
22
- with "http://example.com", :follow_redirects => 0, :http_method => :get
23
-
24
- Kronk::Request.follow_redirect resp, options
25
- end
26
-
27
-
28
- def test_follow_redirect?
29
- resp = mock "resp"
30
- resp.expects(:code).returns "300"
31
-
32
- assert Kronk::Request.follow_redirect?(resp, true)
33
-
34
- resp = mock "resp"
35
- resp.expects(:code).returns "300"
36
-
37
- assert Kronk::Request.follow_redirect?(resp, 1)
16
+ def test_parse_invalid
17
+ assert_raises Kronk::Request::ParseError do
18
+ Kronk::Request.parse "thing\nfoo\n"
19
+ end
20
+ assert_raises Kronk::Request::ParseError do
21
+ Kronk::Request.parse ""
22
+ end
38
23
  end
39
24
 
40
25
 
41
- def test_dont_follow_redirect?
42
- resp = mock "resp"
43
- resp.expects(:code).returns "300"
26
+ def test_parse_to_hash
27
+ expected = {:uri_suffix => "/foobar"}
28
+ assert_equal expected, Kronk::Request.parse_to_hash("/foobar")
44
29
 
45
- assert !Kronk::Request.follow_redirect?(resp, false)
30
+ expected = {:http_method => "GET", :uri_suffix => "/foobar"}
31
+ assert_equal expected, Kronk::Request.parse_to_hash("GET /foobar")
46
32
 
47
- resp = mock "resp"
48
- resp.expects(:code).returns "300"
33
+ expected.merge! :host => "example.com"
34
+ raw = "GET /foobar\r\nHost: example.com"
35
+ assert_equal expected, Kronk::Request.parse_to_hash(raw)
49
36
 
50
- assert !Kronk::Request.follow_redirect?(resp, 0)
37
+ expected.merge! :http_method => "POST",
38
+ :data => "foo=bar",
39
+ :headers => {'Accept' => 'json'}
51
40
 
52
- resp = mock "resp"
53
- resp.expects(:code).returns "200"
54
-
55
- assert !Kronk::Request.follow_redirect?(resp, true)
41
+ raw = "POST /foobar\r\nAccept: json\r\nHost: example.com\r\n\r\nfoo=bar"
42
+ assert_equal expected, Kronk::Request.parse_to_hash(raw)
56
43
  end
57
44
 
58
45
 
59
- def test_retrieve_live
60
- query = "http://example.com"
61
- options = {:foo => "bar"}
62
- Kronk::Request.expects(:retrieve_uri).with query, options
63
-
64
- Kronk::Request.retrieve query, options
46
+ def test_parse_to_hash_invalid
47
+ assert_nil Kronk::Request.parse_to_hash("thing\nfoo\n")
48
+ assert_nil Kronk::Request.parse_to_hash("")
65
49
  end
66
50
 
67
51
 
68
- def test_retrieve_cached
69
- query = "path/to/file.txt"
70
- options = {:foo => "bar"}
71
- File.expects(:file?).with(query).returns true
72
- Kronk::Request.expects(:retrieve_file).with query, options
73
-
74
- Kronk::Request.retrieve query, options
75
- end
52
+ def test_retrieve_post
53
+ expect_request "POST", "http://example.com/request/path?foo=bar",
54
+ :data => {'test' => 'thing'}, :headers => {'X-THING' => 'thing'}
76
55
 
56
+ resp = Kronk::Request.new("http://example.com/request/path?foo=bar",
57
+ :data => 'test=thing', :headers => {'X-THING' => 'thing'},
58
+ :http_method => :post).retrieve
77
59
 
78
- def test_retrieve_file
79
- resp = Kronk::Request.retrieve_file "test/mocks/200_response.txt"
80
60
  assert_equal mock_200_response, resp.raw
81
- assert_equal "200", resp.code
82
61
  end
83
62
 
84
63
 
85
- def test_retrieve_file_redirect
86
- resp2 = Kronk::Request.retrieve_file "test/mocks/200_response.txt"
87
- Kronk::Request.expects(:follow_redirect).returns resp2
88
-
89
- resp = Kronk::Request.retrieve_file "test/mocks/301_response.txt",
90
- :follow_redirects => true
91
-
92
- assert_equal mock_200_response, resp.raw
93
- assert_equal "200", resp.code
64
+ def test_build_uri
65
+ uri = Kronk::Request.build_uri "https://example.com"
66
+ assert_equal URI.parse("https://example.com"), uri
94
67
  end
95
68
 
96
69
 
97
- def test_retrieve_uri
98
- expect_request "GET", "http://example.com/request/path?foo=bar"
99
- Kronk::Request.retrieve_uri "http://example.com/request/path?foo=bar"
70
+ def test_build_uri_string
71
+ uri = Kronk::Request.build_uri "example.com"
72
+ assert_equal "http://example.com", uri.to_s
100
73
  end
101
74
 
102
75
 
103
- def test_retrieve_uri_redirect
104
- resp = expect_request "GET", "http://example.com/request/path?foo=bar",
105
- :status => '301'
106
-
107
- Kronk::Request.expects(:follow_redirect).
108
- with resp, :follow_redirects => true,
109
- :headers => {'User-Agent' => Kronk::USER_AGENTS['kronk']},
110
- :timeout => nil
111
-
112
- Kronk::Request.retrieve_uri "http://example.com/request/path?foo=bar",
113
- :follow_redirects => true
76
+ def test_build_uri_localhost
77
+ uri = Kronk::Request.build_uri "/path/to/resource"
78
+ assert_equal "http://localhost:3000/path/to/resource", uri.to_s
114
79
  end
115
80
 
116
81
 
117
- def test_retrieve_uri_redirect_3_times
118
- resp = expect_request "POST", "http://example.com/request/path?foo=bar",
119
- :status => '301', :data => "foo=bar"
82
+ def test_build_uri_query_hash
83
+ query = {'a' => '1', 'b' => '2'}
84
+ uri = Kronk::Request.build_uri "example.com/path", :query => query
120
85
 
121
- Kronk::Request.expects(:follow_redirect).
122
- with resp, :follow_redirects => 3, :data => {:foo => "bar"},
123
- :headers => {'User-Agent' => Kronk::USER_AGENTS['kronk']},
124
- :timeout => nil
125
-
126
- Kronk::Request.retrieve_uri "http://example.com/request/path?foo=bar",
127
- :follow_redirects => 3, :data => {:foo => "bar"}
86
+ assert_equal query, Kronk::Request.parse_nested_query(uri.query)
128
87
  end
129
88
 
130
89
 
131
- def test_retrieve_uri_redirect_none
132
- expect_request "GET", "http://example.com/request/path?foo=bar",
133
- :status => 301
90
+ def test_build_uri_query_hash_str
91
+ query = {'a' => '1', 'b' => '2'}
92
+ uri = Kronk::Request.build_uri "example.com/path?c=3", :query => query
134
93
 
135
- Kronk::Request.expects(:follow_redirect).never
136
-
137
- Kronk::Request.retrieve_uri "http://example.com/request/path?foo=bar"
94
+ assert_equal({'a' => '1', 'b' => '2', 'c' => '3'},
95
+ Kronk::Request.parse_nested_query(uri.query))
138
96
  end
139
97
 
140
98
 
141
- def test_retrieve_uri_post
142
- expect_request "POST", "http://example.com/request/path?foo=bar",
143
- :data => 'test=thing', :headers => {'X-THING' => 'thing'}
99
+ def test_build_uri_suffix
100
+ uri = Kronk::Request.build_uri "http://example.com/path",
101
+ :uri_suffix => "/to/resource"
144
102
 
145
- Kronk::Request.retrieve_uri "http://example.com/request/path?foo=bar",
146
- :http_method => :post,
147
- :data => {:test => "thing"},
148
- :headers => {'X-THING' => 'thing'}
103
+ assert_equal "http://example.com/path/to/resource", uri.to_s
149
104
  end
150
105
 
151
106
 
152
- def test_call_post
153
- expect_request "POST", "http://example.com/request/path?foo=bar",
154
- :data => {'test' => 'thing'}, :headers => {'X-THING' => 'thing'}
155
-
156
- resp = Kronk::Request.call :post, "http://example.com/request/path?foo=bar",
157
- :data => 'test=thing', :headers => {'X-THING' => 'thing'}
107
+ def test_build_uri_from_uri
108
+ query = {'a' => '1', 'b' => '2'}
109
+ uri = Kronk::Request.build_uri URI.parse("http://example.com/path"),
110
+ :query => query, :uri_suffix => "/to/resource"
158
111
 
159
- assert_equal mock_200_response, resp.raw
112
+ assert_equal "example.com", uri.host
113
+ assert_equal "/path/to/resource", uri.path
114
+ assert_equal query, Kronk::Request.parse_nested_query(uri.query)
160
115
  end
161
116
 
162
117
 
163
- def test_call_get
118
+ def test_retrieve_get
164
119
  expect_request "GET", "http://example.com/request/path?foo=bar"
165
- resp = Kronk::Request.call :get, "http://example.com/request/path?foo=bar"
120
+ resp =
121
+ Kronk::Request.new("http://example.com/request/path?foo=bar").retrieve
166
122
 
167
123
  assert_equal mock_200_response, resp.raw
168
124
  end
169
125
 
170
126
 
171
- def test_call_cookies
127
+ def test_retrieve_cookies
172
128
  Kronk.cookie_jar.expects(:get_cookie_header).
173
129
  with("http://example.com/request/path?foo=bar").returns "mock_cookie"
174
130
 
@@ -178,24 +134,24 @@ class TestRequest < Test::Unit::TestCase
178
134
  expect_request "GET", "http://example.com/request/path?foo=bar",
179
135
  :headers => {'Cookie' => "mock_cookie", 'User-Agent' => "kronk"}
180
136
 
181
- resp = Kronk::Request.call :get, "http://example.com/request/path",
182
- :query => "foo=bar", :headers => {'User-Agent' => "kronk"}
137
+ resp = Kronk::Request.new("http://example.com/request/path",
138
+ :query => "foo=bar", :headers => {'User-Agent' => "kronk"}).retrieve
183
139
  end
184
140
 
185
141
 
186
- def test_call_no_cookies_found
142
+ def test_retrieve_no_cookies_found
187
143
  Kronk.cookie_jar.expects(:get_cookie_header).
188
144
  with("http://example.com/request/path?foo=bar").returns ""
189
145
 
190
146
  expect_request "GET", "http://example.com/request/path?foo=bar",
191
147
  :headers => {'User-Agent' => "kronk"}
192
148
 
193
- resp = Kronk::Request.call :get, "http://example.com/request/path",
194
- :query => "foo=bar", :headers => {'User-Agent' => "kronk"}
149
+ resp = Kronk::Request.new("http://example.com/request/path",
150
+ :query => "foo=bar", :headers => {'User-Agent' => "kronk"}).retrieve
195
151
  end
196
152
 
197
153
 
198
- def test_call_no_cookies
154
+ def test_retrieve_no_cookies
199
155
  Kronk.cookie_jar.expects(:get_cookie_header).
200
156
  with("http://example.com/request/path?foo=bar").never
201
157
 
@@ -204,13 +160,13 @@ class TestRequest < Test::Unit::TestCase
204
160
  expect_request "GET", "http://example.com/request/path?foo=bar",
205
161
  :headers => {'User-Agent' => "kronk"}
206
162
 
207
- resp = Kronk::Request.call :get, "http://example.com/request/path",
163
+ resp = Kronk::Request.new("http://example.com/request/path",
208
164
  :query => "foo=bar", :headers => {'User-Agent' => "kronk"},
209
- :no_cookies => true
165
+ :no_cookies => true).retrieve
210
166
  end
211
167
 
212
168
 
213
- def test_call_no_cookies_config
169
+ def test_retrieve_no_cookies_config
214
170
  old_config = Kronk.config[:use_cookies]
215
171
  Kronk.config[:use_cookies] = false
216
172
 
@@ -222,14 +178,14 @@ class TestRequest < Test::Unit::TestCase
222
178
  expect_request "GET", "http://example.com/request/path?foo=bar",
223
179
  :headers => {'User-Agent' => "kronk"}
224
180
 
225
- resp = Kronk::Request.call :get, "http://example.com/request/path",
226
- :query => "foo=bar", :headers => {'User-Agent' => "kronk"}
181
+ resp = Kronk::Request.new("http://example.com/request/path",
182
+ :query => "foo=bar", :headers => {'User-Agent' => "kronk"}).retrieve
227
183
 
228
184
  Kronk.config[:use_cookies] = old_config
229
185
  end
230
186
 
231
187
 
232
- def test_call_no_cookies_config_override
188
+ def test_retrieve_no_cookies_config_override
233
189
  old_config = Kronk.config[:use_cookies]
234
190
  Kronk.config[:use_cookies] = false
235
191
 
@@ -241,61 +197,77 @@ class TestRequest < Test::Unit::TestCase
241
197
  expect_request "GET", "http://example.com/request/path?foo=bar",
242
198
  :headers => {'User-Agent' => "kronk"}
243
199
 
244
- resp = Kronk::Request.call :get, "http://example.com/request/path",
200
+ resp = Kronk::Request.new("http://example.com/request/path",
245
201
  :query => "foo=bar", :headers => {'User-Agent' => "kronk"},
246
- :no_cookies => false
202
+ :no_cookies => false).retrieve
247
203
 
248
204
  Kronk.config[:use_cookies] = old_config
249
205
  end
250
206
 
251
207
 
252
- def test_call_cookies_already_set
208
+ def test_retrieve_cookies_already_set
253
209
  Kronk.cookie_jar.expects(:get_cookie_header).
254
210
  with("http://example.com/request/path?foo=bar").never
255
211
 
256
212
  expect_request "GET", "http://example.com/request/path?foo=bar",
257
- :headers => {'User-Agent' => "kronk", 'Cookie' => "mock_cookie"}
213
+ :headers => {'User-Agent' => "kronk"}
258
214
 
259
- resp = Kronk::Request.call :get, "http://example.com/request/path",
215
+ resp = Kronk::Request.new("http://example.com/request/path",
260
216
  :query => "foo=bar",
261
217
  :headers => {'User-Agent' => "kronk", 'Cookie' => "mock_cookie"},
262
- :no_cookies => true
218
+ :no_cookies => true).retrieve
263
219
  end
264
220
 
265
221
 
266
- def test_call_query
222
+ def test_retrieve_query
267
223
  expect_request "GET", "http://example.com/path?foo=bar"
268
- Kronk::Request.call :get, "http://example.com/path",
269
- :query => {:foo => :bar}
224
+ Kronk::Request.new("http://example.com/path",
225
+ :query => {:foo => :bar}).retrieve
270
226
  end
271
227
 
272
228
 
273
- def test_call_query_appended
229
+ def test_retrieve_query_appended
274
230
  expect_request "GET", "http://example.com/path?foo=bar&test=thing"
275
- Kronk::Request.call :get, "http://example.com/path?foo=bar",
276
- :query => {:test => :thing}
231
+ Kronk::Request.new("http://example.com/path?foo=bar",
232
+ :query => {:test => :thing}).retrieve
277
233
  end
278
234
 
279
235
 
280
- def test_call_query_appended_string
236
+ def test_retrieve_query_appended_string
281
237
  expect_request "GET", "http://example.com/path?foo=bar&test=thing"
282
- Kronk::Request.call :get, "http://example.com/path?foo=bar",
283
- :query => "test=thing"
238
+ Kronk::Request.new("http://example.com/path?foo=bar",
239
+ :query => "test=thing").retrieve
240
+ end
241
+
242
+
243
+ def test_auth_from_headers
244
+ req = Kronk::Request.parse File.read("test/mocks/get_request.txt")
245
+ assert_equal "bob", req.auth[:username]
246
+ assert_equal "foobar", req.auth[:password]
284
247
  end
285
248
 
286
249
 
287
- def test_call_basic_auth
250
+ def test_auth_from_headers_and_options
251
+ req = Kronk::Request.new "http://example.com/path",
252
+ :headers => {"Authorization" => "Basic Ym9iOmZvb2Jhcg=="},
253
+ :auth => {:password => "password"}
254
+ assert_equal "bob", req.auth[:username]
255
+ assert_equal "password", req.auth[:password]
256
+ end
257
+
258
+
259
+ def test_retrieve_basic_auth
288
260
  auth_opts = {:username => "user", :password => "pass"}
289
261
 
290
262
  expect_request "GET", "http://example.com" do |http, req, resp|
291
263
  req.expects(:basic_auth).with auth_opts[:username], auth_opts[:password]
292
264
  end
293
265
 
294
- resp = Kronk::Request.call :get, "http://example.com", :auth => auth_opts
266
+ resp = Kronk::Request.new("http://example.com", :auth => auth_opts).retrieve
295
267
  end
296
268
 
297
269
 
298
- def test_call_bad_basic_auth
270
+ def test_retrieve_bad_basic_auth
299
271
  auth_opts = {:password => "pass"}
300
272
 
301
273
  expect_request "GET", "http://example.com" do |http, req, resp|
@@ -303,81 +275,81 @@ class TestRequest < Test::Unit::TestCase
303
275
  never
304
276
  end
305
277
 
306
- resp = Kronk::Request.call :get, "http://example.com", :auth => auth_opts
278
+ resp = Kronk::Request.new("http://example.com", :auth => auth_opts).retrieve
307
279
  end
308
280
 
309
281
 
310
- def test_call_no_basic_auth
282
+ def test_retrieve_no_basic_auth
311
283
  expect_request "GET", "http://example.com" do |http, req, resp|
312
284
  req.expects(:basic_auth).never
313
285
  end
314
286
 
315
- resp = Kronk::Request.call :get, "http://example.com"
287
+ resp = Kronk::Request.new("http://example.com").retrieve
316
288
  end
317
289
 
318
290
 
319
- def test_call_ssl
291
+ def test_retrieve_ssl
320
292
  expr = expect_request "GET", "https://example.com" do |http, req, resp|
321
293
  req.expects(:use_ssl=).with true
322
294
  end
323
295
 
324
- resp = Kronk::Request.call :get, "https://example.com"
296
+ resp = Kronk::Request.new("https://example.com").retrieve
325
297
 
326
298
  assert_equal mock_200_response, resp.raw
327
299
  end
328
300
 
329
301
 
330
- def test_call_no_ssl
302
+ def test_retrieve_no_ssl
331
303
  expect_request "GET", "http://example.com" do |http, req, resp|
332
304
  req.expects(:use_ssl=).with(true).never
333
305
  end
334
306
 
335
- resp = Kronk::Request.call :get, "http://example.com"
307
+ resp = Kronk::Request.new("http://example.com").retrieve
336
308
 
337
309
  assert_equal mock_200_response, resp.raw
338
310
  end
339
311
 
340
312
 
341
- def test_call_user_agent_default
313
+ def test_retrieve_user_agent_default
342
314
  expect_request "GET", "http://example.com",
343
315
  :headers => {
344
316
  'User-Agent' =>
345
317
  "Kronk/#{Kronk::VERSION} (http://github.com/yaksnrainbows/kronk)"
346
318
  }
347
319
 
348
- resp = Kronk::Request.call :get, "http://example.com"
320
+ resp = Kronk::Request.new("http://example.com").retrieve
349
321
  end
350
322
 
351
323
 
352
- def test_call_user_agent_alias
324
+ def test_retrieve_user_agent_alias
353
325
  expect_request "GET", "http://example.com",
354
326
  :headers => {'User-Agent' => "Mozilla/5.0 (compatible; Konqueror/3; Linux)"}
355
327
 
356
- resp = Kronk::Request.call :get, "http://example.com",
357
- :user_agent => 'linux_konqueror'
328
+ resp = Kronk::Request.new("http://example.com",
329
+ :user_agent => 'linux_konqueror').retrieve
358
330
  end
359
331
 
360
332
 
361
- def test_call_user_agent_custom
333
+ def test_retrieve_user_agent_custom
362
334
  expect_request "GET", "http://example.com",
363
335
  :headers => {'User-Agent' => "custom user agent"}
364
336
 
365
- resp = Kronk::Request.call :get, "http://example.com",
366
- :user_agent => 'custom user agent'
337
+ resp = Kronk::Request.new("http://example.com",
338
+ :user_agent => 'custom user agent').retrieve
367
339
  end
368
340
 
369
341
 
370
- def test_call_user_agent_header_already_set
342
+ def test_retrieve_user_agent_header_already_set
371
343
  expect_request "GET", "http://example.com",
372
344
  :headers => {'User-Agent' => "custom user agent"}
373
345
 
374
- resp = Kronk::Request.call :get, "http://example.com",
346
+ resp = Kronk::Request.new("http://example.com",
375
347
  :user_agent => 'mac_safari',
376
- :headers => {'User-Agent' => "custom user agent"}
348
+ :headers => {'User-Agent' => "custom user agent"}).retrieve
377
349
  end
378
350
 
379
351
 
380
- def test_call_proxy
352
+ def test_retrieve_proxy
381
353
  proxy = {
382
354
  :address => "proxy.com",
383
355
  :username => "john",
@@ -389,11 +361,11 @@ class TestRequest < Test::Unit::TestCase
389
361
  Net::HTTP.expects(:Proxy).with("proxy.com", 8080, "john", "smith").
390
362
  returns Net::HTTP
391
363
 
392
- Kronk::Request.call :get, "http://example.com", :proxy => proxy
364
+ Kronk::Request.new("http://example.com", :proxy => proxy).retrieve
393
365
  end
394
366
 
395
367
 
396
- def test_call_proxy_string
368
+ def test_retrieve_proxy_string
397
369
  proxy = "proxy.com:8888"
398
370
 
399
371
  expect_request "GET", "http://example.com"
@@ -401,17 +373,17 @@ class TestRequest < Test::Unit::TestCase
401
373
  Net::HTTP.expects(:Proxy).with("proxy.com", "8888", nil, nil).
402
374
  returns Net::HTTP
403
375
 
404
- Kronk::Request.call :get, "http://example.com", :proxy => proxy
376
+ Kronk::Request.new("http://example.com", :proxy => proxy).retrieve
405
377
  end
406
378
 
407
379
 
408
380
  def test_proxy_nil
409
- assert_equal Net::HTTP, Kronk::Request.proxy(nil)
381
+ assert_equal Net::HTTP, Kronk::Request.new("host.com").use_proxy(nil)
410
382
  end
411
383
 
412
384
 
413
385
  def test_proxy_string
414
- proxy_class = Kronk::Request.proxy("myproxy.com:80")
386
+ proxy_class = Kronk::Request.new("host.com").use_proxy("myproxy.com:80")
415
387
 
416
388
  assert_equal "myproxy.com",
417
389
  proxy_class.instance_variable_get("@proxy_address")
@@ -424,7 +396,7 @@ class TestRequest < Test::Unit::TestCase
424
396
 
425
397
 
426
398
  def test_proxy_no_port
427
- proxy_class = Kronk::Request.proxy("myproxy.com")
399
+ proxy_class = Kronk::Request.new("host.com").use_proxy("myproxy.com")
428
400
 
429
401
  assert_equal "myproxy.com",
430
402
  proxy_class.instance_variable_get("@proxy_address")
@@ -437,10 +409,13 @@ class TestRequest < Test::Unit::TestCase
437
409
 
438
410
 
439
411
  def test_proxy_hash
440
- proxy_class = Kronk::Request.proxy "myproxy.com",
441
- :port => 8080,
442
- :username => "john",
443
- :password => "smith"
412
+ req = Kronk::Request.new "http://example.com",
413
+ :proxy => { :address => "myproxy.com",
414
+ :port => 8080,
415
+ :username => "john",
416
+ :password => "smith" }
417
+
418
+ proxy_class = req.instance_variable_get "@HTTP"
444
419
 
445
420
  assert_equal "myproxy.com",
446
421
  proxy_class.instance_variable_get("@proxy_address")
@@ -484,44 +459,4 @@ class TestRequest < Test::Unit::TestCase
484
459
  assert_equal "some/path", req.path
485
460
  assert_equal "vanilla kronk", req['User-Agent']
486
461
  end
487
-
488
-
489
- private
490
-
491
- def expect_request req_method, url, options={}
492
- uri = URI.parse url
493
-
494
- resp_io = StringIO.new(mock_200_response)
495
- resp = Kronk::Response.read_new resp_io #mock 'resp'
496
- resp.stubs(:code).returns(options[:status] || '200')
497
- resp.stubs(:to_hash).returns Hash.new
498
-
499
- http = mock 'http'
500
- socket = mock 'socket'
501
- req = mock 'req'
502
-
503
- data = options[:data]
504
- data &&= Hash === data ? Kronk::Request.build_query(data) : data.to_s
505
-
506
- headers = options[:headers] || Hash.new
507
- headers['User-Agent'] ||= Kronk.config[:user_agents]['kronk']
508
-
509
- socket.expects(:debug_output=)
510
-
511
- Kronk::Request::VanillaRequest.expects(:new).
512
- with(req_method, uri.request_uri, headers).returns req
513
-
514
- http.expects(:request).with(req, data).returns resp
515
-
516
- http.expects(:instance_variable_get).with("@socket").returns socket
517
-
518
- Net::HTTP.expects(:new).with(uri.host, uri.port).returns req
519
- req.expects(:start).yields(http).returns resp
520
-
521
- resp.expects(:read_raw_from).returns [nil, mock_200_response, nil]
522
-
523
- yield http, req, resp if block_given?
524
-
525
- resp
526
- end
527
462
  end