Class: ApiValidator::ResponseExpectation::Results

Inherits:
Object
  • Object
show all
Includes:
Mixins::DeepMerge
Defined in:
lib/api-validator/response_expectation/results.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Mixins::DeepMerge

#deep_merge!

Constructor Details

#initialize(response, results) ⇒ Results

Returns a new instance of Results.



8
9
10
# File 'lib/api-validator/response_expectation/results.rb', line 8

def initialize(response, results)
  @response, @results = response, results
end

Instance Attribute Details

#responseObject (readonly)

Returns the value of attribute response.



7
8
9
# File 'lib/api-validator/response_expectation/results.rb', line 7

def response
  @response
end

#resultsObject (readonly)

Returns the value of attribute results.



7
8
9
# File 'lib/api-validator/response_expectation/results.rb', line 7

def results
  @results
end

Instance Method Details

#as_json(options = {}) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/api-validator/response_expectation/results.rb', line 12

def as_json(options = {})
  res = results.inject(Hash.new) do |memo, result|
    result = result.dup
    deep_merge!((memo[result.delete(:key)] ||= Hash.new), result)
    memo
  end

  merge_diffs!(res)

  {
    :expected => res,
    :actual => {
      :request_headers => response.env[:request_headers],
      :request_body => response.env[:request_body],
      :request_path => response.env[:url].path,
      :request_params => parse_params(response.env[:url]),
      :request_url => response.env[:url].to_s,
      :request_method => response.env[:method].to_s.upcase,

      :response_headers => response.headers,
      :response_body => response.body,
      :response_status => response.status
    }
  }
end