Sha256: 40911198ca46ee17df7094f2bd37136a6ac71a67ae7702165e44a5a2034522d4

Contents?: true

Size: 1.37 KB

Versions: 36

Compression:

Stored size: 1.37 KB

Contents

require File.join(File.expand_path(__FILE__).sub(/\/ftw\/.*/, "/testing"))
require "ftw/http/headers"

describe FTW::HTTP::Headers do
  before do
    @headers = FTW::HTTP::Headers.new
  end

  test "add adds" do
    @headers.add("foo", "bar")
    @headers.add("baz", "fizz")
    assert_equal("fizz", @headers.get("baz"))
    assert_equal("bar", @headers.get("foo"))
  end

  test "add dup field name makes an array" do
    @headers.add("foo", "bar")
    @headers.add("foo", "fizz")
    assert_equal(["bar", "fizz"], @headers.get("foo"))
  end

  test "set replaces" do
    @headers.add("foo", "bar")
    @headers.set("foo", "hello")
    assert_equal("hello", @headers.get("foo"))
  end

  test "remove field" do
    @headers.add("foo", "one")
    @headers.add("bar", "two")
    assert_equal("one", @headers.get("foo"))
    assert_equal("two", @headers.get("bar"))

    @headers.remove("bar")
    assert_equal("one", @headers.get("foo"))
     # bar was removed, must not be present
    assert(!@headers.include?("bar"))
  end

  test "remove field value" do
    @headers.add("foo", "one")
    @headers.add("foo", "two")
    assert_equal(["one", "two"], @headers.get("foo"))

    @headers.remove("foo", "three") # nothing to remove
    assert_equal(["one", "two"], @headers.get("foo"))
    @headers.remove("foo", "two")
    assert_equal("one", @headers.get("foo"))
  end
end # describe FTW::HTTP::Headers

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
ftw-0.0.40 test/ftw/http/headers.rb
ftw-0.0.39 test/ftw/http/headers.rb
ftw-0.0.38 test/ftw/http/headers.rb
ftw-0.0.37 test/ftw/http/headers.rb
ftw-0.0.36 test/ftw/http/headers.rb
ftw-0.0.35 test/ftw/http/headers.rb
ftw-0.0.34 test/ftw/http/headers.rb
ftw-0.0.33 test/ftw/http/headers.rb
ftw-0.0.32 test/ftw/http/headers.rb
ftw-0.0.31 test/ftw/http/headers.rb
ftw-0.0.30 test/ftw/http/headers.rb
ftw-0.0.29 test/ftw/http/headers.rb
ftw-0.0.28 test/ftw/http/headers.rb
ftw-0.0.27 test/ftw/http/headers.rb
ftw-0.0.26 test/ftw/http/headers.rb
ftw-0.0.25 test/ftw/http/headers.rb
ftw-0.0.24 test/ftw/http/headers.rb
ftw-0.0.23 test/ftw/http/headers.rb
ftw-0.0.22 test/ftw/http/headers.rb
ftw-0.0.21 test/ftw/http/headers.rb