File: to_s_spec.rb

package info (click to toggle)
ruby3.3 3.3.8-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 153,620 kB
  • sloc: ruby: 1,244,308; ansic: 836,474; yacc: 28,074; pascal: 6,748; sh: 3,913; python: 1,719; cpp: 1,158; makefile: 742; asm: 712; javascript: 394; lisp: 97; perl: 62; awk: 36; sed: 23; xml: 4
file content (33 lines) | stat: -rw-r--r-- 1,365 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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="

    cookie = CGI::Cookie.new("test-cookie", "value")
    cookie.to_s.should == "test-cookie=value; path="

    cookie = CGI::Cookie.new("test-cookie", "one", "two", "three")
    cookie.to_s.should == "test-cookie=one&two&three; 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

  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="
  end
end