fakeweb 1.2.2 → 1.2.3

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/CHANGELOG CHANGED
@@ -1,3 +1,18 @@
1
+ fakeweb (1.2.3)
2
+
3
+ * fix the #http_version of :file and :string responses, which was returning the
4
+ request URI instead of something sensible like "1.0" [Chris Kampmeier]
5
+
6
+ * add method aliases in the Net::HTTP patch to eliminate warnings when running
7
+ with -w [Joshua Clingenpeel]
8
+
9
+ * fix that removing the redefinition of OpenURI::HTTPError in 1.2.0 caused
10
+ :exception responses to raise when OpenURI isn't available [Chris Kampmeier]
11
+
12
+ * fix registering an :exception response with classes that require arguments for
13
+ instantiation, like Interrupt's subclasses [Chris Kampmeier]
14
+
15
+
1
16
  fakeweb (1.2.2)
2
17
 
3
18
  * fix that HTTP Digest and OAuth requests could raise URI::InvalidURIErrors
data/Rakefile CHANGED
@@ -38,7 +38,7 @@ task :manifest do
38
38
 
39
39
  if spec_file
40
40
  spec = File.read spec_file
41
- spec.gsub! /^(\s* s.(test_)?files \s* = \s* )( \[ [^\]]* \] | %w\( [^)]* \) )/mx do
41
+ spec.gsub!(/^(\s* s.(test_)?files \s* = \s* )( \[ [^\]]* \] | %w\( [^)]* \) )/mx) do
42
42
  assignment = $1
43
43
  bunch = $2 ? list.grep(/^test\//) : list
44
44
  '%s%%w(%s)' % [assignment, bunch.join(' ')]
@@ -5,6 +5,7 @@ require 'stringio'
5
5
  module Net #:nodoc: all
6
6
 
7
7
  class BufferedIO
8
+ alias initialize_without_fakeweb initialize
8
9
  def initialize(io, debug_output = nil)
9
10
  @read_timeout = 60
10
11
  @rbuf = ''
@@ -25,13 +26,14 @@ module Net #:nodoc: all
25
26
  end
26
27
 
27
28
  class HTTP
28
- def self.socket_type
29
- FakeWeb::StubSocket
29
+ class << self
30
+ alias socket_type_without_fakeweb socket_type
31
+ def socket_type
32
+ FakeWeb::StubSocket
33
+ end
30
34
  end
31
35
 
32
- alias :original_net_http_request :request
33
- alias :original_net_http_connect :connect
34
-
36
+ alias request_without_fakeweb request
35
37
  def request(request, body = nil, &block)
36
38
  protocol = use_ssl? ? "https" : "http"
37
39
 
@@ -51,14 +53,15 @@ module Net #:nodoc: all
51
53
  @socket = Net::HTTP.socket_type.new
52
54
  FakeWeb.response_for(method, uri, &block)
53
55
  elsif FakeWeb.allow_net_connect?
54
- original_net_http_connect
55
- original_net_http_request(request, body, &block)
56
+ connect_without_fakeweb
57
+ request_without_fakeweb(request, body, &block)
56
58
  else
57
59
  raise FakeWeb::NetConnectNotAllowedError,
58
60
  "Real HTTP connections are disabled. Unregistered request: #{request.method} #{uri}"
59
61
  end
60
62
  end
61
63
 
64
+ alias connect_without_fakeweb connect
62
65
  def connect
63
66
  end
64
67
  end
@@ -15,7 +15,7 @@ module FakeWeb
15
15
  response = baked_response
16
16
  else
17
17
  code, msg = meta_information
18
- response = Net::HTTPResponse.send(:response_class, code.to_s).new(uri, code.to_s, msg)
18
+ response = Net::HTTPResponse.send(:response_class, code.to_s).new("1.0", code.to_s, msg)
19
19
  response.instance_variable_set(:@body, content)
20
20
  end
21
21
 
@@ -82,13 +82,13 @@ module FakeWeb
82
82
 
83
83
  def optionally_raise(response)
84
84
  return unless options.has_key?(:exception)
85
- ex_alloc = options[:exception].allocate
86
- ex_instance = case ex_alloc
87
- when Net::HTTPError, OpenURI::HTTPError
88
- options[:exception].new('Exception from FakeWeb', response)
89
- else options[:exception].new
85
+
86
+ case options[:exception].to_s
87
+ when "Net::HTTPError", "OpenURI::HTTPError"
88
+ raise options[:exception].new('Exception from FakeWeb', response)
89
+ else
90
+ raise options[:exception].new('Exception from FakeWeb')
90
91
  end
91
- raise ex_instance
92
92
  end
93
93
 
94
94
  def meta_information
@@ -389,6 +389,13 @@ class TestFakeWeb < Test::Unit::TestCase
389
389
  end
390
390
  end
391
391
 
392
+ def test_raising_an_exception_that_requires_an_argument_to_instantiate
393
+ FakeWeb.register_uri(:get, "http://example.com/timeout.txt", :exception => Timeout::Error)
394
+ assert_raises(Timeout::Error) do
395
+ Net::HTTP.get(URI.parse("http://example.com/timeout.txt"))
396
+ end
397
+ end
398
+
392
399
  def test_mock_instance_syntax
393
400
  FakeWeb.register_uri('http://mock/test_example.txt', :file => File.dirname(__FILE__) + '/fixtures/test_example.txt')
394
401
  response = nil
@@ -497,4 +504,16 @@ class TestFakeWeb < Test::Unit::TestCase
497
504
  Net::HTTP.get(URI.parse("http://example.com"))
498
505
  end
499
506
  end
507
+
508
+ def test_http_version_from_string_response
509
+ FakeWeb.register_uri(:get, "http://example.com", :string => "example")
510
+ response = Net::HTTP.start("example.com") { |http| http.get("/") }
511
+ assert_equal "1.0", response.http_version
512
+ end
513
+
514
+ def test_http_version_from_file_response
515
+ FakeWeb.register_uri(:get, "http://example.com", :file => File.dirname(__FILE__) + '/fixtures/test_example.txt')
516
+ response = Net::HTTP.start("example.com") { |http| http.get("/") }
517
+ assert_equal "1.0", response.http_version
518
+ end
500
519
  end
@@ -0,0 +1,24 @@
1
+ require File.join(File.dirname(__FILE__), "test_helper")
2
+
3
+ class TestMissingOpenURI < Test::Unit::TestCase
4
+
5
+ def setup
6
+ FakeWeb.clean_registry
7
+ @saved_open_uri = OpenURI
8
+ Object.send(:remove_const, :OpenURI)
9
+ end
10
+
11
+ def teardown
12
+ Object.const_set(:OpenURI, @saved_open_uri)
13
+ end
14
+
15
+
16
+ def test_register_using_exception_without_open_uri
17
+ # regression test for Responder needing OpenURI::HTTPError to be defined
18
+ FakeWeb.register_uri(:get, "http://example.com/", :exception => StandardError)
19
+ assert_raises(StandardError) do
20
+ Net::HTTP.start("example.com") { |http| http.get("/") }
21
+ end
22
+ end
23
+
24
+ end
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fakeweb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.2
4
+ version: 1.2.3
5
5
  platform: ruby
6
6
  authors:
7
- - Blaine Cook
8
7
  - Chris Kampmeier
8
+ - Blaine Cook
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2009-05-04 00:00:00 -07:00
13
+ date: 2009-05-31 00:00:00 -07:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -23,8 +23,10 @@ dependencies:
23
23
  - !ruby/object:Gem::Version
24
24
  version: 0.9.5
25
25
  version:
26
- description:
27
- email: chris@kampers.net
26
+ description: FakeWeb is a helper for faking web requests in Ruby. It works at a global level, without modifying code or writing extensive stubs.
27
+ email:
28
+ - chris@kampers.net
29
+ - romeda@gmail.com
28
30
  executables: []
29
31
 
30
32
  extensions: []
@@ -55,6 +57,7 @@ files:
55
57
  - test/test_fake_web.rb
56
58
  - test/test_fake_web_open_uri.rb
57
59
  - test/test_helper.rb
60
+ - test/test_missing_open_uri.rb
58
61
  - test/test_query_string.rb
59
62
  - test/test_trailing_slashes.rb
60
63
  has_rdoc: true
@@ -103,5 +106,6 @@ test_files:
103
106
  - test/test_fake_web.rb
104
107
  - test/test_fake_web_open_uri.rb
105
108
  - test/test_helper.rb
109
+ - test/test_missing_open_uri.rb
106
110
  - test/test_query_string.rb
107
111
  - test/test_trailing_slashes.rb