Class: StubBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/brine/test_steps.rb

Direct Known Subclasses

ResponseStatusSequenceStubBuilder

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeStubBuilder

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

#requestObject (readonly)

Returns the value of attribute request.



48
49
50
# File 'lib/brine/test_steps.rb', line 48

def request
  @request
end

#responseObject (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

#build(stubs) ⇒ Object



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

#make_responseObject



55
56
57
# File 'lib/brine/test_steps.rb', line 55

def make_response()
  [@response.status, {}, @response.body]
end