Class: Qeweney::MockAdapter
- Inherits:
-
Object
- Object
- Qeweney::MockAdapter
show all
- Defined in:
- lib/qeweney/mock_adapter.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(request_body) ⇒ MockAdapter
Returns a new instance of MockAdapter.
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/qeweney/mock_adapter.rb', line 23
def initialize(request_body)
case request_body
when Array
@request_body_chunks = request_body
when nil
@request_body_chunks = []
else
@request_body_chunks = [request_body]
end
@calls = []
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args) ⇒ Object
49
50
51
|
# File 'lib/qeweney/mock_adapter.rb', line 49
def method_missing(sym, *args)
calls << [sym, *args]
end
|
Instance Attribute Details
#calls ⇒ Object
Returns the value of attribute calls.
7
8
9
|
# File 'lib/qeweney/mock_adapter.rb', line 7
def calls
@calls
end
|
#response_body ⇒ Object
Returns the value of attribute response_body.
7
8
9
|
# File 'lib/qeweney/mock_adapter.rb', line 7
def response_body
@response_body
end
|
Returns the value of attribute response_headers.
7
8
9
|
# File 'lib/qeweney/mock_adapter.rb', line 7
def
@response_headers
end
|
Class Method Details
.mock(headers = {}, request_body = nil) ⇒ Object
53
54
55
56
57
|
# File 'lib/qeweney/mock_adapter.rb', line 53
def self.mock( = {}, request_body = nil)
[':method'] ||= ''
[':path'] ||= ''
Request.new(, new(request_body))
end
|
Instance Method Details
#complete?(_req) ⇒ Boolean
19
20
21
|
# File 'lib/qeweney/mock_adapter.rb', line 19
def complete?(_req)
@request_body_chunks.empty?
end
|
#get_body(_req) ⇒ Object
13
14
15
16
17
|
# File 'lib/qeweney/mock_adapter.rb', line 13
def get_body(_req)
body = @request_body_chunks.join('')
@request_body_chunks.clear
body
end
|
#get_body_chunk(_req, _buffered_only) ⇒ Object
9
10
11
|
# File 'lib/qeweney/mock_adapter.rb', line 9
def get_body_chunk(_req, _buffered_only)
@request_body_chunks.shift
end
|
#respond(req, body, headers) ⇒ Object
39
40
41
42
43
|
# File 'lib/qeweney/mock_adapter.rb', line 39
def respond(req, body, )
@calls << [:respond, req, body, ]
@response_body = body
@response_headers =
end
|
35
36
37
|
# File 'lib/qeweney/mock_adapter.rb', line 35
def ()
@response_headers =
end
|
#status ⇒ Object
45
46
47
|
# File 'lib/qeweney/mock_adapter.rb', line 45
def status
[':status'] || Qeweney::Status::OK
end
|