Parent

Files

WebMock::Response

Public Class Methods

new(options = {}) click to toggle source
    # File lib/webmock/response.rb, line 19
19:     def initialize(options = {})
20:       if options.is_a?(IO) || options.is_a?(String)
21:         self.options = read_raw_response(options)
22:       else
23:         self.options = options
24:       end
25:     end

Public Instance Methods

==(other) click to toggle source
    # File lib/webmock/response.rb, line 92
92:     def ==(other)
93:       self.body == other.body &&
94:       self.headers === other.headers &&
95:       self.status == other.status &&
96:       self.exception == other.exception &&
97:       self.should_timeout == other.should_timeout
98:     end
body() click to toggle source
    # File lib/webmock/response.rb, line 38
38:     def body
39:       @body || ''
40:     end
body=(body) click to toggle source
    # File lib/webmock/response.rb, line 42
42:     def body=(body)
43:       @body = body
44:       stringify_body!
45:     end
evaluate!(request_signature) click to toggle source
    # File lib/webmock/response.rb, line 83
83:     def evaluate!(request_signature)
84:       self.body = @body.call(request_signature) if @body.is_a?(Proc)
85:       self.headers = @headers.call(request_signature) if @headers.is_a?(Proc)
86:       self.status = @status.call(request_signature) if @status.is_a?(Proc)
87:       @should_timeout = @should_timeout.call(request_signature) if @should_timeout.is_a?(Proc)
88:       @exception = @exception.call(request_signature) if @exception.is_a?(Proc)
89:       self
90:     end
exception() click to toggle source
    # File lib/webmock/response.rb, line 55
55:     def exception
56:       @exception
57:     end
exception=(exception) click to toggle source
    # File lib/webmock/response.rb, line 59
59:     def exception=(exception)
60:       @exception = case exception
61:       when String then StandardError.new(exception)
62:       when Class then exception.new('Exception from WebMock')
63:       when Exception then exception
64:       end
65:     end
headers() click to toggle source
    # File lib/webmock/response.rb, line 27
27:     def headers
28:       @headers
29:     end
headers=(headers) click to toggle source
    # File lib/webmock/response.rb, line 31
31:     def headers=(headers)
32:       @headers = headers
33:       if @headers && !@headers.is_a?(Proc)
34:         @headers = Util::Headers.normalize_headers(@headers)
35:       end
36:     end
options=(options) click to toggle source
    # File lib/webmock/response.rb, line 75
75:     def options=(options)
76:       self.headers = options[:headers]
77:       self.status = options[:status]
78:       self.body = options[:body]
79:       self.exception = options[:exception]
80:       @should_timeout = options[:should_timeout]
81:     end
raise_error_if_any() click to toggle source
    # File lib/webmock/response.rb, line 67
67:     def raise_error_if_any
68:       raise @exception if @exception
69:     end
should_timeout() click to toggle source
    # File lib/webmock/response.rb, line 71
71:     def should_timeout
72:       @should_timeout == true
73:     end
status() click to toggle source
    # File lib/webmock/response.rb, line 47
47:     def status
48:       @status || [200, ""]
49:     end
status=(status) click to toggle source
    # File lib/webmock/response.rb, line 51
51:     def status=(status)
52:       @status = status.is_a?(Integer) ? [status, ""] : status
53:     end

Private Instance Methods

read_raw_response(raw_response) click to toggle source
     # File lib/webmock/response.rb, line 110
110:     def read_raw_response(raw_response)
111:       if raw_response.is_a?(IO)
112:         string = raw_response.read
113:         raw_response.close
114:         raw_response = string
115:       end
116:       socket = ::Net::BufferedIO.new(raw_response)
117:       response = ::Net::HTTPResponse.read_new(socket)
118:       transfer_encoding = response.delete('transfer-encoding') #chunks were already read by curl
119:       response.reading_body(socket, true) {}
120: 
121:       options = {}
122:       options[:headers] = {}
123:       response.each_header {|name, value| options[:headers][name] = value}
124:       options[:headers]['transfer-encoding'] = transfer_encoding if transfer_encoding
125:       options[:body] = response.read_body
126:       options[:status] = [response.code.to_i, response.message]
127:       options
128:     end
stringify_body!() click to toggle source
     # File lib/webmock/response.rb, line 102
102:     def stringify_body!
103:       if @body.is_a?(IO)
104:         io = @body
105:         @body = io.read
106:         io.close
107:       end
108:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.