diff options
author | Hiroshi SHIBATA <[email protected]> | 2024-02-15 16:39:14 +0900 |
---|---|---|
committer | Hiroshi SHIBATA <[email protected]> | 2024-02-15 18:57:23 +0900 |
commit | 4a00fcbd92d6fbc5514e04c1de3a0540e84e996e (patch) | |
tree | b18a90d3867aa383b8ee832de0bb1307698d3fd1 /spec/ruby/library/net-http/httpheader/fetch_spec.rb | |
parent | fa7529afd5566bab3d1db9bba6624122ffd1b4c8 (diff) |
Rename and restructured net/ftp and net/http examples
Diffstat (limited to 'spec/ruby/library/net-http/httpheader/fetch_spec.rb')
-rw-r--r-- | spec/ruby/library/net-http/httpheader/fetch_spec.rb | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/spec/ruby/library/net-http/httpheader/fetch_spec.rb b/spec/ruby/library/net-http/httpheader/fetch_spec.rb new file mode 100644 index 0000000000..58c69c0377 --- /dev/null +++ b/spec/ruby/library/net-http/httpheader/fetch_spec.rb @@ -0,0 +1,68 @@ +require_relative '../../../spec_helper' +require 'net/http' +require_relative 'fixtures/classes' + +describe "Net::HTTPHeader#fetch" do + before :each do + @headers = NetHTTPHeaderSpecs::Example.new + end + + describe "when passed key" do + it "returns the header entry for the passed key" do + @headers["My-Header"] = "test" + @headers.fetch("My-Header").should == "test" + + @headers.add_field("My-Other-Header", "a") + @headers.add_field("My-Other-Header", "b") + @headers.add_field("My-Other-Header", "c") + @headers.fetch("My-Other-Header").should == "a, b, c" + end + + it "is case-insensitive" do + @headers["My-Header"] = "test" + @headers.fetch("my-header").should == "test" + @headers.fetch("MY-HEADER").should == "test" + end + + it "returns nil when there is no entry for the passed key" do + -> { @headers.fetch("my-header") }.should raise_error(IndexError) + end + end + + describe "when passed key, default" do + it "returns the header entry for the passed key" do + @headers["My-Header"] = "test" + @headers.fetch("My-Header", "bla").should == "test" + + @headers.add_field("My-Other-Header", "a") + @headers.add_field("My-Other-Header", "b") + @headers.add_field("My-Other-Header", "c") + @headers.fetch("My-Other-Header", "bla").should == "a, b, c" + end + + # TODO: This raises a NoMethodError: undefined method `join' for "bla":String + it "returns the default value when there is no entry for the passed key" do + @headers.fetch("My-Header", "bla").should == "bla" + end + end + + describe "when passed key and block" do + it "returns the header entry for the passed key" do + @headers["My-Header"] = "test" + @headers.fetch("My-Header") {}.should == "test" + + @headers.add_field("My-Other-Header", "a") + @headers.add_field("My-Other-Header", "b") + @headers.add_field("My-Other-Header", "c") + -> { + @result = @headers.fetch("My-Other-Header", "bla") {} + }.should complain(/block supersedes default value argument/) + @result.should == "a, b, c" + end + + # TODO: This raises a NoMethodError: undefined method `join' for "redaeh-ym":String + it "yieldsand returns the block's return value when there is no entry for the passed key" do + @headers.fetch("My-Header") { |key| key.reverse }.should == "redaeh-ym" + end + end +end |