fakeweb 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +8 -0
- data/Rakefile +1 -1
- data/lib/fake_net_http.rb +11 -5
- data/lib/fake_web.rb +1 -41
- metadata +1 -1
data/CHANGELOG
CHANGED
data/Rakefile
CHANGED
data/lib/fake_net_http.rb
CHANGED
@@ -17,19 +17,21 @@
|
|
17
17
|
|
18
18
|
require 'net/http'
|
19
19
|
require 'net/https'
|
20
|
+
require 'rubygems'
|
21
|
+
require 'breakpoint'
|
20
22
|
require 'stringio'
|
21
23
|
|
22
24
|
module Net #:nodoc:
|
23
25
|
|
24
|
-
class
|
26
|
+
class BufferedIO #:nodoc:
|
25
27
|
def initialize( io, debug_output = nil )
|
26
28
|
@debug_output = debug_output
|
27
|
-
@
|
29
|
+
@io = case io
|
28
30
|
when Socket, IO: io
|
29
31
|
when String
|
30
32
|
File.exists?(io) ? File.open(io, "r") : StringIO.new(io)
|
31
33
|
end
|
32
|
-
raise "Unable to create local socket" unless @
|
34
|
+
raise "Unable to create local socket" unless @io
|
33
35
|
connect
|
34
36
|
end
|
35
37
|
|
@@ -38,7 +40,7 @@ module Net #:nodoc:
|
|
38
40
|
end
|
39
41
|
|
40
42
|
def rbuf_fill
|
41
|
-
@rbuf << @
|
43
|
+
@rbuf << @io.sysread(1024)
|
42
44
|
end
|
43
45
|
end
|
44
46
|
|
@@ -49,7 +51,7 @@ module Net #:nodoc:
|
|
49
51
|
end
|
50
52
|
|
51
53
|
alias :original_net_http_request :request
|
52
|
-
alias :
|
54
|
+
alias :original_net_http_connect :connect
|
53
55
|
|
54
56
|
def request(req, body = nil, &block)
|
55
57
|
prot = use_ssl ? "https" : "http"
|
@@ -58,8 +60,12 @@ module Net #:nodoc:
|
|
58
60
|
@socket = Net::HTTP.socket_type.new
|
59
61
|
return FakeWeb.response_for(uri, &block)
|
60
62
|
else
|
63
|
+
original_net_http_connect
|
61
64
|
return original_net_http_request(req, body, &block)
|
62
65
|
end
|
63
66
|
end
|
67
|
+
|
68
|
+
def connect
|
69
|
+
end
|
64
70
|
end
|
65
71
|
end
|
data/lib/fake_web.rb
CHANGED
@@ -83,11 +83,6 @@ module FakeWeb
|
|
83
83
|
# Checks for presence of +uri+ in the +FakeWeb+ registry.
|
84
84
|
def FakeWeb.registered_uri?(uri); FakeWeb::Registry.instance.registered_uri?(uri); end
|
85
85
|
|
86
|
-
def FakeWeb.registered_host?(*args) #:nodoc:
|
87
|
-
FakeWeb::Registry.instance.registered_host?(*args)
|
88
|
-
end
|
89
|
-
|
90
|
-
|
91
86
|
class Registry #:nodoc:
|
92
87
|
include Singleton
|
93
88
|
|
@@ -109,13 +104,6 @@ module FakeWeb
|
|
109
104
|
uri_map.has_key?(normalize_uri(uri))
|
110
105
|
end
|
111
106
|
|
112
|
-
def registered_host?(host)
|
113
|
-
uri_map.each_key do |uri|
|
114
|
-
return true if uri.host == host
|
115
|
-
end
|
116
|
-
false
|
117
|
-
end
|
118
|
-
|
119
107
|
def registered_uri(uri)
|
120
108
|
uri = normalize_uri(uri)
|
121
109
|
return uri_map[uri] if registered_uri?(uri)
|
@@ -194,7 +182,7 @@ module FakeWeb
|
|
194
182
|
resp = case options[:response]
|
195
183
|
when Net::HTTPResponse: options[:response]
|
196
184
|
when String
|
197
|
-
socket = Net::
|
185
|
+
socket = Net::BufferedIO.new(options[:response])
|
198
186
|
r = Net::HTTPResponse.read_new(socket)
|
199
187
|
r.instance_eval { @header['transfer-encoding'] = nil }
|
200
188
|
r.reading_body(socket, true) {}
|
@@ -226,18 +214,6 @@ module FakeWeb
|
|
226
214
|
|
227
215
|
class SocketDelegator #:nodoc:
|
228
216
|
|
229
|
-
def self.delegate_to
|
230
|
-
Net::InternetMessageIO
|
231
|
-
end
|
232
|
-
|
233
|
-
def self.open(*args)
|
234
|
-
if FakeWeb.registered_host?(args[0])
|
235
|
-
new().open(*args)
|
236
|
-
else
|
237
|
-
delegate_to.open(*args)
|
238
|
-
end
|
239
|
-
end
|
240
|
-
|
241
217
|
def initialize(delegate=nil)
|
242
218
|
@delegate = nil
|
243
219
|
end
|
@@ -247,26 +223,10 @@ module FakeWeb
|
|
247
223
|
return self.send("my_#{method}", *args, &block)
|
248
224
|
end
|
249
225
|
|
250
|
-
def my_open(*args)
|
251
|
-
@open_args = args
|
252
|
-
@closed = false
|
253
|
-
return self
|
254
|
-
end
|
255
|
-
|
256
226
|
def my_closed?
|
257
227
|
@closed ||= true
|
258
228
|
end
|
259
229
|
|
260
|
-
def my_reopen(*args)
|
261
|
-
@reopen_args = args
|
262
|
-
@close = false
|
263
|
-
end
|
264
|
-
|
265
|
-
def my_write(*args)
|
266
|
-
@delegate = self.class.delegate_to.open(*@open_args)
|
267
|
-
return @delegate.write(*args)
|
268
|
-
end
|
269
|
-
|
270
230
|
def my_readuntil(*args)
|
271
231
|
end
|
272
232
|
end
|