Sha256: 92e66d5ed255c156e75f6ff166185fcb5dd53c1ffa4c1224877265718d926d86

Contents?: true

Size: 815 Bytes

Versions: 1

Compression:

Stored size: 815 Bytes

Contents

# frozen_string_literal: true

require_relative "helper"

class RequestHeadersTest < Minitest::Test
  def setup
    env = { "HTTP_HOST" => "127.0.0.1", "CONTENT_TYPE" => "text/plain" }
    request = Tynn::Request.new(env)

    @headers = Tynn::Request::Headers.new(request)
  end

  def test_get_header
    assert_equal "127.0.0.1", @headers["Host"]
  end

  def test_check_if_key_exists
    assert @headers.key?("Host")
  end

  def test_fetch
    assert_equal "text/plain", @headers.fetch("content-type")
  end

  def test_fetch_raises_if_key_not_exists
    assert_raises(KeyError) { @headers.fetch("not-exists") }
  end

  def test_fetch_with_default
    assert_equal "not exists", @headers.fetch("not-exists", "not exists")
    assert_equal "not exists", @headers.fetch("not-exists") { "not exists" }
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tynn-2.0.0.alpha test/request_headers_test.rb