module Rapidash::TestClient

Attributes

json[R]
responses[R]
stubs[R]

Public Class Methods

new(responses, options = {}) click to toggle source
# File lib/rapidash/test_client.rb, line 29
def initialize(responses, options = {})
  @json = options[:json] || false
  @responses = responses
  build_stubs
end

Public Instance Methods

request(verb, url, options = {}) click to toggle source
# File lib/rapidash/test_client.rb, line 35
def request(verb, url, options = {})
  connection.send(verb, url, options).body
end

Private Instance Methods

build_stubs() click to toggle source
# File lib/rapidash/test_client.rb, line 41
def build_stubs
  @stubs = Faraday::Adapter::Test::Stubs.new do |stub|
    responses.each_pair do |verb, req|
      req.each_pair do |url, body|
        stub.send(verb, url) { [200, {}, body] }
      end
    end
  end
end
connection() click to toggle source
# File lib/rapidash/test_client.rb, line 51
def connection
  @connection ||= Faraday.new do |builder|
    builder.adapter :test, stubs
    builder.use FaradayMiddleware::Mashify

    if json
      builder.use FaradayMiddleware::ParseJson
    end
  end
end