Class: HTTP::Fake::Builder
- Inherits:
-
Object
- Object
- HTTP::Fake::Builder
- Defined in:
- lib/http/fake/builder.rb
Overview
Builds the response for a request.
Constant Summary collapse
- ALLOWED_VERBS =
/\A(connect|delete|get|head|options|patch|post|purge|put|trace)\z/
Instance Attribute Summary collapse
-
#requests ⇒ Object
readonly
Returns the value of attribute requests.
Instance Method Summary collapse
-
#initialize(verbs: ALLOWED_VERBS, responder: Responder) ⇒ Builder
constructor
:reek:DuplicateMethodCall.
- #method_missing(verb, *arguments) ⇒ Object
- #request(verb, uri, arguments = {}) ⇒ Object
Constructor Details
#initialize(verbs: ALLOWED_VERBS, responder: Responder) ⇒ Builder
:reek:DuplicateMethodCall
17 18 19 20 21 22 |
# File 'lib/http/fake/builder.rb', line 17 def initialize verbs: ALLOWED_VERBS, responder: Responder @verbs = verbs @responder = responder @requests ||= Hash.with_default Hash.with_default([]) @responders = Hash.with_default [] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(verb, *arguments) ⇒ Object
31 32 33 |
# File 'lib/http/fake/builder.rb', line 31 def method_missing(verb, *arguments, &) respond_to_missing?(verb) ? add_responder(verb, *arguments, &) : super end |
Instance Attribute Details
#requests ⇒ Object (readonly)
Returns the value of attribute requests.
14 15 16 |
# File 'lib/http/fake/builder.rb', line 14 def requests @requests end |
Instance Method Details
#request(verb, uri, arguments = {}) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/http/fake/builder.rb', line 24 def request verb, uri, arguments = {} responder = responders[verb].find { |fake| fake.match? verb, URI(uri).path } missing_route_error verb, uri unless responder requests[uri][verb] << arguments responder.call uri, arguments end |