rubysl-cgi 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +18 -0
  3. data/.travis.yml +8 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE +25 -0
  6. data/README.md +29 -0
  7. data/Rakefile +2 -0
  8. data/lib/cgi.rb +1 -0
  9. data/lib/rubysl/cgi.rb +2 -0
  10. data/lib/rubysl/cgi/cgi.rb +2333 -0
  11. data/lib/rubysl/cgi/version.rb +5 -0
  12. data/rubysl-cgi.gemspec +23 -0
  13. data/spec/cookie/domain_spec.rb +22 -0
  14. data/spec/cookie/expires_spec.rb +22 -0
  15. data/spec/cookie/initialize_spec.rb +146 -0
  16. data/spec/cookie/name_spec.rb +22 -0
  17. data/spec/cookie/parse_spec.rb +17 -0
  18. data/spec/cookie/path_spec.rb +22 -0
  19. data/spec/cookie/secure_spec.rb +69 -0
  20. data/spec/cookie/to_s_spec.rb +28 -0
  21. data/spec/cookie/value_spec.rb +79 -0
  22. data/spec/escapeElement_spec.rb +19 -0
  23. data/spec/escapeHTML_spec.rb +25 -0
  24. data/spec/escape_spec.rb +13 -0
  25. data/spec/header_spec.rb +7 -0
  26. data/spec/htmlextension/a_spec.rb +48 -0
  27. data/spec/htmlextension/base_spec.rb +32 -0
  28. data/spec/htmlextension/blockquote_spec.rb +32 -0
  29. data/spec/htmlextension/br_spec.rb +21 -0
  30. data/spec/htmlextension/caption_spec.rb +32 -0
  31. data/spec/htmlextension/checkbox_group_spec.rb +77 -0
  32. data/spec/htmlextension/checkbox_spec.rb +76 -0
  33. data/spec/htmlextension/doctype_spec.rb +26 -0
  34. data/spec/htmlextension/file_field_spec.rb +73 -0
  35. data/spec/htmlextension/fixtures/common.rb +16 -0
  36. data/spec/htmlextension/form_spec.rb +57 -0
  37. data/spec/htmlextension/frame_spec.rb +13 -0
  38. data/spec/htmlextension/frameset_spec.rb +13 -0
  39. data/spec/htmlextension/hidden_spec.rb +58 -0
  40. data/spec/htmlextension/html_spec.rb +65 -0
  41. data/spec/htmlextension/image_button_spec.rb +68 -0
  42. data/spec/htmlextension/img_spec.rb +84 -0
  43. data/spec/htmlextension/multipart_form_spec.rb +63 -0
  44. data/spec/htmlextension/password_field_spec.rb +83 -0
  45. data/spec/htmlextension/popup_menu_spec.rb +7 -0
  46. data/spec/htmlextension/radio_button_spec.rb +76 -0
  47. data/spec/htmlextension/radio_group_spec.rb +78 -0
  48. data/spec/htmlextension/reset_spec.rb +56 -0
  49. data/spec/htmlextension/scrolling_list_spec.rb +7 -0
  50. data/spec/htmlextension/shared/popup_menu.rb +94 -0
  51. data/spec/htmlextension/submit_spec.rb +56 -0
  52. data/spec/htmlextension/text_field_spec.rb +83 -0
  53. data/spec/htmlextension/textarea_spec.rb +72 -0
  54. data/spec/http_header_spec.rb +9 -0
  55. data/spec/initialize_spec.rb +171 -0
  56. data/spec/out_spec.rb +50 -0
  57. data/spec/parse_spec.rb +23 -0
  58. data/spec/pretty_spec.rb +23 -0
  59. data/spec/print_spec.rb +25 -0
  60. data/spec/queryextension/accept_charset_spec.rb +21 -0
  61. data/spec/queryextension/accept_encoding_spec.rb +21 -0
  62. data/spec/queryextension/accept_language_spec.rb +21 -0
  63. data/spec/queryextension/accept_spec.rb +21 -0
  64. data/spec/queryextension/auth_type_spec.rb +21 -0
  65. data/spec/queryextension/cache_control_spec.rb +21 -0
  66. data/spec/queryextension/content_length_spec.rb +25 -0
  67. data/spec/queryextension/content_type_spec.rb +21 -0
  68. data/spec/queryextension/cookies_spec.rb +9 -0
  69. data/spec/queryextension/element_reference_spec.rb +33 -0
  70. data/spec/queryextension/from_spec.rb +21 -0
  71. data/spec/queryextension/gateway_interface_spec.rb +21 -0
  72. data/spec/queryextension/has_key_spec.rb +6 -0
  73. data/spec/queryextension/host_spec.rb +21 -0
  74. data/spec/queryextension/include_spec.rb +6 -0
  75. data/spec/queryextension/key_spec.rb +6 -0
  76. data/spec/queryextension/keys_spec.rb +19 -0
  77. data/spec/queryextension/multipart_spec.rb +39 -0
  78. data/spec/queryextension/negotiate_spec.rb +21 -0
  79. data/spec/queryextension/params_spec.rb +44 -0
  80. data/spec/queryextension/path_info_spec.rb +21 -0
  81. data/spec/queryextension/path_translated_spec.rb +21 -0
  82. data/spec/queryextension/pragma_spec.rb +21 -0
  83. data/spec/queryextension/query_string_spec.rb +21 -0
  84. data/spec/queryextension/raw_cookie2_spec.rb +21 -0
  85. data/spec/queryextension/raw_cookie_spec.rb +21 -0
  86. data/spec/queryextension/referer_spec.rb +21 -0
  87. data/spec/queryextension/remote_addr_spec.rb +21 -0
  88. data/spec/queryextension/remote_host_spec.rb +21 -0
  89. data/spec/queryextension/remote_ident_spec.rb +21 -0
  90. data/spec/queryextension/remote_user_spec.rb +21 -0
  91. data/spec/queryextension/request_method_spec.rb +21 -0
  92. data/spec/queryextension/script_name_spec.rb +21 -0
  93. data/spec/queryextension/server_name_spec.rb +21 -0
  94. data/spec/queryextension/server_port_spec.rb +25 -0
  95. data/spec/queryextension/server_protocol_spec.rb +21 -0
  96. data/spec/queryextension/server_software_spec.rb +21 -0
  97. data/spec/queryextension/shared/has_key.rb +19 -0
  98. data/spec/queryextension/user_agent_spec.rb +21 -0
  99. data/spec/rfc1123_date_spec.rb +9 -0
  100. data/spec/shared/http_header.rb +111 -0
  101. data/spec/unescapeElement_spec.rb +19 -0
  102. data/spec/unescapeHTML_spec.rb +33 -0
  103. data/spec/unescape_spec.rb +14 -0
  104. metadata +293 -0
@@ -0,0 +1,83 @@
1
+ require 'cgi'
2
+ require File.expand_path('../fixtures/common', __FILE__)
3
+
4
+ describe "CGI::HtmlExtension#text_field" do
5
+ before(:each) do
6
+ @html = CGISpecs.cgi_new
7
+ end
8
+
9
+ describe "when passed no arguments" do
10
+ it "returns an text-'input'-element without a name" do
11
+ output = @html.text_field
12
+ output.should equal_element("INPUT", {"NAME" => "", "TYPE" => "text", "SIZE" => "40"}, "", :not_closed => true)
13
+ end
14
+
15
+ it "ignores a passed block" do
16
+ output = @html.text_field { "test" }
17
+ output.should equal_element("INPUT", {"NAME" => "", "TYPE" => "text", "SIZE" => "40"}, "", :not_closed => true)
18
+ end
19
+ end
20
+
21
+ describe "when passed name" do
22
+ it "returns an text-'input'-element with the passed name" do
23
+ output = @html.text_field("test")
24
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "text", "SIZE" => "40"}, "", :not_closed => true)
25
+ end
26
+
27
+ it "ignores a passed block" do
28
+ output = @html.text_field("test") { "test" }
29
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "text", "SIZE" => "40"}, "", :not_closed => true)
30
+ end
31
+ end
32
+
33
+ describe "when passed name, value" do
34
+ it "returns an text-'input'-element with the passed name and value" do
35
+ output = @html.text_field("test", "some value")
36
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "text", "VALUE" => "some value", "SIZE" => "40"}, "", :not_closed => true)
37
+ end
38
+
39
+ it "ignores a passed block" do
40
+ output = @html.text_field("test", "some value") { "test" }
41
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "text", "VALUE" => "some value", "SIZE" => "40"}, "", :not_closed => true)
42
+ end
43
+ end
44
+
45
+ describe "when passed name, value, size" do
46
+ it "returns an text-'input'-element with the passed name, value and size" do
47
+ output = @html.text_field("test", "some value", 60)
48
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "text", "VALUE" => "some value", "SIZE" => "60"}, "", :not_closed => true)
49
+ end
50
+
51
+ it "ignores a passed block" do
52
+ output = @html.text_field("test", "some value", 60) { "test" }
53
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "text", "VALUE" => "some value", "SIZE" => "60"}, "", :not_closed => true)
54
+ end
55
+ end
56
+
57
+ describe "when passed name, value, size, maxlength" do
58
+ it "returns an text-'input'-element with the passed name, value, size and maxlength" do
59
+ output = @html.text_field("test", "some value", 60, 12)
60
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "text", "VALUE" => "some value", "SIZE" => "60", "MAXLENGTH" => 12}, "", :not_closed => true)
61
+ end
62
+
63
+ it "ignores a passed block" do
64
+ output = @html.text_field("test", "some value", 60, 12) { "test" }
65
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "text", "VALUE" => "some value", "SIZE" => "60", "MAXLENGTH" => 12}, "", :not_closed => true)
66
+ end
67
+ end
68
+
69
+ describe "when passed Hash" do
70
+ it "returns a checkbox-'input'-element using the passed Hash for attributes" do
71
+ output = @html.text_field("NAME" => "test", "VALUE" => "some value")
72
+ output.should equal_element("INPUT", { "NAME" => "test", "VALUE" => "some value", "TYPE" => "text" }, "", :not_closed => true)
73
+
74
+ output = @html.text_field("TYPE" => "hidden")
75
+ output.should equal_element("INPUT", {"TYPE" => "text"}, "", :not_closed => true)
76
+ end
77
+
78
+ it "ignores a passed block" do
79
+ output = @html.text_field("NAME" => "test", "VALUE" => "some value") { "test" }
80
+ output.should equal_element("INPUT", { "NAME" => "test", "VALUE" => "some value", "TYPE" => "text" }, "", :not_closed => true)
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,72 @@
1
+ require 'cgi'
2
+ require File.expand_path('../fixtures/common', __FILE__)
3
+
4
+ describe "CGI::HtmlExtension#textarea" do
5
+ before(:each) do
6
+ @html = CGISpecs.cgi_new
7
+ end
8
+
9
+ describe "when passed no arguments" do
10
+ it "returns an 'textarea'-element without a name" do
11
+ output = @html.textarea
12
+ output.should equal_element("TEXTAREA", {"NAME" => "", "COLS" => "70", "ROWS" => "10"}, "")
13
+ end
14
+
15
+ it "includes the return value of the passed block when passed a block" do
16
+ output = @html.textarea { "Example" }
17
+ output.should equal_element("TEXTAREA", {"NAME" => "", "COLS" => "70", "ROWS" => "10"}, "Example")
18
+ end
19
+ end
20
+
21
+ describe "when passed name" do
22
+ it "returns an 'textarea'-element with the passed name" do
23
+ output = @html.textarea("test")
24
+ output.should equal_element("TEXTAREA", {"NAME" => "test", "COLS" => "70", "ROWS" => "10"}, "")
25
+ end
26
+
27
+ it "includes the return value of the passed block when passed a block" do
28
+ output = @html.textarea("test") { "Example" }
29
+ output.should equal_element("TEXTAREA", {"NAME" => "test", "COLS" => "70", "ROWS" => "10"}, "Example")
30
+ end
31
+ end
32
+
33
+ describe "when passed name, cols" do
34
+ it "returns an 'textarea'-element with the passed name and the passed amount of columns" do
35
+ output = @html.textarea("test", 40)
36
+ output.should equal_element("TEXTAREA", {"NAME" => "test", "COLS" => "40", "ROWS" => "10"}, "")
37
+ end
38
+
39
+ it "includes the return value of the passed block when passed a block" do
40
+ output = @html.textarea("test", 40) { "Example" }
41
+ output.should equal_element("TEXTAREA", {"NAME" => "test", "COLS" => "40", "ROWS" => "10"}, "Example")
42
+ end
43
+ end
44
+
45
+ describe "when passed name, cols, rows" do
46
+ it "returns an 'textarea'-element with the passed name, the passed amount of columns and the passed number of rows" do
47
+ output = @html.textarea("test", 40, 5)
48
+ output.should equal_element("TEXTAREA", {"NAME" => "test", "COLS" => "40", "ROWS" => "5"}, "")
49
+ end
50
+
51
+ it "includes the return value of the passed block when passed a block" do
52
+ output = @html.textarea("test", 40, 5) { "Example" }
53
+ output.should equal_element("TEXTAREA", {"NAME" => "test", "COLS" => "40", "ROWS" => "5"}, "Example")
54
+ end
55
+ end
56
+
57
+ describe "when passed Hash" do
58
+ it "uses the passed Hash as attributes" do
59
+ @html.textarea("ID" => "test").should == '<TEXTAREA ID="test"></TEXTAREA>'
60
+
61
+ attributes = {"ID" => "test-id", "NAME" => "test-name"}
62
+ output = @html.textarea(attributes)
63
+ output.should equal_element("TEXTAREA", attributes, "")
64
+ end
65
+
66
+ it "includes the return value of the passed block when passed a block" do
67
+ attributes = {"ID" => "test-id", "NAME" => "test-name"}
68
+ output = @html.textarea(attributes) { "test" }
69
+ output.should equal_element("TEXTAREA", attributes, "test")
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,9 @@
1
+ require 'cgi'
2
+
3
+ require File.expand_path('../shared/http_header', __FILE__)
4
+
5
+ ruby_version_is '2.0' do
6
+ describe "CGI#http_header" do
7
+ it_behaves_like(:cgi_http_header, :http_header)
8
+ end
9
+ end
@@ -0,0 +1,171 @@
1
+ require 'cgi'
2
+
3
+ describe "CGI#initialize" do
4
+ it "is private" do
5
+ CGI.should have_private_instance_method(:initialize)
6
+ end
7
+ end
8
+
9
+ describe "CGI#initialize when passed no arguments" do
10
+ before(:each) do
11
+ ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
12
+ @cgi = CGI.allocate
13
+ end
14
+
15
+ after(:each) do
16
+ ENV['REQUEST_METHOD'] = @old_request_method
17
+ end
18
+
19
+ it "extends self with CGI::QueryExtension" do
20
+ @cgi.send(:initialize)
21
+ @cgi.should be_kind_of(CGI::QueryExtension)
22
+ end
23
+
24
+ it "does not extend self with CGI::HtmlExtension" do
25
+ @cgi.send(:initialize)
26
+ @cgi.should_not be_kind_of(CGI::HtmlExtension)
27
+ end
28
+
29
+ it "does not extend self with any of the other HTML modules" do
30
+ @cgi.send(:initialize)
31
+ @cgi.should_not be_kind_of(CGI::Html3)
32
+ @cgi.should_not be_kind_of(CGI::HtmlExtension)
33
+ @cgi.should_not be_kind_of(CGI::Html4)
34
+ @cgi.should_not be_kind_of(CGI::Html4Tr)
35
+ @cgi.should_not be_kind_of(CGI::Html4Fr)
36
+ end
37
+
38
+ it "sets #cookies based on ENV['HTTP_COOKIE']" do
39
+ begin
40
+ old_env, ENV["HTTP_COOKIE"] = ENV["HTTP_COOKIE"], "test=test yay"
41
+ @cgi.send(:initialize)
42
+ @cgi.cookies.should == { "test"=>[ "test yay" ] }
43
+ ensure
44
+ ENV["HTTP_COOKIE"] = old_env
45
+ end
46
+ end
47
+
48
+ it "sets #params based on ENV['QUERY_STRING'] when ENV['REQUEST_METHOD'] is GET" do
49
+ begin
50
+ old_env_query, ENV["QUERY_STRING"] = ENV["QUERY_STRING"], "?test=a&test2=b"
51
+ old_env_method, ENV["REQUEST_METHOD"] = ENV["REQUEST_METHOD"], "GET"
52
+ @cgi.send(:initialize)
53
+ @cgi.params.should == { "test2" => ["b"], "?test" => ["a"] }
54
+ ensure
55
+ ENV["QUERY_STRING"] = old_env_query
56
+ ENV["REQUEST_METHOD"] = old_env_method
57
+ end
58
+ end
59
+
60
+ it "sets #params based on ENV['QUERY_STRING'] when ENV['REQUEST_METHOD'] is HEAD" do
61
+ begin
62
+ old_env_query, ENV["QUERY_STRING"] = ENV["QUERY_STRING"], "?test=a&test2=b"
63
+ old_env_method, ENV["REQUEST_METHOD"] = ENV["REQUEST_METHOD"], "HEAD"
64
+ @cgi.send(:initialize)
65
+ @cgi.params.should == { "test2" => ["b"], "?test" => ["a"] }
66
+ ensure
67
+ ENV["QUERY_STRING"] = old_env_query
68
+ ENV["REQUEST_METHOD"] = old_env_method
69
+ end
70
+ end
71
+ end
72
+
73
+ describe "CGI#initialize when passed type" do
74
+ before(:each) do
75
+ ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
76
+ @cgi = CGI.allocate
77
+ end
78
+
79
+ after(:each) do
80
+ ENV['REQUEST_METHOD'] = @old_request_method
81
+ end
82
+
83
+
84
+ it "extends self with CGI::QueryExtension" do
85
+ @cgi.send(:initialize, "test")
86
+ @cgi.should be_kind_of(CGI::QueryExtension)
87
+ end
88
+
89
+ it "extends self with CGI::QueryExtension, CGI::Html3 and CGI::HtmlExtension when the passed type is 'html3'" do
90
+ @cgi.send(:initialize, "html3")
91
+ @cgi.should be_kind_of(CGI::Html3)
92
+ @cgi.should be_kind_of(CGI::HtmlExtension)
93
+ @cgi.should be_kind_of(CGI::QueryExtension)
94
+
95
+ @cgi.should_not be_kind_of(CGI::Html4)
96
+ @cgi.should_not be_kind_of(CGI::Html4Tr)
97
+ @cgi.should_not be_kind_of(CGI::Html4Fr)
98
+ end
99
+
100
+ it "extends self with CGI::QueryExtension, CGI::Html4 and CGI::HtmlExtension when the passed type is 'html4'" do
101
+ @cgi.send(:initialize, "html4")
102
+ @cgi.should be_kind_of(CGI::Html4)
103
+ @cgi.should be_kind_of(CGI::HtmlExtension)
104
+ @cgi.should be_kind_of(CGI::QueryExtension)
105
+
106
+ @cgi.should_not be_kind_of(CGI::Html3)
107
+ @cgi.should_not be_kind_of(CGI::Html4Tr)
108
+ @cgi.should_not be_kind_of(CGI::Html4Fr)
109
+ end
110
+
111
+ it "extends self with CGI::QueryExtension, CGI::Html4Tr and CGI::HtmlExtension when the passed type is 'html4Tr'" do
112
+ @cgi.send(:initialize, "html4Tr")
113
+ @cgi.should be_kind_of(CGI::Html4Tr)
114
+ @cgi.should be_kind_of(CGI::HtmlExtension)
115
+ @cgi.should be_kind_of(CGI::QueryExtension)
116
+
117
+ @cgi.should_not be_kind_of(CGI::Html3)
118
+ @cgi.should_not be_kind_of(CGI::Html4)
119
+ @cgi.should_not be_kind_of(CGI::Html4Fr)
120
+ end
121
+
122
+ it "extends self with CGI::QueryExtension, CGI::Html4Tr, CGI::Html4Fr and CGI::HtmlExtension when the passed type is 'html4Fr'" do
123
+ @cgi.send(:initialize, "html4Fr")
124
+ @cgi.should be_kind_of(CGI::Html4Tr)
125
+ @cgi.should be_kind_of(CGI::Html4Fr)
126
+ @cgi.should be_kind_of(CGI::HtmlExtension)
127
+ @cgi.should be_kind_of(CGI::QueryExtension)
128
+
129
+ @cgi.should_not be_kind_of(CGI::Html3)
130
+ @cgi.should_not be_kind_of(CGI::Html4)
131
+ end
132
+ end
133
+
134
+ describe "CGI#initialize when CGI_PARAMS is set" do
135
+ before(:each) do
136
+ ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
137
+ @cgi = CGI.allocate
138
+ end
139
+
140
+ after(:each) do
141
+ ENV['REQUEST_METHOD'] = @old_request_method
142
+ end
143
+
144
+
145
+ ruby_version_is "" ... "1.9" do
146
+ it "prints out a warning" do
147
+ begin
148
+ CGI_PARAMS = { "test" => "test" }
149
+ CGI_COOKIES = [ "cookie!" ]
150
+ lambda { @cgi.send(:initialize) }.should complain("do not use CGI_PARAMS and CGI_COOKIES\n")
151
+ ensure
152
+ Object.send(:remove_const, :CGI_PARAMS)
153
+ Object.send(:remove_const, :CGI_COOKIES)
154
+ end
155
+ end
156
+
157
+ it "sets #cookies and #params to the contents of CGI_PARAMS and CGI_COOKIES" do
158
+ begin
159
+ CGI_PARAMS = { "test" => "test" }
160
+ CGI_COOKIES = [ "cookie!" ]
161
+
162
+ @cgi.send(:initialize)
163
+ @cgi.params.should == CGI_PARAMS
164
+ @cgi.cookies.should == CGI_COOKIES
165
+ ensure
166
+ Object.send(:remove_const, :CGI_PARAMS)
167
+ Object.send(:remove_const, :CGI_COOKIES)
168
+ end
169
+ end
170
+ end
171
+ end
data/spec/out_spec.rb ADDED
@@ -0,0 +1,50 @@
1
+ require 'cgi'
2
+
3
+ describe "CGI#out" do
4
+ before(:each) do
5
+ ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
6
+ @cgi = CGI.new
7
+ $stdout, @old_stdout = IOStub.new, $stdout
8
+ end
9
+
10
+ after(:each) do
11
+ $stdout = @old_stdout
12
+ ENV['REQUEST_METHOD'] = @old_request_method
13
+ end
14
+
15
+ it "it writes a HTMl header based on the passed argument to $stdout" do
16
+ @cgi.out { "" }
17
+ $stdout.should == "Content-Type: text/html\r\nContent-Length: 0\r\n\r\n"
18
+ end
19
+
20
+ it "appends the block's return value to the HTML header" do
21
+ @cgi.out { "test!" }
22
+ $stdout.should == "Content-Type: text/html\r\nContent-Length: 5\r\n\r\ntest!"
23
+ end
24
+
25
+ it "automatically sets the Content-Length Header based on the block's return value" do
26
+ @cgi.out { "0123456789" }
27
+ $stdout.should == "Content-Type: text/html\r\nContent-Length: 10\r\n\r\n0123456789"
28
+ end
29
+
30
+ it "includes Cookies in the @output_cookies field" do
31
+ @cgi.instance_variable_set(:@output_cookies, ["multiple", "cookies"])
32
+ @cgi.out { "" }
33
+ $stdout.should == "Content-Type: text/html\r\nContent-Length: 0\r\nSet-Cookie: multiple\r\nSet-Cookie: cookies\r\n\r\n"
34
+ end
35
+ end
36
+
37
+ describe "CGI#out when passed no block" do
38
+ before(:each) do
39
+ ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
40
+ @cgi = CGI.new
41
+ end
42
+
43
+ after(:each) do
44
+ ENV['REQUEST_METHOD'] = @old_request_method
45
+ end
46
+
47
+ it "raises a LocalJumpError" do
48
+ lambda { @cgi.out }.should raise_error(LocalJumpError)
49
+ end
50
+ end
@@ -0,0 +1,23 @@
1
+ require 'cgi'
2
+
3
+ describe "CGI.parse when passed String" do
4
+ it "parses a HTTP Query String into a Hash" do
5
+ CGI.parse("test=test&a=b").should == { "a" => ["b"], "test" => ["test"] }
6
+ CGI.parse("test=1,2,3").should == { "test" => ["1,2,3"] }
7
+ CGI.parse("test=a&a=&b=").should == { "test" => ["a"], "a" => [""], "b" => [""] }
8
+ end
9
+
10
+ it "parses query strings with semicolons in place of ampersands" do
11
+ CGI.parse("test=test;a=b").should == { "a" => ["b"], "test" => ["test"] }
12
+ CGI.parse("test=a;a=;b=").should == { "test" => ["a"], "a" => [""], "b" => [""] }
13
+ end
14
+
15
+ it "allows passing multiple values for one key" do
16
+ CGI.parse("test=1&test=2&test=3").should == { "test" => ["1", "2", "3"] }
17
+ CGI.parse("test[]=1&test[]=2&test[]=3").should == { "test[]" => [ "1", "2", "3" ] }
18
+ end
19
+
20
+ it "unescapes keys and values" do
21
+ CGI.parse("hello%3F=hello%21").should == { "hello?" => ["hello!"] }
22
+ end
23
+ end
@@ -0,0 +1,23 @@
1
+ require 'cgi'
2
+
3
+ describe "CGI.pretty when passed html" do
4
+ it "indents the passed html String with two spaces" do
5
+ CGI.pretty("<HTML><BODY></BODY></HTML>").should == <<-EOS
6
+ <HTML>
7
+ <BODY>
8
+ </BODY>
9
+ </HTML>
10
+ EOS
11
+ end
12
+ end
13
+
14
+ describe "CGI.pretty when passed html, indentation_unit" do
15
+ it "indents the passed html String with the passed indentation_unit" do
16
+ CGI.pretty("<HTML><BODY></BODY></HTML>", "\t").should == <<-EOS
17
+ <HTML>
18
+ \t<BODY>
19
+ \t</BODY>
20
+ </HTML>
21
+ EOS
22
+ end
23
+ end
@@ -0,0 +1,25 @@
1
+ require 'cgi'
2
+
3
+ describe "CGI#print" do
4
+ before(:each) do
5
+ ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
6
+ @cgi = CGI.new
7
+ end
8
+
9
+ after(:each) do
10
+ ENV['REQUEST_METHOD'] = @old_request_method
11
+ end
12
+
13
+ it "passes all arguments to $stdout.print" do
14
+ $stdout.should_receive(:print).with("test")
15
+ @cgi.print("test")
16
+
17
+ $stdout.should_receive(:print).with("one", "two", "three", ["four", "five"])
18
+ @cgi.print("one", "two", "three", ["four", "five"])
19
+ end
20
+
21
+ it "returns the result of calling $stdout.print" do
22
+ $stdout.should_receive(:print).with("test").and_return(:expected)
23
+ @cgi.print("test").should == :expected
24
+ end
25
+ end