Class: Qeweney::MockAdapter
- Inherits:
-
Object
- Object
- Qeweney::MockAdapter
- Defined in:
- lib/qeweney/mock_adapter.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#calls ⇒ Object
readonly
Returns the value of attribute calls.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
Class Method Summary collapse
Instance Method Summary collapse
- #complete?(_req) ⇒ Boolean
- #get_body(_req) ⇒ Object
- #get_body_chunk(_req, _buffered_only) ⇒ Object
-
#initialize(request_body) ⇒ MockAdapter
constructor
A new instance of MockAdapter.
- #method_missing(sym, *args) ⇒ Object
- #respond(req, body, headers) ⇒ Object
- #status ⇒ Object
Constructor Details
#initialize(request_body) ⇒ MockAdapter
Returns a new instance of MockAdapter.
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/qeweney/mock_adapter.rb', line 21 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
43 44 45 |
# File 'lib/qeweney/mock_adapter.rb', line 43 def method_missing(sym, *args) calls << [sym, *args] end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
5 6 7 |
# File 'lib/qeweney/mock_adapter.rb', line 5 def body @body end |
#calls ⇒ Object (readonly)
Returns the value of attribute calls.
5 6 7 |
# File 'lib/qeweney/mock_adapter.rb', line 5 def calls @calls end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
5 6 7 |
# File 'lib/qeweney/mock_adapter.rb', line 5 def headers @headers end |
Class Method Details
Instance Method Details
#complete?(_req) ⇒ Boolean
17 18 19 |
# File 'lib/qeweney/mock_adapter.rb', line 17 def complete?(_req) @request_body_chunks.empty? end |
#get_body(_req) ⇒ Object
11 12 13 14 15 |
# File 'lib/qeweney/mock_adapter.rb', line 11 def get_body(_req) body = @request_body_chunks.join('') @request_body_chunks.clear body end |
#get_body_chunk(_req, _buffered_only) ⇒ Object
7 8 9 |
# File 'lib/qeweney/mock_adapter.rb', line 7 def get_body_chunk(_req, _buffered_only) @request_body_chunks.shift end |
#respond(req, body, headers) ⇒ Object
33 34 35 36 37 |
# File 'lib/qeweney/mock_adapter.rb', line 33 def respond(req, body, headers) @calls << [:respond, req, body, headers] @body = body @headers = headers end |