dkubb-fakeweb 1.1.2.6

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.
@@ -0,0 +1 @@
1
+ test example content
@@ -0,0 +1,21 @@
1
+ HTTP/1.1 200 OK
2
+ Cache-Control: private
3
+ Content-Type: text/html
4
+ Set-Cookie: PREF=ID=c1e3135f3180fabf:TM=1148188144:LM=1148188144:S=x9CJYC71XSKRA32Q; expires=Sun, 17-Jan-2038 19:14:07 GMT; path=/; domain=.google.com
5
+ Server: GWS/2.1
6
+ Transfer-Encoding: chunked
7
+ Date: Sun, 21 May 2006 05:09:04 GMT
8
+
9
+ <html><head><meta http-equiv="content-type" content="text/html; charset=ISO-8859-1"><title>Google</title><style><!--
10
+ body,td,a,p,.h{font-family:arial,sans-serif;}
11
+ .h{font-size: 20px;}
12
+ .q{color:#0000cc;}
13
+ -->
14
+ </style>
15
+ <script>
16
+ <!--
17
+ function sf(){document.f.q.focus();}
18
+ // -->
19
+ </script>
20
+ </head><body bgcolor=#ffffff text=#000000 link=#0000cc vlink=#551a8b alink=#ff0000 onLoad=sf() topmargin=3 marginheight=3><center><table border=0 cellspacing=0 cellpadding=0 width=100%><tr><td align=right nowrap><font size=-1><a href="/url?sa=p&pref=ig&pval=2&q=http://www.google.com/ig%3Fhl%3Den">Personalized Home</a>&nbsp;|&nbsp;<a href="https://www.google.com/accounts/Login?continue=http://www.google.com/&hl=en">Sign in</a></font></td></tr><tr height=4><td><img alt="" width=1 height=1></td></tr></table><img src="/intl/en/images/logo.gif" width=276 height=110 alt="Google"><br><br>
21
+ <form action=/search name=f><table border=0 cellspacing=0 cellpadding=4><tr><td nowrap><font size=-1><b>Web</b>&nbsp;&nbsp;&nbsp;&nbsp;<a id=1a class=q href="/imghp?hl=en&tab=wi&ie=UTF-8">Images</a>&nbsp;&nbsp;&nbsp;&nbsp;<a id=2a class=q href="http://groups.google.com/grphp?hl=en&tab=wg&ie=UTF-8">Groups</a>&nbsp;&nbsp;&nbsp;&nbsp;<a id=4a class=q href="http://news.google.com/nwshp?hl=en&tab=wn&ie=UTF-8">News</a>&nbsp;&nbsp;&nbsp;&nbsp;<a id=5a class=q href="http://froogle.google.com/frghp?hl=en&tab=wf&ie=UTF-8">Froogle</a>&nbsp;&nbsp;&nbsp;&nbsp;<a id=7a class=q href="/maphp?hl=en&tab=wl&ie=UTF-8">Maps</a>&nbsp;&nbsp;&nbsp;&nbsp;<b><a href="/intl/en/options/" class=q>more&nbsp;&raquo;</a></b></font></td></tr></table><table cellspacing=0 cellpadding=0><tr><td width=25%>&nbsp;</td><td align=center><input type=hidden name=hl value=en><input type=hidden name=ie value="ISO-8859-1"><input maxlength=2048 size=55 name=q value="" title="Google Search"><br><input type=submit value="Google Search" name=btnG><input type=submit value="I'm Feeling Lucky" name=btnI></td><td valign=top nowrap width=25%><font size=-2>&nbsp;&nbsp;<a href=/advanced_search?hl=en>Advanced Search</a><br>&nbsp;&nbsp;<a href=/preferences?hl=en>Preferences</a><br>&nbsp;&nbsp;<a href=/language_tools?hl=en>Language Tools</a></font></td></tr></table></form><br><br><font size=-1><a href="/intl/en/ads/">Advertising&nbsp;Programs</a> - <a href=/services/>Business Solutions</a> - <a href=/intl/en/about.html>About Google</a></font><p><font size=-2>&copy;2006 Google</font></p></center></body></html>
@@ -0,0 +1,41 @@
1
+ require File.join(File.dirname(__FILE__), "test_helper")
2
+
3
+ class TestFakeWebAllowNetConnect < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @original_allow_net_connect = FakeWeb.allow_net_connect?
7
+ end
8
+
9
+ def teardown
10
+ FakeWeb.allow_net_connect = @original_allow_net_connect
11
+ end
12
+
13
+
14
+ def test_unregistered_requests_are_passed_through_when_allow_net_connect_is_true
15
+ FakeWeb.allow_net_connect = true
16
+ setup_expectations_for_real_apple_hot_news_request
17
+ Net::HTTP.get(URI.parse("http://images.apple.com/main/rss/hotnews/hotnews.rss"))
18
+ end
19
+
20
+ def test_raises_for_unregistered_requests_when_allow_net_connect_is_false
21
+ FakeWeb.allow_net_connect = false
22
+ exception = assert_raise FakeWeb::NetConnectNotAllowedError do
23
+ Net::HTTP.get(URI.parse('http://example.com/'))
24
+ end
25
+ end
26
+
27
+ def test_question_mark_method_returns_true_after_setting_allow_net_connect_to_true
28
+ FakeWeb.allow_net_connect = true
29
+ assert FakeWeb.allow_net_connect?
30
+ end
31
+
32
+ def test_question_mark_method_returns_false_after_setting_allow_net_connect_to_false
33
+ FakeWeb.allow_net_connect = false
34
+ assert !FakeWeb.allow_net_connect?
35
+ end
36
+
37
+ def test_allow_net_connect_is_true_by_default
38
+ assert FakeWeb.allow_net_connect?
39
+ end
40
+
41
+ end
@@ -0,0 +1,443 @@
1
+ require File.join(File.dirname(__FILE__), "test_helper")
2
+
3
+ class TestFakeWeb < Test::Unit::TestCase
4
+
5
+ def setup
6
+ FakeWeb.allow_net_connect = true
7
+ FakeWeb.clean_registry
8
+ end
9
+
10
+ def test_register_uri
11
+ FakeWeb.register_uri('http://mock/test_example.txt', :string => "example")
12
+ assert FakeWeb.registered_uri?('http://mock/test_example.txt')
13
+ end
14
+
15
+ def test_register_uri_with_wrong_number_of_arguments
16
+ assert_raises ArgumentError do
17
+ FakeWeb.register_uri("http://example.com")
18
+ end
19
+ assert_raises ArgumentError do
20
+ FakeWeb.register_uri(:get, "http://example.com", "/example", :string => "example")
21
+ end
22
+ end
23
+
24
+ def test_registered_uri_with_wrong_number_of_arguments
25
+ assert_raises ArgumentError do
26
+ FakeWeb.registered_uri?
27
+ end
28
+ assert_raises ArgumentError do
29
+ FakeWeb.registered_uri?(:get, "http://example.com", "/example")
30
+ end
31
+ end
32
+
33
+ def test_response_for_with_wrong_number_of_arguments
34
+ assert_raises ArgumentError do
35
+ FakeWeb.response_for
36
+ end
37
+ assert_raises ArgumentError do
38
+ FakeWeb.response_for(:get, :some_client_lib, "http://example.com", "/example")
39
+ end
40
+ end
41
+
42
+ def test_register_uri_without_domain_name
43
+ assert_raises URI::InvalidURIError do
44
+ FakeWeb.register_uri('test_example2.txt', File.dirname(__FILE__) + '/fixtures/test_example.txt')
45
+ end
46
+ end
47
+
48
+ def test_register_uri_with_port_and_check_with_port
49
+ FakeWeb.register_uri('http://example.com:3000/', :string => 'foo')
50
+ assert FakeWeb.registered_uri?('http://example.com:3000/')
51
+ end
52
+
53
+ def test_register_uri_with_port_and_check_without_port
54
+ FakeWeb.register_uri('http://example.com:3000/', :string => 'foo')
55
+ assert !FakeWeb.registered_uri?('http://example.com/')
56
+ end
57
+
58
+ def test_register_uri_with_default_port_for_http_and_check_without_port
59
+ FakeWeb.register_uri('http://example.com:80/', :string => 'foo')
60
+ assert FakeWeb.registered_uri?('http://example.com/')
61
+ end
62
+
63
+ def test_register_uri_with_default_port_for_https_and_check_without_port
64
+ FakeWeb.register_uri('https://example.com:443/', :string => 'foo')
65
+ assert FakeWeb.registered_uri?('https://example.com/')
66
+ end
67
+
68
+ def test_register_uri_with_no_port_for_http_and_check_with_default_port
69
+ FakeWeb.register_uri('http://example.com/', :string => 'foo')
70
+ assert FakeWeb.registered_uri?('http://example.com:80/')
71
+ end
72
+
73
+ def test_register_uri_with_no_port_for_https_and_check_with_default_port
74
+ FakeWeb.register_uri('https://example.com/', :string => 'foo')
75
+ assert FakeWeb.registered_uri?('https://example.com:443/')
76
+ end
77
+
78
+ def test_register_uri_for_any_method_explicitly
79
+ FakeWeb.register_uri(:any, "http://example.com/rpc_endpoint", :string => "OK")
80
+ assert FakeWeb.registered_uri?(:get, "http://example.com/rpc_endpoint")
81
+ assert FakeWeb.registered_uri?(:post, "http://example.com/rpc_endpoint")
82
+ assert FakeWeb.registered_uri?(:put, "http://example.com/rpc_endpoint")
83
+ assert FakeWeb.registered_uri?(:delete, "http://example.com/rpc_endpoint")
84
+ assert FakeWeb.registered_uri?(:any, "http://example.com/rpc_endpoint")
85
+ assert FakeWeb.registered_uri?("http://example.com/rpc_endpoint")
86
+ end
87
+
88
+ def test_register_uri_for_get_method_only
89
+ FakeWeb.register_uri(:get, "http://example.com/users", :string => "User list")
90
+ assert FakeWeb.registered_uri?(:get, "http://example.com/users")
91
+ assert !FakeWeb.registered_uri?(:post, "http://example.com/users")
92
+ assert !FakeWeb.registered_uri?(:put, "http://example.com/users")
93
+ assert !FakeWeb.registered_uri?(:delete, "http://example.com/users")
94
+ assert !FakeWeb.registered_uri?(:any, "http://example.com/users")
95
+ assert !FakeWeb.registered_uri?("http://example.com/users")
96
+ end
97
+
98
+ def test_response_for_with_registered_uri
99
+ FakeWeb.register_uri('http://mock/test_example.txt', :file => File.dirname(__FILE__) + '/fixtures/test_example.txt')
100
+ FakeWeb::CLIENT_LIBRARIES.each { |library_identifier|
101
+ assert_equal 'test example content', FakeWeb.response_for(library_identifier, 'http://mock/test_example.txt').get_content
102
+ }
103
+ end
104
+
105
+ def test_response_for_with_unknown_uri
106
+ assert_equal nil, FakeWeb.response_for(:get, 'http://example.com/')
107
+ end
108
+
109
+ def test_response_for_with_put_method
110
+ FakeWeb.register_uri(:put, "http://example.com", :string => "response")
111
+ FakeWeb::CLIENT_LIBRARIES.each { |library_identifier|
112
+ assert_equal 'response', FakeWeb.response_for(:put, library_identifier, "http://example.com").get_content
113
+ }
114
+ end
115
+
116
+ def test_response_for_with_any_method_explicitly
117
+ FakeWeb.register_uri(:any, "http://example.com", :string => "response")
118
+ FakeWeb::CLIENT_LIBRARIES.each { |library_identifier|
119
+ assert_equal 'response', FakeWeb.response_for(:get, library_identifier, "http://example.com").get_content
120
+ assert_equal 'response', FakeWeb.response_for(:any, library_identifier, "http://example.com").get_content
121
+ }
122
+ end
123
+
124
+ def test_content_for_registered_uri_with_port_and_request_with_port
125
+ FakeWeb.register_uri('http://example.com:3000/', :string => 'test example content')
126
+ Net::HTTP.start('example.com', 3000) do |http|
127
+ response = http.get('/')
128
+ assert_equal 'test example content', response.body
129
+ end
130
+ end
131
+
132
+ def test_content_for_registered_uri_with_default_port_for_http_and_request_without_port
133
+ FakeWeb.register_uri('http://example.com:80/', :string => 'test example content')
134
+ Net::HTTP.start('example.com') do |http|
135
+ response = http.get('/')
136
+ assert_equal 'test example content', response.body
137
+ end
138
+ end
139
+
140
+ def test_content_for_registered_uri_with_no_port_for_http_and_request_with_default_port
141
+ FakeWeb.register_uri('http://example.com/', :string => 'test example content')
142
+ Net::HTTP.start('example.com', 80) do |http|
143
+ response = http.get('/')
144
+ assert_equal 'test example content', response.body
145
+ end
146
+ end
147
+
148
+ def test_content_for_registered_uri_with_default_port_for_https_and_request_with_default_port
149
+ FakeWeb.register_uri('https://example.com:443/', :string => 'test example content')
150
+ http = Net::HTTP.new('example.com', 443)
151
+ http.use_ssl = true
152
+ response = http.get('/')
153
+ assert_equal 'test example content', response.body
154
+ end
155
+
156
+ def test_content_for_registered_uri_with_no_port_for_https_and_request_with_default_port
157
+ FakeWeb.register_uri('https://example.com/', :string => 'test example content')
158
+ http = Net::HTTP.new('example.com', 443)
159
+ http.use_ssl = true
160
+ response = http.get('/')
161
+ assert_equal 'test example content', response.body
162
+ end
163
+
164
+ def test_content_for_registered_uris_with_ports_on_same_domain_and_request_without_port
165
+ FakeWeb.register_uri('http://example.com:3000/', :string => 'port 3000')
166
+ FakeWeb.register_uri('http://example.com/', :string => 'port 80')
167
+ Net::HTTP.start('example.com') do |http|
168
+ response = http.get('/')
169
+ assert_equal 'port 80', response.body
170
+ end
171
+ end
172
+
173
+ def test_content_for_registered_uris_with_ports_on_same_domain_and_request_with_port
174
+ FakeWeb.register_uri('http://example.com:3000/', :string => 'port 3000')
175
+ FakeWeb.register_uri('http://example.com/', :string => 'port 80')
176
+ Net::HTTP.start('example.com', 3000) do |http|
177
+ response = http.get('/')
178
+ assert_equal 'port 3000', response.body
179
+ end
180
+ end
181
+
182
+ def test_content_for_registered_uri_with_get_method_only
183
+ FakeWeb.allow_net_connect = false
184
+ FakeWeb.register_uri(:get, "http://example.com/", :string => "test example content")
185
+ Net::HTTP.start('example.com') do |http|
186
+ assert_equal 'test example content', http.get('/').body
187
+ assert_raises(FakeWeb::NetConnectNotAllowedError) { http.post('/', nil) }
188
+ assert_raises(FakeWeb::NetConnectNotAllowedError) { http.put('/', nil) }
189
+ assert_raises(FakeWeb::NetConnectNotAllowedError) { http.delete('/', nil) }
190
+ end
191
+ end
192
+
193
+ def test_content_for_registered_uri_with_any_method_explicitly
194
+ FakeWeb.allow_net_connect = false
195
+ FakeWeb.register_uri(:any, "http://example.com/", :string => "test example content")
196
+ Net::HTTP.start('example.com') do |http|
197
+ assert_equal 'test example content', http.get('/').body
198
+ assert_equal 'test example content', http.post('/', nil).body
199
+ assert_equal 'test example content', http.put('/', nil).body
200
+ assert_equal 'test example content', http.delete('/').body
201
+ end
202
+ end
203
+
204
+ def test_content_for_registered_uri_with_any_method_implicitly
205
+ FakeWeb.allow_net_connect = false
206
+ FakeWeb.register_uri("http://example.com/", :string => "test example content")
207
+ Net::HTTP.start('example.com') do |http|
208
+ assert_equal 'test example content', http.get('/').body
209
+ assert_equal 'test example content', http.post('/', nil).body
210
+ assert_equal 'test example content', http.put('/', nil).body
211
+ assert_equal 'test example content', http.delete('/').body
212
+ end
213
+ end
214
+
215
+ def test_mock_request_with_block
216
+ FakeWeb.register_uri('http://mock/test_example.txt', :file => File.dirname(__FILE__) + '/fixtures/test_example.txt')
217
+ Net::HTTP.start('mock') do |http|
218
+ response = http.get('/test_example.txt')
219
+ assert_equal 'test example content', response.body
220
+ end
221
+ end
222
+
223
+ def test_mock_request_with_undocumented_full_uri_argument_style
224
+ FakeWeb.register_uri('http://mock/test_example.txt', :file => File.dirname(__FILE__) + '/fixtures/test_example.txt')
225
+ Net::HTTP.start('mock') do |query|
226
+ response = query.get('http://mock/test_example.txt')
227
+ assert_equal 'test example content', response.body
228
+ end
229
+ end
230
+
231
+ def test_mock_request_with_undocumented_full_uri_argument_style_and_query
232
+ FakeWeb.register_uri('http://mock/test_example.txt?a=b', :string => 'test query content')
233
+ Net::HTTP.start('mock') do |query|
234
+ response = query.get('http://mock/test_example.txt?a=b')
235
+ assert_equal 'test query content', response.body
236
+ end
237
+ end
238
+
239
+ def test_mock_post
240
+ FakeWeb.register_uri('http://mock/test_example.txt', :file => File.dirname(__FILE__) + '/fixtures/test_example.txt')
241
+ response = nil
242
+ Net::HTTP.start('mock') do |query|
243
+ response = query.post('/test_example.txt', '')
244
+ end
245
+ assert_equal 'test example content', response.body
246
+ end
247
+
248
+ def test_mock_post_with_string_as_registered_uri
249
+ response = nil
250
+ FakeWeb.register_uri('http://mock/test_string.txt', :string => 'foo')
251
+ Net::HTTP.start('mock') do |query|
252
+ response = query.post('/test_string.txt', '')
253
+ end
254
+ assert_equal 'foo', response.body
255
+ end
256
+
257
+ def test_mock_get_with_request_as_registered_uri
258
+ fake_response = Net::HTTPOK.new('1.1', '200', 'OK')
259
+ FakeWeb.register_uri('http://mock/test_response', :response => fake_response)
260
+ response = nil
261
+ Net::HTTP.start('mock') do |query|
262
+ response = query.get('/test_response')
263
+ end
264
+
265
+ assert_equal fake_response, response
266
+ end
267
+
268
+ def test_mock_get_with_request_from_file_as_registered_uri
269
+ FakeWeb.register_uri('http://www.google.com/', :response => File.dirname(__FILE__) + '/fixtures/test_request')
270
+ response = nil
271
+ Net::HTTP.start('www.google.com') do |query|
272
+ response = query.get('/')
273
+ end
274
+ assert_equal '200', response.code
275
+ assert response.body.include?('<title>Google</title>')
276
+ end
277
+
278
+ def test_mock_post_with_request_from_file_as_registered_uri
279
+ FakeWeb.register_uri('http://www.google.com/', :response => File.dirname(__FILE__) + '/fixtures/test_request')
280
+ response = nil
281
+ Net::HTTP.start('www.google.com') do |query|
282
+ response = query.post('/', '')
283
+ end
284
+ assert_equal "200", response.code
285
+ assert response.body.include?('<title>Google</title>')
286
+ end
287
+
288
+ def test_proxy_request
289
+ FakeWeb.register_uri('http://www.example.com/', :string => "hello world")
290
+ FakeWeb.register_uri('http://your.proxy.host/', :string => "lala")
291
+ proxy_addr = 'your.proxy.host'
292
+ proxy_port = 8080
293
+
294
+ Net::HTTP::Proxy(proxy_addr, proxy_port).start('www.example.com') do |http|
295
+ response = http.get('/')
296
+ assert_equal "hello world", response.body
297
+ end
298
+ end
299
+
300
+ def test_https_request
301
+ FakeWeb.register_uri('https://www.example.com/', :string => "Hello World")
302
+ http = Net::HTTP.new('www.example.com', 443)
303
+ http.use_ssl = true
304
+ response = http.get('/')
305
+ assert_equal "Hello World", response.body
306
+ end
307
+
308
+ def test_register_unimplemented_response
309
+ FakeWeb.register_uri('http://mock/unimplemented', :response => 1)
310
+ assert_raises StandardError do
311
+ Net::HTTP.start('mock') { |q| q.get('/unimplemented') }
312
+ end
313
+ end
314
+
315
+ def test_real_http_request
316
+ setup_expectations_for_real_apple_hot_news_request
317
+
318
+ resp = nil
319
+ Net::HTTP.start('images.apple.com') do |query|
320
+ resp = query.get('/main/rss/hotnews/hotnews.rss')
321
+ end
322
+ assert resp.body.include?('Apple')
323
+ assert resp.body.include?('News')
324
+ end
325
+
326
+ def test_real_http_request_with_undocumented_full_uri_argument_style
327
+ setup_expectations_for_real_apple_hot_news_request(:path => 'http://images.apple.com/main/rss/hotnews/hotnews.rss')
328
+
329
+ resp = nil
330
+ Net::HTTP.start('images.apple.com') do |query|
331
+ resp = query.get('http://images.apple.com/main/rss/hotnews/hotnews.rss')
332
+ end
333
+ assert resp.body.include?('Apple')
334
+ assert resp.body.include?('News')
335
+ end
336
+
337
+ def test_real_https_request
338
+ setup_expectations_for_real_apple_hot_news_request(:port => 443)
339
+
340
+ http = Net::HTTP.new('images.apple.com', 443)
341
+ http.use_ssl = true
342
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE # silence certificate warning
343
+ response = http.get('/main/rss/hotnews/hotnews.rss')
344
+ assert response.body.include?('Apple')
345
+ assert response.body.include?('News')
346
+ end
347
+
348
+ def test_real_request_on_same_domain_as_mock
349
+ setup_expectations_for_real_apple_hot_news_request
350
+
351
+ FakeWeb.register_uri('http://images.apple.com/test_string.txt', :string => 'foo')
352
+
353
+ resp = nil
354
+ Net::HTTP.start('images.apple.com') do |query|
355
+ resp = query.get('/main/rss/hotnews/hotnews.rss')
356
+ end
357
+ assert resp.body.include?('Apple')
358
+ assert resp.body.include?('News')
359
+ end
360
+
361
+ def test_mock_request_on_real_domain
362
+ FakeWeb.register_uri('http://images.apple.com/test_string.txt', :string => 'foo')
363
+ resp = nil
364
+ Net::HTTP.start('images.apple.com') do |query|
365
+ resp = query.get('/test_string.txt')
366
+ end
367
+ assert_equal 'foo', resp.body
368
+ end
369
+
370
+ def test_mock_post_that_raises_exception
371
+ FakeWeb.register_uri('http://mock/raising_exception.txt', :exception => StandardError)
372
+ assert_raises(StandardError) do
373
+ Net::HTTP.start('mock') do |query|
374
+ query.post('/raising_exception.txt', 'some data')
375
+ end
376
+ end
377
+ end
378
+
379
+ def test_mock_post_that_raises_an_http_error
380
+ FakeWeb.register_uri('http://mock/raising_exception.txt', :exception => Net::HTTPError)
381
+ assert_raises(Net::HTTPError) do
382
+ Net::HTTP.start('mock') do |query|
383
+ query.post('/raising_exception.txt', '')
384
+ end
385
+ end
386
+ end
387
+
388
+ def test_mock_instance_syntax
389
+ FakeWeb.register_uri('http://mock/test_example.txt', :file => File.dirname(__FILE__) + '/fixtures/test_example.txt')
390
+ response = nil
391
+ uri = URI.parse('http://mock/test_example.txt')
392
+ http = Net::HTTP.new(uri.host, uri.port)
393
+ response = http.start do
394
+ http.get(uri.path)
395
+ end
396
+
397
+ assert_equal 'test example content', response.body
398
+ end
399
+
400
+ def test_mock_via_nil_proxy
401
+ response = nil
402
+ proxy_address = nil
403
+ proxy_port = nil
404
+ FakeWeb.register_uri('http://mock/test_example.txt', :file => File.dirname(__FILE__) + '/fixtures/test_example.txt')
405
+ uri = URI.parse('http://mock/test_example.txt')
406
+ http = Net::HTTP::Proxy(proxy_address, proxy_port).new(
407
+ uri.host, (uri.port or 80))
408
+ response = http.start do
409
+ http.get(uri.path)
410
+ end
411
+
412
+ assert_equal 'test example content', response.body
413
+ end
414
+
415
+ def test_response_type
416
+ FakeWeb.register_uri('http://mock/test_example.txt', :string => "test")
417
+ Net::HTTP.start('mock') do |http|
418
+ response = http.get('/test_example.txt', '')
419
+ assert_kind_of(Net::HTTPSuccess, response)
420
+ end
421
+ end
422
+
423
+ def test_mock_request_that_raises_an_http_error_with_a_specific_status
424
+ FakeWeb.register_uri('http://mock/raising_exception.txt', :exception => Net::HTTPError, :status => ['404', 'Not Found'])
425
+ exception = assert_raises(Net::HTTPError) do
426
+ Net::HTTP.start('mock') { |http| response = http.get('/raising_exception.txt') }
427
+ end
428
+ assert_equal '404', exception.response.code
429
+ assert_equal 'Not Found', exception.response.msg
430
+ end
431
+
432
+ def test_mock_rotate_responses
433
+ FakeWeb.register_uri('http://mock/multiple_test_example.txt',
434
+ [ {:file => File.dirname(__FILE__) + '/fixtures/test_example.txt', :times => 2},
435
+ {:string => "thrice", :times => 3},
436
+ {:string => "ever_more"} ])
437
+
438
+ uri = URI.parse('http://mock/multiple_test_example.txt')
439
+ 2.times { assert_equal 'test example content', Net::HTTP.get(uri) }
440
+ 3.times { assert_equal 'thrice', Net::HTTP.get(uri) }
441
+ 4.times { assert_equal 'ever_more', Net::HTTP.get(uri) }
442
+ end
443
+ end