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.



91
92
93
94
95
96
97
# File 'lib/faraday/adapter/test.rb', line 91

def initialize(full, body, block)
  path, query = full.split('?')
  params = query ?
    Rack::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



90
91
92
# File 'lib/faraday/adapter/test.rb', line 90

def block
  @block
end

#bodyObject

Returns the value of attribute body

Returns:

  • (Object)

    the current value of body



90
91
92
# File 'lib/faraday/adapter/test.rb', line 90

def body
  @body
end

#paramsObject

Returns the value of attribute params

Returns:

  • (Object)

    the current value of params



90
91
92
# File 'lib/faraday/adapter/test.rb', line 90

def params
  @params
end

#pathObject

Returns the value of attribute path

Returns:

  • (Object)

    the current value of path



90
91
92
# File 'lib/faraday/adapter/test.rb', line 90

def path
  @path
end

Instance Method Details

#matches?(request_uri, request_body) ⇒ Boolean

Returns:

  • (Boolean)


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

def matches?(request_uri, request_body)
  request_path, request_query = request_uri.split('?')
  request_params = request_query ?
    Rack::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)


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

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

#to_sObject



115
116
117
# File 'lib/faraday/adapter/test.rb', line 115

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