Sha256: 19520fa5e18259b18a8f58cbb885fb7a50c161414ce7b4d84f706d317e5a84b2

Contents?: true

Size: 1.33 KB

Versions: 6

Compression:

Stored size: 1.33 KB

Contents

require 'base64'

class Holodeck
  attr_accessor :host, :port

  class Request
    attr_reader :method, :url, :auth, :params, :data, :headers, :any

    def initialize(method: nil, url: nil, auth: nil, params: {}, data: {}, headers: {}, any: false)
      @method = method
      @url = url
      @auth = auth
      @params = params
      @data = data
      @headers = headers
      @any = any
    end

    def any?
      @any
    end

    def ==(other)
      if method.casecmp(other.method.upcase).zero? &&
         url == other.url &&
         params == other.params &&
         data == other.data
        other.headers.each do |h, value|
          return false unless headers[h] == value
        end
        true
      end
    end

    def to_s
      "#<Holodeck::Request method:#{method} url:#{url} params:#{params} data:#{data} headers:#{headers}>"
    end
  end

  ANY = Request.new(any: true)

  def initialize
    @response = nil
    @requests = []
  end

  def mock(response)
    @response = response
  end

  def request(host, port, method, url, params = {}, data = {}, headers = {}, auth = nil, _timeout = nil)
    @requests << Request.new(
      method: method,
      url: url,
      params: params,
      data: data,
      headers: headers,
      auth: auth
    )
    @response
  end

  def has_request?(request)
    @requests.include?(request)
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
twilio-ruby-5.40.1 spec/holodeck/holodeck.rb
twilio-ruby-5.40.0 spec/holodeck/holodeck.rb
twilio-ruby-5.39.3 spec/holodeck/holodeck.rb
twilio-ruby-5.39.2 spec/holodeck/holodeck.rb
twilio-ruby-5.39.1 spec/holodeck/holodeck.rb
twilio-ruby-5.39.0 spec/holodeck/holodeck.rb