Class: Fitting::Response

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

Instance Method Summary collapse

Constructor Details

#initialize(env_response, tomogram) ⇒ Response

Returns a new instance of Response.



6
7
8
9
10
11
12
# File 'lib/fitting/response.rb', line 6

def initialize(env_response, tomogram)
  @request = Request.new(env_response.request, tomogram)
  @status = env_response.status
  @body = env_response.body
  @schemas = @request.schemas_of_possible_responses(status: @status)
  @fully_validates = set_fully_validate if @schemas
end

Instance Method Details

#diffObject



45
46
47
48
49
# File 'lib/fitting/response.rb', line 45

def diff
  @fully_validates.inject("") do |res, fully_validate|
    res + "#{fully_validate.join("\n")}\n\n"
  end
end

#documented?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/fitting/response.rb', line 25

def documented?
  @schemas && @schemas.present?
end

#expectedObject



51
52
53
54
55
# File 'lib/fitting/response.rb', line 51

def expected
  @schemas.inject([]) do |res, schema|
    res.push("#{schema}")
  end.join("\n\n")
end

#gotObject



41
42
43
# File 'lib/fitting/response.rb', line 41

def got
  @body
end

#real_request_with_statusObject



37
38
39
# File 'lib/fitting/response.rb', line 37

def real_request_with_status
  "#{@request.real_method_with_path} #{@status}"
end

#routeObject



33
34
35
# File 'lib/fitting/response.rb', line 33

def route
  "#{@request.route} #{@status} #{index}"
end

#set_fully_validateObject



14
15
16
17
18
19
20
21
22
23
# File 'lib/fitting/response.rb', line 14

def set_fully_validate
  @valid = false
  fully_validates = []
  @schemas.map do |old_schema|
    fully_validate = JSON::Validator.fully_validate(old_schema, @body)
    fully_validates.push(fully_validate)
    @valid = true if fully_validate == []
  end
  fully_validates
end

#valid?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/fitting/response.rb', line 29

def valid?
  @valid == true
end