diff options
Diffstat (limited to 'spec/ruby/library/cgi/cookie')
-rw-r--r-- | spec/ruby/library/cgi/cookie/domain_spec.rb | 33 | ||||
-rw-r--r-- | spec/ruby/library/cgi/cookie/expires_spec.rb | 33 | ||||
-rw-r--r-- | spec/ruby/library/cgi/cookie/initialize_spec.rb | 235 | ||||
-rw-r--r-- | spec/ruby/library/cgi/cookie/name_spec.rb | 33 | ||||
-rw-r--r-- | spec/ruby/library/cgi/cookie/parse_spec.rb | 41 | ||||
-rw-r--r-- | spec/ruby/library/cgi/cookie/path_spec.rb | 33 | ||||
-rw-r--r-- | spec/ruby/library/cgi/cookie/secure_spec.rb | 99 | ||||
-rw-r--r-- | spec/ruby/library/cgi/cookie/to_s_spec.rb | 51 | ||||
-rw-r--r-- | spec/ruby/library/cgi/cookie/value_spec.rb | 121 |
9 files changed, 353 insertions, 326 deletions
diff --git a/spec/ruby/library/cgi/cookie/domain_spec.rb b/spec/ruby/library/cgi/cookie/domain_spec.rb index 962609ebaf..622549039f 100644 --- a/spec/ruby/library/cgi/cookie/domain_spec.rb +++ b/spec/ruby/library/cgi/cookie/domain_spec.rb @@ -1,23 +1,26 @@ require_relative '../../../spec_helper' -require 'cgi' -describe "CGI::Cookie#domain" do - it "returns self's domain" do - cookie = CGI::Cookie.new("test-cookie") - cookie.domain.should be_nil +ruby_version_is ""..."3.5" do + require 'cgi' - cookie = CGI::Cookie.new("name" => "test-cookie", "domain" => "example.com") - cookie.domain.should == "example.com" + describe "CGI::Cookie#domain" do + it "returns self's domain" do + cookie = CGI::Cookie.new("test-cookie") + cookie.domain.should be_nil + + cookie = CGI::Cookie.new("name" => "test-cookie", "domain" => "example.com") + cookie.domain.should == "example.com" + end end -end -describe "CGI::Cookie#domain=" do - it "sets self's domain" do - cookie = CGI::Cookie.new("test-cookie") - cookie.domain = "test.com" - cookie.domain.should == "test.com" + describe "CGI::Cookie#domain=" do + it "sets self's domain" do + cookie = CGI::Cookie.new("test-cookie") + cookie.domain = "test.com" + cookie.domain.should == "test.com" - cookie.domain = "example.com" - cookie.domain.should == "example.com" + cookie.domain = "example.com" + cookie.domain.should == "example.com" + end end end diff --git a/spec/ruby/library/cgi/cookie/expires_spec.rb b/spec/ruby/library/cgi/cookie/expires_spec.rb index c8f26d01cd..df52a6f41e 100644 --- a/spec/ruby/library/cgi/cookie/expires_spec.rb +++ b/spec/ruby/library/cgi/cookie/expires_spec.rb @@ -1,23 +1,26 @@ require_relative '../../../spec_helper' -require 'cgi' -describe "CGI::Cookie#expires" do - it "returns self's expiration date" do - cookie = CGI::Cookie.new("test-cookie") - cookie.expires.should be_nil +ruby_version_is ""..."3.5" do + require 'cgi' - cookie = CGI::Cookie.new("name" => "test-cookie", "expires" => Time.at(1196524602)) - cookie.expires.should == Time.at(1196524602) + describe "CGI::Cookie#expires" do + it "returns self's expiration date" do + cookie = CGI::Cookie.new("test-cookie") + cookie.expires.should be_nil + + cookie = CGI::Cookie.new("name" => "test-cookie", "expires" => Time.at(1196524602)) + cookie.expires.should == Time.at(1196524602) + end end -end -describe "CGI::Cookie#expires=" do - it "sets self's expiration date" do - cookie = CGI::Cookie.new("test-cookie") - cookie.expires = Time.at(1196524602) - cookie.expires.should == Time.at(1196524602) + describe "CGI::Cookie#expires=" do + it "sets self's expiration date" do + cookie = CGI::Cookie.new("test-cookie") + cookie.expires = Time.at(1196524602) + cookie.expires.should == Time.at(1196524602) - cookie.expires = Time.at(1196525000) - cookie.expires.should == Time.at(1196525000) + cookie.expires = Time.at(1196525000) + cookie.expires.should == Time.at(1196525000) + end end end diff --git a/spec/ruby/library/cgi/cookie/initialize_spec.rb b/spec/ruby/library/cgi/cookie/initialize_spec.rb index 4b6e104b10..ac99d5e4fd 100644 --- a/spec/ruby/library/cgi/cookie/initialize_spec.rb +++ b/spec/ruby/library/cgi/cookie/initialize_spec.rb @@ -1,147 +1,150 @@ require_relative '../../../spec_helper' -require 'cgi' -describe "CGI::Cookie#initialize when passed String" do - before :each do - @cookie = CGI::Cookie.allocate - end - - it "sets the self's name to the passed String" do - @cookie.send(:initialize, "test-cookie") - @cookie.name.should == "test-cookie" - end +ruby_version_is ""..."3.5" do + require 'cgi' - it "sets the self's value to an empty Array" do - @cookie.send(:initialize, "test-cookie") - @cookie.value.should == [] - end - - it "sets self to a non-secure cookie" do - @cookie.send(:initialize, "test") - @cookie.secure.should be_false - end - - it "does set self's path to an empty String when ENV[\"SCRIPT_NAME\"] is not set" do - @cookie.send(:initialize, "test-cookie") - @cookie.path.should == "" - end - - it "does set self's path based on ENV[\"SCRIPT_NAME\"] when ENV[\"SCRIPT_NAME\"] is set" do - old_script_name = ENV["SCRIPT_NAME"] + describe "CGI::Cookie#initialize when passed String" do + before :each do + @cookie = CGI::Cookie.allocate + end - begin - ENV["SCRIPT_NAME"] = "some/path/script.rb" + it "sets the self's name to the passed String" do @cookie.send(:initialize, "test-cookie") - @cookie.path.should == "some/path/" + @cookie.name.should == "test-cookie" + end - ENV["SCRIPT_NAME"] = "script.rb" + it "sets the self's value to an empty Array" do @cookie.send(:initialize, "test-cookie") - @cookie.path.should == "" + @cookie.value.should == [] + end - ENV["SCRIPT_NAME"] = nil + it "sets self to a non-secure cookie" do + @cookie.send(:initialize, "test") + @cookie.secure.should be_false + end + + it "does set self's path to an empty String when ENV[\"SCRIPT_NAME\"] is not set" do @cookie.send(:initialize, "test-cookie") @cookie.path.should == "" - ensure - ENV["SCRIPT_NAME"] = old_script_name end - end - it "does not set self's expiration date" do - @cookie.expires.should be_nil - end + it "does set self's path based on ENV[\"SCRIPT_NAME\"] when ENV[\"SCRIPT_NAME\"] is set" do + old_script_name = ENV["SCRIPT_NAME"] - it "does not set self's domain" do - @cookie.domain.should be_nil - end -end + begin + ENV["SCRIPT_NAME"] = "some/path/script.rb" + @cookie.send(:initialize, "test-cookie") + @cookie.path.should == "some/path/" -describe "CGI::Cookie#initialize when passed Hash" do - before :each do - @cookie = CGI::Cookie.allocate - end + ENV["SCRIPT_NAME"] = "script.rb" + @cookie.send(:initialize, "test-cookie") + @cookie.path.should == "" + + ENV["SCRIPT_NAME"] = nil + @cookie.send(:initialize, "test-cookie") + @cookie.path.should == "" + ensure + ENV["SCRIPT_NAME"] = old_script_name + end + end + + it "does not set self's expiration date" do + @cookie.expires.should be_nil + end - it "sets self's contents based on the passed Hash" do - @cookie.send(:initialize, - 'name' => 'test-cookie', - 'value' => ["one", "two", "three"], - 'path' => 'some/path/', - 'domain' => 'example.com', - 'expires' => Time.at(1196524602), - 'secure' => true) - - @cookie.name.should == "test-cookie" - @cookie.value.should == ["one", "two", "three"] - @cookie.path.should == "some/path/" - @cookie.domain.should == "example.com" - @cookie.expires.should == Time.at(1196524602) - @cookie.secure.should be_true + it "does not set self's domain" do + @cookie.domain.should be_nil + end end - it "does set self's path based on ENV[\"SCRIPT_NAME\"] when the Hash has no 'path' entry" do - old_script_name = ENV["SCRIPT_NAME"] + describe "CGI::Cookie#initialize when passed Hash" do + before :each do + @cookie = CGI::Cookie.allocate + end - begin - ENV["SCRIPT_NAME"] = "some/path/script.rb" - @cookie.send(:initialize, 'name' => 'test-cookie') + it "sets self's contents based on the passed Hash" do + @cookie.send(:initialize, + 'name' => 'test-cookie', + 'value' => ["one", "two", "three"], + 'path' => 'some/path/', + 'domain' => 'example.com', + 'expires' => Time.at(1196524602), + 'secure' => true) + + @cookie.name.should == "test-cookie" + @cookie.value.should == ["one", "two", "three"] @cookie.path.should == "some/path/" + @cookie.domain.should == "example.com" + @cookie.expires.should == Time.at(1196524602) + @cookie.secure.should be_true + end - ENV["SCRIPT_NAME"] = "script.rb" - @cookie.send(:initialize, 'name' => 'test-cookie') - @cookie.path.should == "" + it "does set self's path based on ENV[\"SCRIPT_NAME\"] when the Hash has no 'path' entry" do + old_script_name = ENV["SCRIPT_NAME"] - ENV["SCRIPT_NAME"] = nil - @cookie.send(:initialize, 'name' => 'test-cookie') - @cookie.path.should == "" - ensure - ENV["SCRIPT_NAME"] = old_script_name + begin + ENV["SCRIPT_NAME"] = "some/path/script.rb" + @cookie.send(:initialize, 'name' => 'test-cookie') + @cookie.path.should == "some/path/" + + ENV["SCRIPT_NAME"] = "script.rb" + @cookie.send(:initialize, 'name' => 'test-cookie') + @cookie.path.should == "" + + ENV["SCRIPT_NAME"] = nil + @cookie.send(:initialize, 'name' => 'test-cookie') + @cookie.path.should == "" + ensure + ENV["SCRIPT_NAME"] = old_script_name + end end - end - it "tries to convert the Hash's 'value' to an Array using #Array" do - obj = mock("Converted To Array") - obj.should_receive(:to_ary).and_return(["1", "2", "3"]) - @cookie.send(:initialize, - 'name' => 'test-cookie', - 'value' => obj) - @cookie.value.should == [ "1", "2", "3" ] - - obj = mock("Converted To Array") - obj.should_receive(:to_a).and_return(["one", "two", "three"]) - @cookie.send(:initialize, - 'name' => 'test-cookie', - 'value' => obj) - @cookie.value.should == [ "one", "two", "three" ] - - obj = mock("Put into an Array") - @cookie.send(:initialize, - 'name' => 'test-cookie', - 'value' => obj) - @cookie.value.should == [ obj ] - end + it "tries to convert the Hash's 'value' to an Array using #Array" do + obj = mock("Converted To Array") + obj.should_receive(:to_ary).and_return(["1", "2", "3"]) + @cookie.send(:initialize, + 'name' => 'test-cookie', + 'value' => obj) + @cookie.value.should == [ "1", "2", "3" ] + + obj = mock("Converted To Array") + obj.should_receive(:to_a).and_return(["one", "two", "three"]) + @cookie.send(:initialize, + 'name' => 'test-cookie', + 'value' => obj) + @cookie.value.should == [ "one", "two", "three" ] + + obj = mock("Put into an Array") + @cookie.send(:initialize, + 'name' => 'test-cookie', + 'value' => obj) + @cookie.value.should == [ obj ] + end - it "raises a ArgumentError when the passed Hash has no 'name' entry" do - -> { @cookie.send(:initialize, {}) }.should raise_error(ArgumentError) - -> { @cookie.send(:initialize, "value" => "test") }.should raise_error(ArgumentError) + it "raises a ArgumentError when the passed Hash has no 'name' entry" do + -> { @cookie.send(:initialize, {}) }.should raise_error(ArgumentError) + -> { @cookie.send(:initialize, "value" => "test") }.should raise_error(ArgumentError) + end end -end -describe "CGI::Cookie#initialize when passed String, values ..." do - before :each do - @cookie = CGI::Cookie.allocate - end + describe "CGI::Cookie#initialize when passed String, values ..." do + before :each do + @cookie = CGI::Cookie.allocate + end - it "sets the self's name to the passed String" do - @cookie.send(:initialize, "test-cookie", "one", "two", "three") - @cookie.name.should == "test-cookie" - end + it "sets the self's name to the passed String" do + @cookie.send(:initialize, "test-cookie", "one", "two", "three") + @cookie.name.should == "test-cookie" + end - it "sets the self's value to an Array containing all passed values" do - @cookie.send(:initialize, "test-cookie", "one", "two", "three") - @cookie.value.should == ["one", "two", "three"] - end + it "sets the self's value to an Array containing all passed values" do + @cookie.send(:initialize, "test-cookie", "one", "two", "three") + @cookie.value.should == ["one", "two", "three"] + end - it "sets self to a non-secure cookie" do - @cookie.send(:initialize, "test", "one", "two", "three") - @cookie.secure.should be_false + it "sets self to a non-secure cookie" do + @cookie.send(:initialize, "test", "one", "two", "three") + @cookie.secure.should be_false + end end end diff --git a/spec/ruby/library/cgi/cookie/name_spec.rb b/spec/ruby/library/cgi/cookie/name_spec.rb index 326a43ade3..712628180b 100644 --- a/spec/ruby/library/cgi/cookie/name_spec.rb +++ b/spec/ruby/library/cgi/cookie/name_spec.rb @@ -1,23 +1,26 @@ require_relative '../../../spec_helper' -require 'cgi' -describe "CGI::Cookie#name" do - it "returns self's name" do - cookie = CGI::Cookie.new("test-cookie") - cookie.name.should == "test-cookie" +ruby_version_is ""..."3.5" do + require 'cgi' - cookie = CGI::Cookie.new("name" => "another-cookie") - cookie.name.should == "another-cookie" + describe "CGI::Cookie#name" do + it "returns self's name" do + cookie = CGI::Cookie.new("test-cookie") + cookie.name.should == "test-cookie" + + cookie = CGI::Cookie.new("name" => "another-cookie") + cookie.name.should == "another-cookie" + end end -end -describe "CGI::Cookie#name=" do - it "sets self's expiration date" do - cookie = CGI::Cookie.new("test-cookie") - cookie.name = "another-name" - cookie.name.should == "another-name" + describe "CGI::Cookie#name=" do + it "sets self's expiration date" do + cookie = CGI::Cookie.new("test-cookie") + cookie.name = "another-name" + cookie.name.should == "another-name" - cookie.name = "and-one-more" - cookie.name.should == "and-one-more" + cookie.name = "and-one-more" + cookie.name.should == "and-one-more" + end end end diff --git a/spec/ruby/library/cgi/cookie/parse_spec.rb b/spec/ruby/library/cgi/cookie/parse_spec.rb index d484c7bad9..ecc78d77dc 100644 --- a/spec/ruby/library/cgi/cookie/parse_spec.rb +++ b/spec/ruby/library/cgi/cookie/parse_spec.rb @@ -1,26 +1,29 @@ require_relative '../../../spec_helper' -require 'cgi' -describe "CGI::Cookie.parse" do - it "parses a raw cookie string into a hash of Cookies" do - expected = { "test-cookie" => ["one", "two", "three"] } - CGI::Cookie.parse("test-cookie=one&two&three").should == expected +ruby_version_is ""..."3.5" do + require 'cgi' - expected = { "second-cookie" => ["three", "four"], "first-cookie" => ["one", "two"] } - CGI::Cookie.parse("first-cookie=one&two;second-cookie=three&four").should == expected - end + describe "CGI::Cookie.parse" do + it "parses a raw cookie string into a hash of Cookies" do + expected = { "test-cookie" => ["one", "two", "three"] } + CGI::Cookie.parse("test-cookie=one&two&three").should == expected - it "does not use , for cookie separators" do - expected = { - "first-cookie" => ["one", "two"], - "second-cookie" => ["three", "four,third_cookie=five", "six"] - } - CGI::Cookie.parse("first-cookie=one&two;second-cookie=three&four,third_cookie=five&six").should == expected - end + expected = { "second-cookie" => ["three", "four"], "first-cookie" => ["one", "two"] } + CGI::Cookie.parse("first-cookie=one&two;second-cookie=three&four").should == expected + end + + it "does not use , for cookie separators" do + expected = { + "first-cookie" => ["one", "two"], + "second-cookie" => ["three", "four,third_cookie=five", "six"] + } + CGI::Cookie.parse("first-cookie=one&two;second-cookie=three&four,third_cookie=five&six").should == expected + end - it "unescapes the Cookie values" do - cookie = "test-cookie=+%21%22%23%24%25%26%27%28%29%2A%2B%2C-.%2F0123456789%3A%3B%3C%3D%3E%3F%40ABCDEFGHIJKLMNOPQRSTUVWXYZ%5B%5C%5D%5E_%60abcdefghijklmnopqrstuvwxyz%7B%7C%7D%7E" - expected = { "test-cookie" => [ " !\"\#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~" ] } - CGI::Cookie.parse(cookie).should == expected + it "unescapes the Cookie values" do + cookie = "test-cookie=+%21%22%23%24%25%26%27%28%29%2A%2B%2C-.%2F0123456789%3A%3B%3C%3D%3E%3F%40ABCDEFGHIJKLMNOPQRSTUVWXYZ%5B%5C%5D%5E_%60abcdefghijklmnopqrstuvwxyz%7B%7C%7D%7E" + expected = { "test-cookie" => [ " !\"\#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~" ] } + CGI::Cookie.parse(cookie).should == expected + end end end diff --git a/spec/ruby/library/cgi/cookie/path_spec.rb b/spec/ruby/library/cgi/cookie/path_spec.rb index 8a2f05aa50..010e87a6b8 100644 --- a/spec/ruby/library/cgi/cookie/path_spec.rb +++ b/spec/ruby/library/cgi/cookie/path_spec.rb @@ -1,23 +1,26 @@ require_relative '../../../spec_helper' -require 'cgi' -describe "CGI::Cookie#path" do - it "returns self's path" do - cookie = CGI::Cookie.new("test-cookie") - cookie.path.should == "" +ruby_version_is ""..."3.5" do + require 'cgi' - cookie = CGI::Cookie.new("name" => "test-cookie", "path" => "/some/path/") - cookie.path.should == "/some/path/" + describe "CGI::Cookie#path" do + it "returns self's path" do + cookie = CGI::Cookie.new("test-cookie") + cookie.path.should == "" + + cookie = CGI::Cookie.new("name" => "test-cookie", "path" => "/some/path/") + cookie.path.should == "/some/path/" + end end -end -describe "CGI::Cookie#path=" do - it "sets self's path" do - cookie = CGI::Cookie.new("test-cookie") - cookie.path = "/some/path/" - cookie.path.should == "/some/path/" + describe "CGI::Cookie#path=" do + it "sets self's path" do + cookie = CGI::Cookie.new("test-cookie") + cookie.path = "/some/path/" + cookie.path.should == "/some/path/" - cookie.path = "/another/path/" - cookie.path.should == "/another/path/" + cookie.path = "/another/path/" + cookie.path.should == "/another/path/" + end end end diff --git a/spec/ruby/library/cgi/cookie/secure_spec.rb b/spec/ruby/library/cgi/cookie/secure_spec.rb index 694bc2eeed..b526897250 100644 --- a/spec/ruby/library/cgi/cookie/secure_spec.rb +++ b/spec/ruby/library/cgi/cookie/secure_spec.rb @@ -1,70 +1,73 @@ require_relative '../../../spec_helper' -require 'cgi' -describe "CGI::Cookie#secure" do - before :each do - @cookie = CGI::Cookie.new("test-cookie") - end +ruby_version_is ""..."3.5" do + require 'cgi' - it "returns whether self is a secure cookie or not" do - @cookie.secure = true - @cookie.secure.should be_true + describe "CGI::Cookie#secure" do + before :each do + @cookie = CGI::Cookie.new("test-cookie") + end - @cookie.secure = false - @cookie.secure.should be_false - end -end + it "returns whether self is a secure cookie or not" do + @cookie.secure = true + @cookie.secure.should be_true -describe "CGI::Cookie#secure= when passed true" do - before :each do - @cookie = CGI::Cookie.new("test-cookie") + @cookie.secure = false + @cookie.secure.should be_false + end end - it "returns true" do - (@cookie.secure = true).should be_true - end + describe "CGI::Cookie#secure= when passed true" do + before :each do + @cookie = CGI::Cookie.new("test-cookie") + end - it "sets self to a secure cookie" do - @cookie.secure = true - @cookie.secure.should be_true - end -end + it "returns true" do + (@cookie.secure = true).should be_true + end -describe "CGI::Cookie#secure= when passed false" do - before :each do - @cookie = CGI::Cookie.new("test-cookie") + it "sets self to a secure cookie" do + @cookie.secure = true + @cookie.secure.should be_true + end end - it "returns false" do - (@cookie.secure = false).should be_false - end + describe "CGI::Cookie#secure= when passed false" do + before :each do + @cookie = CGI::Cookie.new("test-cookie") + end - it "sets self to a non-secure cookie" do - @cookie.secure = false - @cookie.secure.should be_false - end -end + it "returns false" do + (@cookie.secure = false).should be_false + end -describe "CGI::Cookie#secure= when passed Object" do - before :each do - @cookie = CGI::Cookie.new("test-cookie") + it "sets self to a non-secure cookie" do + @cookie.secure = false + @cookie.secure.should be_false + end end - it "does not change self's secure value" do - @cookie.secure = false + describe "CGI::Cookie#secure= when passed Object" do + before :each do + @cookie = CGI::Cookie.new("test-cookie") + end + + it "does not change self's secure value" do + @cookie.secure = false - @cookie.secure = Object.new - @cookie.secure.should be_false + @cookie.secure = Object.new + @cookie.secure.should be_false - @cookie.secure = "Test" - @cookie.secure.should be_false + @cookie.secure = "Test" + @cookie.secure.should be_false - @cookie.secure = true + @cookie.secure = true - @cookie.secure = Object.new - @cookie.secure.should be_true + @cookie.secure = Object.new + @cookie.secure.should be_true - @cookie.secure = "Test" - @cookie.secure.should be_true + @cookie.secure = "Test" + @cookie.secure.should be_true + end end end diff --git a/spec/ruby/library/cgi/cookie/to_s_spec.rb b/spec/ruby/library/cgi/cookie/to_s_spec.rb index da15e6ed2a..34326f672b 100644 --- a/spec/ruby/library/cgi/cookie/to_s_spec.rb +++ b/spec/ruby/library/cgi/cookie/to_s_spec.rb @@ -1,33 +1,36 @@ require_relative '../../../spec_helper' -require 'cgi' -describe "CGI::Cookie#to_s" do - it "returns a String representation of self" do - cookie = CGI::Cookie.new("test-cookie") - cookie.to_s.should == "test-cookie=; path=" +ruby_version_is ""..."3.5" do + require 'cgi' - cookie = CGI::Cookie.new("test-cookie", "value") - cookie.to_s.should == "test-cookie=value; path=" + describe "CGI::Cookie#to_s" do + it "returns a String representation of self" do + cookie = CGI::Cookie.new("test-cookie") + cookie.to_s.should == "test-cookie=; path=" - cookie = CGI::Cookie.new("test-cookie", "one", "two", "three") - cookie.to_s.should == "test-cookie=one&two&three; path=" + cookie = CGI::Cookie.new("test-cookie", "value") + cookie.to_s.should == "test-cookie=value; path=" - cookie = CGI::Cookie.new( - 'name' => 'test-cookie', - 'value' => ["one", "two", "three"], - 'path' => 'some/path/', - 'domain' => 'example.com', - 'expires' => Time.at(1196524602), - 'secure' => true) - cookie.to_s.should == "test-cookie=one&two&three; domain=example.com; path=some/path/; expires=Sat, 01 Dec 2007 15:56:42 GMT; secure" - end + cookie = CGI::Cookie.new("test-cookie", "one", "two", "three") + cookie.to_s.should == "test-cookie=one&two&three; path=" - it "escapes the self's values" do - cookie = CGI::Cookie.new("test-cookie", " !\"\#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}") - cookie.to_s.should == "test-cookie=+%21%22%23%24%25%26%27%28%29%2A%2B%2C-.%2F0123456789%3A%3B%3C%3D%3E%3F%40ABCDEFGHIJKLMNOPQRSTUVWXYZ%5B%5C%5D%5E_%60abcdefghijklmnopqrstuvwxyz%7B%7C%7D; path=" - end + cookie = CGI::Cookie.new( + 'name' => 'test-cookie', + 'value' => ["one", "two", "three"], + 'path' => 'some/path/', + 'domain' => 'example.com', + 'expires' => Time.at(1196524602), + 'secure' => true) + cookie.to_s.should == "test-cookie=one&two&three; domain=example.com; path=some/path/; expires=Sat, 01 Dec 2007 15:56:42 GMT; secure" + end + + it "escapes the self's values" do + cookie = CGI::Cookie.new("test-cookie", " !\"\#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}") + cookie.to_s.should == "test-cookie=+%21%22%23%24%25%26%27%28%29%2A%2B%2C-.%2F0123456789%3A%3B%3C%3D%3E%3F%40ABCDEFGHIJKLMNOPQRSTUVWXYZ%5B%5C%5D%5E_%60abcdefghijklmnopqrstuvwxyz%7B%7C%7D; path=" + end - it "does not escape tilde" do - cookie = CGI::Cookie.new("test-cookie", "~").to_s.should == "test-cookie=~; path=" + it "does not escape tilde" do + cookie = CGI::Cookie.new("test-cookie", "~").to_s.should == "test-cookie=~; path=" + end end end diff --git a/spec/ruby/library/cgi/cookie/value_spec.rb b/spec/ruby/library/cgi/cookie/value_spec.rb index 1d5da3a3ac..e7c91b55b9 100644 --- a/spec/ruby/library/cgi/cookie/value_spec.rb +++ b/spec/ruby/library/cgi/cookie/value_spec.rb @@ -1,76 +1,79 @@ require_relative '../../../spec_helper' -require 'cgi' -describe "CGI::Cookie#value" do - it "returns self's value" do - cookie = CGI::Cookie.new("test-cookie") - cookie.value.should == [] +ruby_version_is ""..."3.5" do + require 'cgi' - cookie = CGI::Cookie.new("test-cookie", "one") - cookie.value.should == ["one"] + describe "CGI::Cookie#value" do + it "returns self's value" do + cookie = CGI::Cookie.new("test-cookie") + cookie.value.should == [] - cookie = CGI::Cookie.new("test-cookie", "one", "two", "three") - cookie.value.should == ["one", "two", "three"] + cookie = CGI::Cookie.new("test-cookie", "one") + cookie.value.should == ["one"] - cookie = CGI::Cookie.new("name" => "test-cookie", "value" => ["one", "two", "three"]) - cookie.value.should == ["one", "two", "three"] - end + cookie = CGI::Cookie.new("test-cookie", "one", "two", "three") + cookie.value.should == ["one", "two", "three"] - it "is in synch with self" do - fail = [] - [ - :pop, - :shift, - [:<<, "Hello"], - [:push, "Hello"], - [:unshift, "World"], - [:replace, ["A", "B"]], - [:[]=, 1, "Set"], - [:delete, "first"], - [:delete_at, 0], - ].each do |method, *args| - cookie1 = CGI::Cookie.new("test-cookie", "first", "second") - cookie2 = CGI::Cookie.new("test-cookie", "first", "second") - cookie1.send(method, *args) - cookie2.value.send(method, *args) - fail << method unless cookie1.value == cookie2.value + cookie = CGI::Cookie.new("name" => "test-cookie", "value" => ["one", "two", "three"]) + cookie.value.should == ["one", "two", "three"] end - fail.should be_empty - end -end -describe "CGI::Cookie#value=" do - before :each do - @cookie = CGI::Cookie.new("test-cookie") + it "is in synch with self" do + fail = [] + [ + :pop, + :shift, + [:<<, "Hello"], + [:push, "Hello"], + [:unshift, "World"], + [:replace, ["A", "B"]], + [:[]=, 1, "Set"], + [:delete, "first"], + [:delete_at, 0], + ].each do |method, *args| + cookie1 = CGI::Cookie.new("test-cookie", "first", "second") + cookie2 = CGI::Cookie.new("test-cookie", "first", "second") + cookie1.send(method, *args) + cookie2.value.send(method, *args) + fail << method unless cookie1.value == cookie2.value + end + fail.should be_empty + end end - it "sets self's value" do - @cookie.value = ["one"] - @cookie.value.should == ["one"] + describe "CGI::Cookie#value=" do + before :each do + @cookie = CGI::Cookie.new("test-cookie") + end - @cookie.value = ["one", "two", "three"] - @cookie.value.should == ["one", "two", "three"] - end + it "sets self's value" do + @cookie.value = ["one"] + @cookie.value.should == ["one"] - it "automatically converts the passed Object to an Array using #Array" do - @cookie.value = "test" - @cookie.value.should == ["test"] + @cookie.value = ["one", "two", "three"] + @cookie.value.should == ["one", "two", "three"] + end - obj = mock("to_a") - obj.should_receive(:to_a).and_return(["1", "2"]) - @cookie.value = obj - @cookie.value.should == ["1", "2"] + it "automatically converts the passed Object to an Array using #Array" do + @cookie.value = "test" + @cookie.value.should == ["test"] - obj = mock("to_ary") - obj.should_receive(:to_ary).and_return(["1", "2"]) - @cookie.value = obj - @cookie.value.should == ["1", "2"] - end + obj = mock("to_a") + obj.should_receive(:to_a).and_return(["1", "2"]) + @cookie.value = obj + @cookie.value.should == ["1", "2"] - it "does keep self and the values in sync" do - @cookie.value = ["one", "two", "three"] - @cookie[0].should == "one" - @cookie[1].should == "two" - @cookie[2].should == "three" + obj = mock("to_ary") + obj.should_receive(:to_ary).and_return(["1", "2"]) + @cookie.value = obj + @cookie.value.should == ["1", "2"] + end + + it "does keep self and the values in sync" do + @cookie.value = ["one", "two", "three"] + @cookie[0].should == "one" + @cookie[1].should == "two" + @cookie[2].should == "three" + end end end |