Class: Fitting::Report::Responses

Inherits:
Object
  • Object
show all
Defined in:
lib/fitting/report/responses.rb

Defined Under Namespace

Classes: NotFound

Instance Method Summary collapse

Constructor Details

#initialize(responses) ⇒ Responses

Returns a new instance of Responses.



15
16
17
18
19
20
21
# File 'lib/fitting/report/responses.rb', line 15

def initialize(responses)
  @responses = responses
  @responses = []
  responses.to_a.map do |response|
    @responses.push(Fitting::Report::Response.new(response))
  end
end

Instance Method Details

#find!(log) ⇒ Object

Raises:



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/fitting/report/responses.rb', line 23

def find!(log)
  message = ""
  @responses.map do |response|
    if response.status.to_s == log.status
      if JSON::Validator.fully_validate(response.body, log.body) == []
        return response
      else
        message += "\nbody: #{response.body}\nvalidate: #{JSON::Validator.fully_validate(response.body, log.body)}\n"
      end
    else
      message += "\nstatus: #{response.status}\n"
    end
  end

  raise NotFound.new("method: #{log.method}, host: #{log.host}, path: #{log.path}, status: #{log.status}, body: #{log.body}\n\n#{message}", log)
end

#to_aObject



40
41
42
# File 'lib/fitting/report/responses.rb', line 40

def to_a
  @responses
end