Class: MnoeFaradayTestAdapter::Stub
- Inherits:
-
Struct
- Object
- Struct
- MnoeFaradayTestAdapter::Stub
- Defined in:
- lib/mno_enterprise/testing_support/mnoe_faraday_test_adapter.rb
Instance Attribute Summary collapse
-
#block ⇒ Object
Returns the value of attribute block.
-
#body ⇒ Object
Returns the value of attribute body.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#params ⇒ Object
Returns the value of attribute params.
-
#path ⇒ Object
Returns the value of attribute path.
Instance Method Summary collapse
- #headers_match?(request_headers) ⇒ Boolean
-
#initialize(full, headers, body, block) ⇒ Stub
constructor
A new instance of Stub.
- #matches?(request_uri, request_headers, request_body) ⇒ Boolean
- #params_deep_equal?(src, dst) ⇒ Boolean
- #params_match?(request_params) ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(full, headers, body, block) ⇒ Stub
Returns a new instance of Stub.
100 101 102 103 104 105 106 |
# File 'lib/mno_enterprise/testing_support/mnoe_faraday_test_adapter.rb', line 100 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
#block ⇒ Object
Returns the value of attribute block
99 100 101 |
# File 'lib/mno_enterprise/testing_support/mnoe_faraday_test_adapter.rb', line 99 def block @block end |
#body ⇒ Object
Returns the value of attribute body
99 100 101 |
# File 'lib/mno_enterprise/testing_support/mnoe_faraday_test_adapter.rb', line 99 def body @body end |
#headers ⇒ Object
Returns the value of attribute headers
99 100 101 |
# File 'lib/mno_enterprise/testing_support/mnoe_faraday_test_adapter.rb', line 99 def headers @headers end |
#params ⇒ Object
Returns the value of attribute params
99 100 101 |
# File 'lib/mno_enterprise/testing_support/mnoe_faraday_test_adapter.rb', line 99 def params @params end |
#path ⇒ Object
Returns the value of attribute path
99 100 101 |
# File 'lib/mno_enterprise/testing_support/mnoe_faraday_test_adapter.rb', line 99 def path @path end |
Instance Method Details
#headers_match?(request_headers) ⇒ Boolean
136 137 138 139 140 |
# File 'lib/mno_enterprise/testing_support/mnoe_faraday_test_adapter.rb', line 136 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
108 109 110 111 112 113 114 115 116 117 |
# File 'lib/mno_enterprise/testing_support/mnoe_faraday_test_adapter.rb', line 108 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_deep_equal?(src, dst) ⇒ Boolean
126 127 128 129 130 131 132 133 134 |
# File 'lib/mno_enterprise/testing_support/mnoe_faraday_test_adapter.rb', line 126 def params_deep_equal?(src,dst) src.keys.all? do |key| if src[key] && dst[key] && src[key].is_a?(Hash) && dst[key].is_a?(Hash) params_deep_equal?(src[key],dst[key]) else (src[key] == '**' && dst[key]) || src[key] == dst[key] end end end |
#params_match?(request_params) ⇒ Boolean
119 120 121 122 123 124 |
# File 'lib/mno_enterprise/testing_support/mnoe_faraday_test_adapter.rb', line 119 def params_match?(request_params) params_deep_equal?(params,request_params) # params.keys.all? do |key| # request_params[key] == params[key] # end end |
#to_s ⇒ Object
142 143 144 |
# File 'lib/mno_enterprise/testing_support/mnoe_faraday_test_adapter.rb', line 142 def to_s "#{path} #{body}" end |