Class: WebMock::Response
- Inherits:
-
Object
show all
- Defined in:
- lib/webmock/response.rb
Instance Method Summary
collapse
Constructor Details
#initialize(options = {}) ⇒ Response
Returns a new instance of Response.
16
17
18
19
20
21
22
|
# File 'lib/webmock/response.rb', line 16
def initialize(options = {})
if options.is_a?(IO) || options.is_a?(String)
self.options = read_raw_response(options)
else
self.options = options
end
end
|
Instance Method Details
#==(other) ⇒ Object
92
93
94
95
96
97
98
|
# File 'lib/webmock/response.rb', line 92
def ==(other)
self.body == other.body &&
self. === other. &&
self.status == other.status &&
self.exception == other.exception &&
self.should_timeout == other.should_timeout
end
|
#body ⇒ Object
35
36
37
|
# File 'lib/webmock/response.rb', line 35
def body
@body || ''
end
|
#body=(body) ⇒ Object
39
40
41
42
43
|
# File 'lib/webmock/response.rb', line 39
def body=(body)
@body = body
assert_valid_body!
stringify_body!
end
|
#evaluate(request_signature) ⇒ Object
83
84
85
86
87
88
89
90
|
# File 'lib/webmock/response.rb', line 83
def evaluate(request_signature)
self.body = @body.call(request_signature) if @body.is_a?(Proc)
self. = @headers.call(request_signature) if @headers.is_a?(Proc)
self.status = @status.call(request_signature) if @status.is_a?(Proc)
@should_timeout = @should_timeout.call(request_signature) if @should_timeout.is_a?(Proc)
@exception = @exception.call(request_signature) if @exception.is_a?(Proc)
self
end
|
#exception ⇒ Object
53
54
55
|
# File 'lib/webmock/response.rb', line 53
def exception
@exception
end
|
#exception=(exception) ⇒ Object
57
58
59
60
61
62
63
|
# File 'lib/webmock/response.rb', line 57
def exception=(exception)
@exception = case exception
when String then StandardError.new(exception)
when Class then exception.new('Exception from WebMock')
when Exception then exception
end
end
|
24
25
26
|
# File 'lib/webmock/response.rb', line 24
def
@headers
end
|
28
29
30
31
32
33
|
# File 'lib/webmock/response.rb', line 28
def ()
@headers =
if @headers && !@headers.is_a?(Proc)
@headers = Util::Headers.(@headers)
end
end
|
#options=(options) ⇒ Object
73
74
75
76
77
78
79
80
81
|
# File 'lib/webmock/response.rb', line 73
def options=(options)
options = WebMock::Util::HashKeysStringifier.stringify_keys!(options)
HashValidator.new(options).validate_keys('headers', 'status', 'body', 'exception', 'should_timeout')
self. = options['headers']
self.status = options['status']
self.body = options['body']
self.exception = options['exception']
@should_timeout = options['should_timeout']
end
|
#raise_error_if_any ⇒ Object
65
66
67
|
# File 'lib/webmock/response.rb', line 65
def raise_error_if_any
raise @exception if @exception
end
|
#should_timeout ⇒ Object
69
70
71
|
# File 'lib/webmock/response.rb', line 69
def should_timeout
@should_timeout == true
end
|
#status ⇒ Object
45
46
47
|
# File 'lib/webmock/response.rb', line 45
def status
@status || [200, ""]
end
|
#status=(status) ⇒ Object
49
50
51
|
# File 'lib/webmock/response.rb', line 49
def status=(status)
@status = status.is_a?(Integer) ? [status, ""] : status
end
|