Class: Capsium::Package::Testing::RouteTest

Inherits:
TestCase
  • Object
show all
Defined in:
lib/capsium/package/testing/route_test.rb,
sig/capsium/package/testing/route_test.rbs

Overview

A "route" test (05x-testing): requests the URL path from the reactor serving the package and checks the expected status, and optionally the content type and a response body substring.

Instance Attribute Summary collapse

Attributes inherited from TestCase

#name

Instance Method Summary collapse

Methods inherited from TestCase

build, from_h, register, types

Constructor Details

#initialize(name:, url:, expected_status:, response_contains: nil, expected_content_type: nil) ⇒ RouteTest

Returns a new instance of RouteTest.



15
16
17
18
19
20
21
22
# File 'lib/capsium/package/testing/route_test.rb', line 15

def initialize(name:, url:, expected_status:, response_contains: nil,
               expected_content_type: nil)
  super(name: name)
  @url = url
  @expected_status = expected_status
  @response_contains = response_contains
  @expected_content_type = expected_content_type
end

Instance Attribute Details

#expected_content_typeString? (readonly)

Returns the value of attribute expected_content_type.

Returns:

  • (String, nil)


13
14
15
# File 'lib/capsium/package/testing/route_test.rb', line 13

def expected_content_type
  @expected_content_type
end

#expected_statusInteger (readonly)

Returns the value of attribute expected_status.

Returns:

  • (Integer)


13
14
15
# File 'lib/capsium/package/testing/route_test.rb', line 13

def expected_status
  @expected_status
end

#response_containsString? (readonly)

Returns the value of attribute response_contains.

Returns:

  • (String, nil)


13
14
15
# File 'lib/capsium/package/testing/route_test.rb', line 13

def response_contains
  @response_contains
end

#urlString (readonly)

Returns the value of attribute url.

Returns:

  • (String)


13
14
15
# File 'lib/capsium/package/testing/route_test.rb', line 13

def url
  @url
end

Instance Method Details

#run(context) ⇒ TestCase::Result

Parameters:

Returns:



24
25
26
27
28
29
# File 'lib/capsium/package/testing/route_test.rb', line 24

def run(context)
  response = Net::HTTP.get_response(URI.join(context.base_url, request_path))
  problems = status_problems(response) + content_type_problems(response) +
             body_problems(response)
  Result.new(name: name, ok: problems.empty?, messages: problems)
end