4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/excon/middlewares/mock.rb', line 4
def request_call(datum)
if datum[:mock]
unless datum[:body].nil? || datum[:body].is_a?(String)
if datum[:body].respond_to?(:binmode)
datum[:body].binmode
end
if datum[:body].respond_to?(:rewind)
datum[:body].rewind
end
datum[:body] = datum[:body].read
end
if stub = Excon.stub_for(datum)
datum[:response] = {
:body => '',
:headers => {},
:status => 200,
:remote_ip => '127.0.0.1'
}
stub_datum = case stub.last
when Proc
stub.last.call(datum)
else
stub.last
end
datum[:response].merge!(stub_datum.reject {|key,value| key == :headers})
if stub_datum.has_key?(:headers)
datum[:response][:headers].merge!(stub_datum[:headers])
end
else
raise(Excon::Errors::StubNotFound.new('no stubs matched ' << datum.inspect))
end
end
@stack.request_call(datum)
end
|