Module: Minitest::Assertions

Defined in:
lib/dock_test/assertions.rb

Instance Method Summary collapse

Instance Method Details

#assert_response_body(body_string) ⇒ Object



16
17
18
# File 'lib/dock_test/assertions.rb', line 16

def assert_response_body(body_string)
  assert last_response.body == body_string, "The actual response body is #{last_response.body}"
end

#assert_response_content_type(content_type) ⇒ Object



6
7
8
# File 'lib/dock_test/assertions.rb', line 6

def assert_response_content_type(content_type)
  assert last_response['Content-Type'] == content_type.to_s, "The actual response content_type is #{last_response['Content-Type']}"
end

#assert_response_headers(headers, options = {}) ⇒ Object



10
11
12
13
14
# File 'lib/dock_test/assertions.rb', line 10

def assert_response_headers(headers, options = {})
  exclude_keys = Array(options[:exclude] || [])
  response_headers = last_response.to_hash.delete_if {|k, _| exclude_keys.include?(k)}
  assert response_headers == headers, "The actual response headers are #{response_headers.inspect}"
end

#assert_response_json_schema(schema_path) ⇒ Object



20
21
22
23
24
# File 'lib/dock_test/assertions.rb', line 20

def assert_response_json_schema(schema_path)
  schema = File.open(schema_path).read
  errors = JSON::Validator.fully_validate(schema, last_response.body)
  assert errors.empty?, "The actual response does not match the schema defined in #{schema_path} because #{errors.join(', ')}"
end

#assert_response_status(status) ⇒ Object



2
3
4
# File 'lib/dock_test/assertions.rb', line 2

def assert_response_status(status)
  assert last_response.code == status.to_s, "The actual response status is #{last_response.code}"
end

#assert_response_xml_schema(schema_path) ⇒ Object



26
27
28
29
30
# File 'lib/dock_test/assertions.rb', line 26

def assert_response_xml_schema(schema_path)
  schema = ::Nokogiri::XML::Schema(File.read(schema_path))
  document = ::Nokogiri::XML(last_response.body)
  assert document.root && schema.valid?(document), "The actual response does not match the schema defined in #{schema_path} because #{schema.validate(document)}"
end