Class: Faraday::Adapter::Test::Stub

Inherits:
Struct
  • Object
show all
Defined in:
lib/faraday/adapter/test.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(full, headers, body, block) ⇒ Stub

Returns a new instance of Stub



98
99
100
101
102
103
104
# File 'lib/faraday/adapter/test.rb', line 98

def initialize(full, headers, body, block)
  path, query = full.split('?')
  params = query ?
    Faraday::Utils.parse_nested_query(query) :
    {}
  super(path, params, headers, body, block)
end

Instance Attribute Details

#blockObject

Returns the value of attribute block

Returns:

  • (Object)

    the current value of block



97
98
99
# File 'lib/faraday/adapter/test.rb', line 97

def block
  @block
end

#bodyObject

Returns the value of attribute body

Returns:

  • (Object)

    the current value of body



97
98
99
# File 'lib/faraday/adapter/test.rb', line 97

def body
  @body
end

#headersObject

Returns the value of attribute headers

Returns:

  • (Object)

    the current value of headers



97
98
99
# File 'lib/faraday/adapter/test.rb', line 97

def headers
  @headers
end

#paramsObject

Returns the value of attribute params

Returns:

  • (Object)

    the current value of params



97
98
99
# File 'lib/faraday/adapter/test.rb', line 97

def params
  @params
end

#pathObject

Returns the value of attribute path

Returns:

  • (Object)

    the current value of path



97
98
99
# File 'lib/faraday/adapter/test.rb', line 97

def path
  @path
end

Instance Method Details

#headers_match?(request_headers) ⇒ Boolean

Returns:

  • (Boolean)


123
124
125
126
127
# File 'lib/faraday/adapter/test.rb', line 123

def headers_match?(request_headers)
  headers.keys.all? do |key|
    request_headers[key] == headers[key]
  end
end

#matches?(request_uri, request_headers, request_body) ⇒ Boolean

Returns:

  • (Boolean)


106
107
108
109
110
111
112
113
114
115
# File 'lib/faraday/adapter/test.rb', line 106

def matches?(request_uri, request_headers, request_body)
  request_path, request_query = request_uri.split('?')
  request_params = request_query ?
    Faraday::Utils.parse_nested_query(request_query) :
    {}
  request_path == path &&
    params_match?(request_params) &&
    (body.to_s.size.zero? || request_body == body) &&
    headers_match?(request_headers)
end

#params_match?(request_params) ⇒ Boolean

Returns:

  • (Boolean)


117
118
119
120
121
# File 'lib/faraday/adapter/test.rb', line 117

def params_match?(request_params)
  params.keys.all? do |key|
    request_params[key] == params[key]
  end
end

#to_sObject



129
130
131
# File 'lib/faraday/adapter/test.rb', line 129

def to_s
  "#{path} #{body}"
end