File: header_spec.rb

package info (click to toggle)
dlr-languages 20090805%2Bgit.e6b28d27%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 51,484 kB
  • ctags: 59,257
  • sloc: cs: 298,829; ruby: 159,643; xml: 19,872; python: 2,820; yacc: 1,960; makefile: 96; sh: 65
file content (110 lines) | stat: -rw-r--r-- 4,085 bytes parent folder | download
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
require File.dirname(__FILE__) + '/../../spec_helper'
require 'cgi'

describe "CGI#header when passed no arguments" do
  before(:each) do
    ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
    @cgi = CGI.new
  end
  
  after(:each) do
    ENV['REQUEST_METHOD'] = @old_request_method
  end

  
  it "returns a HTML header specifiying the Content-Type as text/html" do
    @cgi.header.should == "Content-Type: text/html\r\n\r\n"
  end

  it "includes Cookies in the @output_cookies field" do
    @cgi.instance_variable_set(:@output_cookies, ["multiple", "cookies"])
    @cgi.header.should == "Content-Type: text/html\r\nSet-Cookie: multiple\r\nSet-Cookie: cookies\r\n\r\n" 
  end
end

describe "CGI#header when passed String" do
  before(:each) do
    ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
    @cgi = CGI.new
  end
  
  after(:each) do
    ENV['REQUEST_METHOD'] = @old_request_method
  end

  
  it "returns a HTML header specifiying the Content-Type as the passed String's content" do
    @cgi.header("text/plain").should == "Content-Type: text/plain\r\n\r\n"
  end

  it "includes Cookies in the @output_cookies field" do
    @cgi.instance_variable_set(:@output_cookies, ["multiple", "cookies"])
    @cgi.header("text/plain").should == "Content-Type: text/plain\r\nSet-Cookie: multiple\r\nSet-Cookie: cookies\r\n\r\n" 
  end
end

describe "CGI#header when passed Hash" do
  before(:each) do
    ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
    @cgi = CGI.new
  end
  
  after(:each) do
    ENV['REQUEST_METHOD'] = @old_request_method
  end


  it "returns a HTML header based on the Hash's key/value pairs" do
    header = @cgi.header("type" => "text/plain")
    header.should == "Content-Type: text/plain\r\n\r\n"
    
    header = @cgi.header("type" => "text/plain", "charset" => "UTF-8")
    header.should == "Content-Type: text/plain; charset=UTF-8\r\n\r\n"
    
    header = @cgi.header("nph" => true)
    header.should include("HTTP/1.0 200 OK\r\n")
    header.should include("Date: ")
    header.should include("Server: ")
    header.should include("Connection: close\r\n")
    header.should include("Content-Type: text/html\r\n")
    
    header = @cgi.header("status" => "OK")
    header.should == "Status: 200 OK\r\nContent-Type: text/html\r\n\r\n"

    header = @cgi.header("status" => "PARTIAL_CONTENT")
    header.should == "Status: 206 Partial Content\r\nContent-Type: text/html\r\n\r\n"

    header = @cgi.header("status" => "MULTIPLE_CHOICES")
    header.should == "Status: 300 Multiple Choices\r\nContent-Type: text/html\r\n\r\n"
  
    header = @cgi.header("server" => "Server Software used")
    header.should == "Server: Server Software used\r\nContent-Type: text/html\r\n\r\n"
  
    header = @cgi.header("connection" => "connection type")
    header.should == "Connection: connection type\r\nContent-Type: text/html\r\n\r\n"
  
    header = @cgi.header("length" => 103)
    header.should == "Content-Type: text/html\r\nContent-Length: 103\r\n\r\n"

    header = @cgi.header("language" => "ja")
    header.should == "Content-Type: text/html\r\nContent-Language: ja\r\n\r\n"

    header = @cgi.header("expires" => Time.at(0))
    header.should == "Content-Type: text/html\r\nExpires: Thu, 01 Jan 1970 00:00:00 GMT\r\n\r\n"

    header = @cgi.header("cookie" => "my cookie's content")
    header.should == "Content-Type: text/html\r\nSet-Cookie: my cookie's content\r\n\r\n"

    header = @cgi.header("cookie" => ["multiple", "cookies"])
    header.should == "Content-Type: text/html\r\nSet-Cookie: multiple\r\nSet-Cookie: cookies\r\n\r\n"
  end
  
  it "includes Cookies in the @output_cookies field" do
    @cgi.instance_variable_set(:@output_cookies, ["multiple", "cookies"])
    @cgi.header({}).should == "Content-Type: text/html\r\nSet-Cookie: multiple\r\nSet-Cookie: cookies\r\n\r\n" 
  end
  
  it "returns a HTML header specifiying the Content-Type as text/html when passed an empty Hash" do
    @cgi.header({}).should == "Content-Type: text/html\r\n\r\n"
  end
end