chrisk-fakeweb 1.1.2.3 → 1.1.2.4

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,6 +1,8 @@
1
1
  fakeweb (development)
2
2
 
3
3
  [ Chris Kampmeier ]
4
+ * add support for Net::HTTP's undocumented full-URI request style (fixes
5
+ URI::InvalidURIErrors that you might see in older libraries)
4
6
  * sort query params before storing internally, so that
5
7
  http://example.com/?a=1&b=2 and http://example.com/?b=2&a=1 are considered
6
8
  the same URL (although this is technically incorrect, it's much more
@@ -1,10 +1,53 @@
1
- = Name
1
+ = FakeWeb
2
2
 
3
- FakeWeb - Helper for Faking Web Requests
3
+ A Helper for Faking Web Requests
4
4
 
5
- = Synopsis
5
+ = Examples
6
+
7
+ require 'test/unit'
8
+ require 'fake_web'
9
+ require 'open-uri'
10
+
11
+ class FakeWebExampleTest < Test::Unit::TestCase
12
+ def test_request
13
+ FakeWeb.register_uri('http://example.com/test_me', :string => "Hello World!")
14
+ content = Net::HTTP.get(URI.parse('http://example.com/test_me'))
15
+ assert_equal "Hello World!", content
16
+ end
17
+
18
+ def test_request_with_response
19
+ FakeWeb.register_uri('http://www.google.com/', :response => `curl -is http://www.google.com/`)
20
+ Net::HTTP.start('www.google.com') do |req|
21
+ response = req.get('/')
22
+ if response.code == 200
23
+ assert_equal "OK", response.message
24
+ assert response.body.include?('<title>Google')
25
+ elsif response.code == 302
26
+ # Google redirects foreign sites to ccTLDs.
27
+ assert_equal "Found", response.message
28
+ assert response.body.include?('The document has moved')
29
+ end
30
+ end
31
+ end
32
+
33
+ def test_request_with_custom_status
34
+ FakeWeb.register_uri('http://example.com/', :string => "Nothing to be found 'round here",
35
+ :status => ['404', 'Not Found'])
36
+ Net::HTTP.start('example.com') do |req|
37
+ response = req.get('/')
38
+ assert_equal "404", response.code
39
+ assert_equal "Not Found", response.message
40
+ assert_equal "Nothing to be found 'round here", response.body
41
+ end
42
+ end
43
+
44
+ def test_open_uri
45
+ FakeWeb.register_uri('http://example.com/', :string => "Hello, World!")
46
+ content = open('http://example.com/').string
47
+ assert_equal "Hello, World!", content
48
+ end
49
+ end
6
50
 
7
- :include:test/test_examples.rb
8
51
 
9
52
  = Description
10
53
 
data/Rakefile CHANGED
@@ -25,7 +25,7 @@ spec = Gem::Specification.new do |s|
25
25
  s.add_dependency('rake')
26
26
  s.add_dependency('rcov')
27
27
  s.name = "FakeWeb"
28
- s.version = "1.1.2.3"
28
+ s.version = "1.1.2.4"
29
29
  s.author = "Blaine Cook"
30
30
  s.email = "romeda@gmail.com"
31
31
  s.homepage = "http://fakeweb.rubyforge.org/"
@@ -35,7 +35,7 @@ spec = Gem::Specification.new do |s|
35
35
  s.require_path = "lib"
36
36
  s.test_files = Dir.glob("test/test_*.rb")
37
37
  s.has_rdoc = true
38
- s.extra_rdoc_files = ["README", "COPYING"]
38
+ s.extra_rdoc_files = ["README.rdoc", "COPYING"]
39
39
  s.rubyforge_project = "fakeweb"
40
40
  end
41
41
 
@@ -56,9 +56,9 @@ end
56
56
 
57
57
  desc "Generate Documentation"
58
58
  Rake::RDocTask.new do |rdoc|
59
- rdoc.main = "README"
59
+ rdoc.main = "README.rdoc"
60
60
  rdoc.rdoc_dir = "doc"
61
- rdoc.rdoc_files.include("README", "COPYING", "lib/*.rb")
61
+ rdoc.rdoc_files.include("README.rdoc", "COPYING", "lib/*.rb")
62
62
  rdoc.title = "FakeWeb"
63
63
  end
64
64
 
@@ -1,16 +1,16 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "fakeweb"
3
- s.version = "1.1.2.3"
4
- s.date = "2008-10-23"
3
+ s.version = "1.1.2.4"
4
+ s.date = "2008-10-29"
5
5
  s.summary = "A test helper that makes it simple to test HTTP interaction"
6
6
  s.homepage = "http://github.com/chrisk/fakeweb"
7
7
  s.has_rdoc = true
8
8
  s.authors = ["Blaine Cook"]
9
- s.files = ["CHANGELOG", "COPYING", "fakeweb.gemspec", "Rakefile", "README",
9
+ s.files = ["CHANGELOG", "COPYING", "fakeweb.gemspec", "Rakefile", "README.rdoc",
10
10
  "setup.rb", "lib/fake_net_http.rb", "lib/fake_web.rb"]
11
11
  s.test_files = ["test/fixtures/test_example.txt", "test/fixtures/test_request",
12
12
  "test/test_examples.rb", "test/test_fake_web.rb",
13
13
  "test/test_fake_web_open_uri.rb"]
14
- s.rdoc_options = ["--main", "README"]
15
- s.extra_rdoc_files = ["CHANGELOG", "COPYING", "README"]
14
+ s.rdoc_options = ["--main", "README.rdoc"]
15
+ s.extra_rdoc_files = ["CHANGELOG", "COPYING", "README.rdoc"]
16
16
  end
@@ -53,7 +53,12 @@ module Net #:nodoc:
53
53
 
54
54
  def request(req, body = nil, &block)
55
55
  prot = use_ssl ? "https" : "http"
56
- uri = "#{prot}://#{self.address}:#{self.port}#{req.path}"
56
+
57
+ path = req.path
58
+ path = URI.parse(req.path).request_uri if req.path =~ /^http/
59
+
60
+ uri = "#{prot}://#{self.address}:#{self.port}#{path}"
61
+
57
62
  if FakeWeb.registered_uri?(uri)
58
63
  @socket = Net::HTTP.socket_type.new
59
64
  return FakeWeb.response_for(uri, &block)
@@ -146,7 +146,22 @@ class TestFakeWeb < Test::Unit::TestCase
146
146
  assert_equal 'test example content', response.body
147
147
  end
148
148
  end
149
-
149
+
150
+ def test_mock_request_with_undocumented_full_uri_argument_style
151
+ Net::HTTP.start('mock') do |query|
152
+ response = query.get('http://mock/test_example.txt')
153
+ assert_equal 'test example content', response.body
154
+ end
155
+ end
156
+
157
+ def test_mock_request_with_undocumented_full_uri_argument_style_and_query
158
+ FakeWeb.register_uri('http://mock/test_example.txt?a=b', :string => 'test query content')
159
+ Net::HTTP.start('mock') do |query|
160
+ response = query.get('http://mock/test_example.txt?a=b')
161
+ assert_equal 'test query content', response.body
162
+ end
163
+ end
164
+
150
165
  def test_mock_post
151
166
  response = nil
152
167
  Net::HTTP.start('mock') do |query|
@@ -231,6 +246,15 @@ class TestFakeWeb < Test::Unit::TestCase
231
246
  assert resp.body.include?('News')
232
247
  end
233
248
 
249
+ def test_real_http_request_with_undocumented_full_uri_argument_style
250
+ resp = nil
251
+ Net::HTTP.start('images.apple.com') do |query|
252
+ resp = query.get('http://images.apple.com/main/rss/hotnews/hotnews.rss')
253
+ end
254
+ assert resp.body.include?('Apple')
255
+ assert resp.body.include?('News')
256
+ end
257
+
234
258
  def test_real_https_request
235
259
  http = Net::HTTP.new('images.apple.com', 443)
236
260
  http.use_ssl = true
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chrisk-fakeweb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2.3
4
+ version: 1.1.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Blaine Cook
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-10-23 00:00:00 -07:00
12
+ date: 2008-10-29 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -22,13 +22,13 @@ extensions: []
22
22
  extra_rdoc_files:
23
23
  - CHANGELOG
24
24
  - COPYING
25
- - README
25
+ - README.rdoc
26
26
  files:
27
27
  - CHANGELOG
28
28
  - COPYING
29
29
  - fakeweb.gemspec
30
30
  - Rakefile
31
- - README
31
+ - README.rdoc
32
32
  - setup.rb
33
33
  - lib/fake_net_http.rb
34
34
  - lib/fake_web.rb
@@ -37,7 +37,7 @@ homepage: http://github.com/chrisk/fakeweb
37
37
  post_install_message:
38
38
  rdoc_options:
39
39
  - --main
40
- - README
40
+ - README.rdoc
41
41
  require_paths:
42
42
  - lib
43
43
  required_ruby_version: !ruby/object:Gem::Requirement