Class: Fitting::Records::TestUnit::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/fitting/records/test_unit/request.rb

Instance Method Summary collapse

Constructor Details

#initialize(tested_request, all_documented_requests) ⇒ Request

Returns a new instance of Request.



7
8
9
10
# File 'lib/fitting/records/test_unit/request.rb', line 7

def initialize(tested_request, all_documented_requests)
  @tested_request = tested_request
  @all_documented_requests = all_documented_requests
end

Instance Method Details

#bodyObject



20
21
22
# File 'lib/fitting/records/test_unit/request.rb', line 20

def body
  @body ||= @tested_request.body
end

#documented?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/fitting/records/test_unit/request.rb', line 44

def documented?
  @documented ||= documented_requests.present?
end

#documented_requestsObject



36
37
38
39
40
41
42
# File 'lib/fitting/records/test_unit/request.rb', line 36

def documented_requests
  @documented_requests ||= @all_documented_requests.inject([]) do |res, documented_request|
    next res unless @tested_request.method == documented_request.method &&
                    documented_request.path.match(@tested_request.path.to_s)
    res.push(documented_request)
  end
end

#documented_responsesObject



48
49
50
51
52
53
54
55
# File 'lib/fitting/records/test_unit/request.rb', line 48

def documented_responses
  @documented_responses ||= documented_requests.inject([]) do |res, documented_request|
    documented_request.responses.map do |documented_response|
      next unless documented_response['status'] == response.status.to_s
      res.push(documented_response)
    end
  end.flatten.compact
end

#invalid_json_schemasObject



78
79
80
81
82
83
84
85
86
# File 'lib/fitting/records/test_unit/request.rb', line 78

def invalid_json_schemas
  @invalid_json_schemas ||= response_json_schemas.inject([]) do |res, json_schema|
    next res if JSON::Validator.validate(json_schema, response.body)
    res.push(
      json_schema: json_schema,
      fully_validate: JSON::Validator.fully_validate(json_schema, response.body)
    )
  end.flatten
end

#methodObject



12
13
14
# File 'lib/fitting/records/test_unit/request.rb', line 12

def method
  @method ||= @tested_request.method
end

#pathObject



16
17
18
# File 'lib/fitting/records/test_unit/request.rb', line 16

def path
  @path ||= @tested_request.path
end

#responseObject



24
25
26
# File 'lib/fitting/records/test_unit/request.rb', line 24

def response
  @response ||= @tested_request.response
end

#response_documented?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/fitting/records/test_unit/request.rb', line 57

def response_documented?
  @response_documented ||= documented_responses.present?
end

#response_json_schemasObject



61
62
63
64
65
# File 'lib/fitting/records/test_unit/request.rb', line 61

def response_json_schemas
  @response_json_schemas ||= documented_responses.inject([]) do |res, documented_response|
    res.push(documented_response['json_schemas'])
  end.flatten
end

#response_json_schemas?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/fitting/records/test_unit/request.rb', line 67

def response_json_schemas?
  @response_json_schemas_present ||= response_json_schemas.present?
end

#test_file_pathObject



32
33
34
# File 'lib/fitting/records/test_unit/request.rb', line 32

def test_file_path
  @test_file_path ||= @tested_request.group
end

#test_pathObject



28
29
30
# File 'lib/fitting/records/test_unit/request.rb', line 28

def test_path
  @test_path ||= @tested_request.title
end

#valid_json_schemasObject



71
72
73
74
75
76
# File 'lib/fitting/records/test_unit/request.rb', line 71

def valid_json_schemas
  @valid_json_schemas ||= response_json_schemas.inject([]) do |res, json_schema|
    next res unless JSON::Validator.validate(json_schema, response.body)
    res.push(json_schema)
  end.flatten
end

#valid_json_schemas?Boolean

Returns:

  • (Boolean)


88
89
90
# File 'lib/fitting/records/test_unit/request.rb', line 88

def valid_json_schemas?
  @valid_json_schemas_present ||= valid_json_schemas.present?
end