class Hurley::HeaderTest

Public Instance Methods

test_delete_key() click to toggle source
# File test/header_test.rb, line 71
def test_delete_key
  h = Header.new :content_type => "text/plain"
  assert_equal %w(Content-Type), h.keys
  assert_equal "text/plain", h[:content_type]

  h.delete :content_type
  assert_equal [], h.keys
end
test_dup() click to toggle source
# File test/header_test.rb, line 95
def test_dup
  h1 = Header.new :content_type => "text/plain"
  h2 = h1
  h3 = h1.dup

  h2[:content_type] = "text/plain; charset=utf-8"
  h3[:content_type] = "image/gif"

  assert_equal "text/plain; charset=utf-8", h1[:content_type]
  assert_equal "text/plain; charset=utf-8", h2[:content_type]
  assert_equal "image/gif", h3[:content_type]
end
test_empty_initial() click to toggle source
# File test/header_test.rb, line 28
def test_empty_initial
  h = Header.new
  assert !h.key?(:content_type)
  assert_equal 0, h.size
  assert_equal [], h.keys
end
test_initial() click to toggle source
# File test/header_test.rb, line 35
def test_initial
  h = Header.new :content_type => "text/plain"
  assert_equal 1, h.size
  assert_equal %w(Content-Type), h.keys
  [
    "Content-Type",
    "content-type",
    :content_type,
  ].each do |key|
    assert h.key?(key)
    assert_equal "text/plain", h[key]
  end
end
test_integration() click to toggle source
# File test/header_test.rb, line 5
def test_integration
  client = Client.new "https://example.com"
  client.header["Client"] = "1"
  client.header["Override"] = "1"
  client.connection = Test.new do |t|
    t.get("/a") do |req|
      output = []
      req.header.each do |key, value|
        output << "#{key}:#{value}"
      end
      [200, {}, output.join("\n")]
    end
  end

  res = client.get("/a") do |req|
    req.header["Request"] = "2"
    req.header["Override"] = "2"
  end

  assert_equal 200, res.status_code
  assert_equal "User-Agent:Hurley v0.1\nClient:1\nOverride:2\nRequest:2", res.body
end
test_iterate_keys() click to toggle source
# File test/header_test.rb, line 80
def test_iterate_keys
  h = Header.new :content_type => "text/plain", :content_length => 2
  assert_equal %w(Content-Type Content-Length), h.keys
  assert_equal "text/plain", h[:content_type]
  assert_equal "2", h[:content_length]

  pieces = []
  h.each do |key, value|
    pieces << "#{key}=#{value}"
  end

  assert_equal "Content-Type=text/plain\nContent-Length=2",
    pieces.join("\n")
end
test_set_and_get_custom_key() click to toggle source
# File test/header_test.rb, line 60
def test_set_and_get_custom_key
  ["X-Hurley", "x-hurley", :x_hurley, "X-HURLEY"].each do |key|
    h = Header.new
    assert_nil h[key]

    h[key] = "text/plain"
    assert_equal %w(X-Hurley), h.keys
    assert_equal "text/plain", h[key]
  end
end
test_set_and_get_key_with_shortcuts() click to toggle source
# File test/header_test.rb, line 49
def test_set_and_get_key_with_shortcuts
  ["Content-Type", "content-type", :content_type, "CONTENT-TYPE"].each do |key|
    h = Header.new
    assert_nil h[key]

    h[key] = "text/plain"
    assert_equal %w(Content-Type), h.keys
    assert_equal "text/plain", h[key]
  end
end