Class: Faraday::Adapter::Test::Stub
- Defined in:
- lib/faraday/adapter/test.rb
Instance Attribute Summary collapse
-
#block ⇒ Object
Returns the value of attribute block.
-
#body ⇒ Object
Returns the value of attribute body.
-
#params ⇒ Object
Returns the value of attribute params.
-
#path ⇒ Object
Returns the value of attribute path.
Instance Method Summary collapse
-
#initialize(full, body, block) ⇒ Stub
constructor
A new instance of Stub.
- #matches?(request_uri, request_body) ⇒ Boolean
- #params_match?(request_params) ⇒ Boolean
- #to_s ⇒ Object
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
#block ⇒ Object
Returns the value of attribute block
90 91 92 |
# File 'lib/faraday/adapter/test.rb', line 90 def block @block end |
#body ⇒ Object
Returns the value of attribute body
90 91 92 |
# File 'lib/faraday/adapter/test.rb', line 90 def body @body end |
#params ⇒ Object
Returns the value of attribute params
90 91 92 |
# File 'lib/faraday/adapter/test.rb', line 90 def params @params end |
#path ⇒ Object
Returns the value of attribute 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
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
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_s ⇒ Object
115 116 117 |
# File 'lib/faraday/adapter/test.rb', line 115 def to_s "#{path} #{body}" end |