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, body, block) ⇒ Stub

Returns a new instance of Stub.



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

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

Instance Attribute Details

#blockObject

Returns the value of attribute block

Returns:

  • (Object)

    the current value of block



105
106
107
# File 'lib/faraday/adapter/test.rb', line 105

def block
  @block
end

#bodyObject

Returns the value of attribute body

Returns:

  • (Object)

    the current value of body



105
106
107
# File 'lib/faraday/adapter/test.rb', line 105

def body
  @body
end

#paramsObject

Returns the value of attribute params

Returns:

  • (Object)

    the current value of params



105
106
107
# File 'lib/faraday/adapter/test.rb', line 105

def params
  @params
end

#pathObject

Returns the value of attribute path

Returns:

  • (Object)

    the current value of path



105
106
107
# File 'lib/faraday/adapter/test.rb', line 105

def path
  @path
end

Instance Method Details

#matches?(request_uri, request_body) ⇒ Boolean

Returns:

  • (Boolean)


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

def matches?(request_uri, 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)
end

#params_match?(request_params) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#to_sObject



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

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