Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Update code for compatibility with ruby 1.8.4; this breaks compatibil…

…ity with ruby 1.8.2 - use fakeweb 1.0.0 if you are stuck on 1.8.2.
  • Loading branch information...
commit 9bdcca3b30e87b2343ccc0795f81086394b5a73e 1 parent 7a1a3d5
@blaine blaine authored
Showing with 20 additions and 46 deletions.
  1. +8 −0 CHANGELOG
  2. +11 −5 lib/fake_net_http.rb
  3. +1 −41 lib/fake_web.rb
View
8 CHANGELOG
@@ -1,3 +1,11 @@
+fakeweb (1.0.1)
+
+ [ Blaine Cook ]
+ * update code to correspond to ruby 1.8.4
+ * breaks compatibility with ruby 1.8.2
+
+-- Blaine Cook <romeda@gmail.com> Tue, 23 May 2006 16:13:26 -0800
+
fakeweb (1.0.0)
[ Blaine Cook ]
View
16 lib/fake_net_http.rb
@@ -17,19 +17,21 @@
require 'net/http'
require 'net/https'
+require 'rubygems'
+require 'breakpoint'
require 'stringio'
module Net #:nodoc:
- class LocalMessageIO < Net::InternetMessageIO #:nodoc:
+ class BufferedIO #:nodoc:
def initialize( io, debug_output = nil )
@debug_output = debug_output
- @socket = case io
+ @io = case io
when Socket, IO: io
when String
File.exists?(io) ? File.open(io, "r") : StringIO.new(io)
end
- raise "Unable to create local socket" unless @socket
+ raise "Unable to create local socket" unless @io
connect
end
@@ -38,7 +40,7 @@ def connect(*args)
end
def rbuf_fill
- @rbuf << @socket.sysread(1024)
+ @rbuf << @io.sysread(1024)
end
end
@@ -49,7 +51,7 @@ def HTTP.socket_type #:nodoc:
end
alias :original_net_http_request :request
- alias :original_net_http_do_start :do_start
+ alias :original_net_http_connect :connect
def request(req, body = nil, &block)
prot = use_ssl ? "https" : "http"
@@ -58,8 +60,12 @@ def request(req, body = nil, &block)
@socket = Net::HTTP.socket_type.new
return FakeWeb.response_for(uri, &block)
else
+ original_net_http_connect
return original_net_http_request(req, body, &block)
end
end
+
+ def connect
+ end
end
end
View
42 lib/fake_web.rb
@@ -83,11 +83,6 @@ def FakeWeb.response_for(uri, &block) #:nodoc: :yields: response
# Checks for presence of +uri+ in the +FakeWeb+ registry.
def FakeWeb.registered_uri?(uri); FakeWeb::Registry.instance.registered_uri?(uri); end
- def FakeWeb.registered_host?(*args) #:nodoc:
- FakeWeb::Registry.instance.registered_host?(*args)
- end
-
-
class Registry #:nodoc:
include Singleton
@@ -109,13 +104,6 @@ def registered_uri?(uri)
uri_map.has_key?(normalize_uri(uri))
end
- def registered_host?(host)
- uri_map.each_key do |uri|
- return true if uri.host == host
- end
- false
- end
-
def registered_uri(uri)
uri = normalize_uri(uri)
return uri_map[uri] if registered_uri?(uri)
@@ -194,7 +182,7 @@ def baked_response
resp = case options[:response]
when Net::HTTPResponse: options[:response]
when String
- socket = Net::LocalMessageIO.new(options[:response])
+ socket = Net::BufferedIO.new(options[:response])
r = Net::HTTPResponse.read_new(socket)
r.instance_eval { @header['transfer-encoding'] = nil }
r.reading_body(socket, true) {}
@@ -226,18 +214,6 @@ def meta_information
class SocketDelegator #:nodoc:
- def self.delegate_to
- Net::InternetMessageIO
- end
-
- def self.open(*args)
- if FakeWeb.registered_host?(args[0])
- new().open(*args)
- else
- delegate_to.open(*args)
- end
- end
-
def initialize(delegate=nil)
@delegate = nil
end
@@ -247,26 +223,10 @@ def method_missing(method, *args, &block)
return self.send("my_#{method}", *args, &block)
end
- def my_open(*args)
- @open_args = args
- @closed = false
- return self
- end
-
def my_closed?
@closed ||= true
end
- def my_reopen(*args)
- @reopen_args = args
- @close = false
- end
-
- def my_write(*args)
- @delegate = self.class.delegate_to.open(*@open_args)
- return @delegate.write(*args)
- end
-
def my_readuntil(*args)
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.