Class: StubBuilder
- Inherits:
-
Object
- Object
- StubBuilder
- Defined in:
- lib/brine/test_steps.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#request ⇒ Object
readonly
Returns the value of attribute request.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
- #build(stubs) ⇒ Object
-
#initialize ⇒ StubBuilder
constructor
A new instance of StubBuilder.
- #make_response ⇒ Object
Constructor Details
permalink #initialize ⇒ StubBuilder
Returns a new instance of StubBuilder.
50 51 52 53 |
# File 'lib/brine/test_steps.rb', line 50 def initialize @request = StubRequest.new @response = StubResponse.new end |
Instance Attribute Details
permalink #request ⇒ Object (readonly)
Returns the value of attribute request.
48 49 50 |
# File 'lib/brine/test_steps.rb', line 48 def request @request end |
permalink #response ⇒ Object (readonly)
Returns the value of attribute response.
48 49 50 |
# File 'lib/brine/test_steps.rb', line 48 def response @response end |
Instance Method Details
permalink #build(stubs) ⇒ Object
[View source]
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/brine/test_steps.rb', line 59 def build(stubs) # Currently the Faraday stub code provides one method per HTTP method (which then # calls a generalized protected method), so this block grabs the method to use # and passes the right args based on the signature. The last arg is normally a block # but we're using the make_response method to avoid duplication and allow overriding. m = stubs.method(@request.method) case m.parameters.length when 3 m.call(@request.path, @request.headers, &method(:make_response)) when 4 m.call(@request.path, @request.body, @request.headers, &method(:make_response)) else raise "I don't know how to call #{m}" end end |
permalink #make_response ⇒ Object
[View source]
55 56 57 |
# File 'lib/brine/test_steps.rb', line 55 def make_response() [@response.status, {}, @response.body] end |