Sha256: 9f9bc1a7d00d440d7d94f959dca66c9482e3b535b9ac9fa3292e1a47ba31b346

Contents?: true

Size: 1.4 KB

Versions: 9

Compression:

Stored size: 1.4 KB

Contents

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

  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

  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

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

  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

  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

end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
dock_test-0.4.8 lib/dock_test/assertions.rb
dock_test-0.4.6 lib/dock_test/assertions.rb
dock_test-0.4.5 lib/dock_test/assertions.rb
dock_test-0.4.0 lib/dock_test/assertions.rb
dock_test-0.3.7 lib/dock_test/assertions.rb
dock_test-0.3.6 lib/dock_test/assertions.rb
dock_test-0.3.5 lib/dock_test/assertions.rb
dock_test-0.3.4 lib/dock_test/assertions.rb
dock_test-0.3.3 lib/dock_test/assertions.rb