Class: MnoeFaradayTestAdapter::Stub

Inherits:
Struct
  • Object
show all
Defined in:
lib/mno_enterprise/testing_support/mnoe_faraday_test_adapter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#blockObject

Returns the value of attribute block

Returns:

  • (Object)

    the current value of block



99
100
101
# File 'lib/mno_enterprise/testing_support/mnoe_faraday_test_adapter.rb', line 99

def block
  @block
end

#bodyObject

Returns the value of attribute body

Returns:

  • (Object)

    the current value of body



99
100
101
# File 'lib/mno_enterprise/testing_support/mnoe_faraday_test_adapter.rb', line 99

def body
  @body
end

#headersObject

Returns the value of attribute headers

Returns:

  • (Object)

    the current value of headers



99
100
101
# File 'lib/mno_enterprise/testing_support/mnoe_faraday_test_adapter.rb', line 99

def headers
  @headers
end

#paramsObject

Returns the value of attribute params

Returns:

  • (Object)

    the current value of params



99
100
101
# File 'lib/mno_enterprise/testing_support/mnoe_faraday_test_adapter.rb', line 99

def params
  @params
end

#pathObject

Returns the value of attribute path

Returns:

  • (Object)

    the current value of 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

Returns:

  • (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

Returns:

  • (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

Returns:

  • (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

Returns:

  • (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_sObject



142
143
144
# File 'lib/mno_enterprise/testing_support/mnoe_faraday_test_adapter.rb', line 142

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