rubysl-cgi 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
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,16 @@
1
+ module CGISpecs
2
+ def self.cgi_new(html = "html4")
3
+ cgi = nil
4
+ ruby_version_is "" ... "1.9" do
5
+ cgi = CGI.new(html)
6
+ end
7
+ ruby_version_is "1.9" do
8
+ cgi = CGI.new(:tag_maker => html)
9
+ end
10
+ cgi
11
+ end
12
+
13
+ def self.split(string)
14
+ string.split("<").reject { |x| x.empty? }.map { |x| "<#{x}" }
15
+ end
16
+ end
@@ -0,0 +1,57 @@
1
+ require 'cgi'
2
+ require File.expand_path('../fixtures/common', __FILE__)
3
+
4
+ describe "CGI::HtmlExtension#form" do
5
+ before(:each) do
6
+ @html = CGISpecs.cgi_new
7
+ @html.stub!(:script_name).and_return("/path/to/some/script")
8
+ end
9
+
10
+ describe "when passed no arguments" do
11
+ it "returns a 'form'-element" do
12
+ output = @html.form
13
+ output.should equal_element("FORM", {"ENCTYPE" => "application/x-www-form-urlencoded", "METHOD" => "post", "ACTION" => "/path/to/some/script"}, "")
14
+ end
15
+
16
+ it "includes the return value of the passed block when passed a block" do
17
+ output = @html.form { "test" }
18
+ output.should equal_element("FORM", {"ENCTYPE" => "application/x-www-form-urlencoded", "METHOD" => "post", "ACTION" => "/path/to/some/script"}, "test")
19
+ end
20
+ end
21
+
22
+ describe "when passed method" do
23
+ it "returns a 'form'-element with the passed method" do
24
+ output = @html.form("get")
25
+ output.should equal_element("FORM", {"ENCTYPE" => "application/x-www-form-urlencoded", "METHOD" => "get", "ACTION" => "/path/to/some/script"}, "")
26
+ end
27
+
28
+ it "includes the return value of the passed block when passed a block" do
29
+ output = @html.form("get") { "test" }
30
+ output.should equal_element("FORM", {"ENCTYPE" => "application/x-www-form-urlencoded", "METHOD" => "get", "ACTION" => "/path/to/some/script"}, "test")
31
+ end
32
+ end
33
+
34
+ describe "when passed method, action" do
35
+ it "returns a 'form'-element with the passed method and the passed action" do
36
+ output = @html.form("get", "/some/other/script")
37
+ output.should equal_element("FORM", {"ENCTYPE" => "application/x-www-form-urlencoded", "METHOD" => "get", "ACTION" => "/some/other/script"}, "")
38
+ end
39
+
40
+ it "includes the return value of the passed block when passed a block" do
41
+ output = @html.form("get", "/some/other/script") { "test" }
42
+ output.should equal_element("FORM", {"ENCTYPE" => "application/x-www-form-urlencoded", "METHOD" => "get", "ACTION" => "/some/other/script"}, "test")
43
+ end
44
+ end
45
+
46
+ describe "when passed method, action, enctype" do
47
+ it "returns a 'form'-element with the passed method, action and enctype" do
48
+ output = @html.form("get", "/some/other/script", "multipart/form-data")
49
+ output.should equal_element("FORM", {"ENCTYPE" => "multipart/form-data", "METHOD" => "get", "ACTION" => "/some/other/script"}, "")
50
+ end
51
+
52
+ it "includes the return value of the passed block when passed a block" do
53
+ output = @html.form("get", "/some/other/script", "multipart/form-data") { "test" }
54
+ output.should equal_element("FORM", {"ENCTYPE" => "multipart/form-data", "METHOD" => "get", "ACTION" => "/some/other/script"}, "test")
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,13 @@
1
+ require File.expand_path('../fixtures/common', __FILE__)
2
+ require 'cgi'
3
+
4
+ describe "CGI::HtmlExtension#frame" do
5
+ before(:each) do
6
+ @html = CGISpecs.cgi_new("html4Fr")
7
+ end
8
+
9
+ it "initializes the HTML Generation methods for the Frameset version of HTML4" do
10
+ @html.frameset.should == "<FRAMESET></FRAMESET>"
11
+ @html.frameset { "link text" }.should == "<FRAMESET>link text</FRAMESET>"
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ require File.expand_path('../fixtures/common', __FILE__)
2
+ require 'cgi'
3
+
4
+ describe "CGI::HtmlExtension#frameset" do
5
+ before(:each) do
6
+ @html = CGISpecs.cgi_new("html4Fr")
7
+ end
8
+
9
+ it "initializes the HTML Generation methods for the Frameset version of HTML4" do
10
+ @html.frameset.should == "<FRAMESET></FRAMESET>"
11
+ @html.frameset { "link text" }.should == "<FRAMESET>link text</FRAMESET>"
12
+ end
13
+ end
@@ -0,0 +1,58 @@
1
+ require 'cgi'
2
+ require File.expand_path('../fixtures/common', __FILE__)
3
+
4
+ describe "CGI::HtmlExtension#hidden" do
5
+ before(:each) do
6
+ @html = CGISpecs.cgi_new
7
+ end
8
+
9
+ describe "when passed no arguments" do
10
+ it "returns an hidden-'input'-element without a name" do
11
+ output = @html.hidden
12
+ output.should equal_element("INPUT", {"NAME" => "", "TYPE" => "hidden"}, "", :not_closed => true)
13
+ end
14
+
15
+ it "ignores a passed block" do
16
+ output = @html.hidden { "test" }
17
+ output.should equal_element("INPUT", {"NAME" => "", "TYPE" => "hidden"}, "", :not_closed => true)
18
+ end
19
+ end
20
+
21
+ describe "when passed name" do
22
+ it "returns an hidden-'input'-element with the passed name" do
23
+ output = @html.hidden("test")
24
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "hidden"}, "", :not_closed => true)
25
+ end
26
+
27
+ it "ignores a passed block" do
28
+ output = @html.hidden("test") { "test" }
29
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "hidden"}, "", :not_closed => true)
30
+ end
31
+ end
32
+
33
+ describe "when passed name, value" do
34
+ it "returns an hidden-'input'-element with the passed name and value" do
35
+ output = @html.hidden("test", "some value")
36
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "hidden", "VALUE" => "some value"}, "", :not_closed => true)
37
+ end
38
+
39
+ it "ignores a passed block" do
40
+ output = @html.hidden("test", "some value") { "test" }
41
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "hidden", "VALUE" => "some value"}, "", :not_closed => true)
42
+ end
43
+ end
44
+
45
+ describe "when passed Hash" do
46
+ it "returns a checkbox-'input'-element using the passed Hash for attributes" do
47
+ attributes = { "NAME" => "test", "VALUE" => "some value" }
48
+ output = @html.hidden("test", "some value")
49
+ output.should equal_element("INPUT", attributes, "", :not_closed => true)
50
+ end
51
+
52
+ it "ignores a passed block" do
53
+ attributes = { "NAME" => "test", "VALUE" => "some value" }
54
+ output = @html.hidden("test", "some value") { "test" }
55
+ output.should equal_element("INPUT", attributes, "", :not_closed => true)
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,65 @@
1
+ require 'cgi'
2
+ require File.expand_path('../fixtures/common', __FILE__)
3
+
4
+ describe "CGI::HtmlExtension#html" do
5
+ before(:each) do
6
+ @html = CGISpecs.cgi_new
7
+ @html.stub!(:doctype).and_return("<!DOCTYPE SUPA-FUNKAY-RUBYSPEC-DOCTYPE>")
8
+ end
9
+
10
+ describe "when passed no arguments" do
11
+ it "returns a self's doctype and an 'html'-element" do
12
+ expected = '<!DOCTYPE SUPA-FUNKAY-RUBYSPEC-DOCTYPE><HTML>'
13
+ @html.html.should == expected
14
+ end
15
+
16
+ it "includes the passed block when passed a block" do
17
+ expected = '<!DOCTYPE SUPA-FUNKAY-RUBYSPEC-DOCTYPE><HTML>test</HTML>'
18
+ @html.html { "test" }.should == expected
19
+ end
20
+ end
21
+
22
+ describe "when passed 'PRETTY'" do
23
+ it "returns pretty output when the passed String is 'PRETTY" do
24
+ expected = "<!DOCTYPE SUPA-FUNKAY-RUBYSPEC-DOCTYPE>\n<HTML>\n"
25
+ @html.html("PRETTY").should == expected
26
+ end
27
+
28
+ it "includes the passed block when passed a block" do
29
+ expected = "<!DOCTYPE SUPA-FUNKAY-RUBYSPEC-DOCTYPE>\n<HTML>\n test\n</HTML>\n"
30
+ @html.html("PRETTY") { "test" }.should == expected
31
+ end
32
+ end
33
+
34
+ describe "when passed a Hash" do
35
+ it "returns an 'html'-element using the passed Hash for attributes" do
36
+ expected = '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"><HTML BLA="TEST">'
37
+ @html.html("DOCTYPE" => '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">', "BLA" => "TEST").should == expected
38
+ end
39
+
40
+ it "omits the doctype when the Hash contains a 'DOCTYPE' entry that's false or nil" do
41
+ @html.html("DOCTYPE" => false).should == "<HTML>"
42
+ @html.html("DOCTYPE" => nil).should == "<HTML>"
43
+ end
44
+ end
45
+
46
+ describe "when each HTML generation" do
47
+ it "returns the doctype declaration for HTML3" do
48
+ expect = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">'
49
+ CGISpecs.cgi_new("html3").html.should == expect + "<HTML>"
50
+ CGISpecs.cgi_new("html3").html { "html body" }.should == expect + "<HTML>html body</HTML>"
51
+ end
52
+
53
+ it "returns the doctype declaration for HTML4" do
54
+ expect = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">'
55
+ CGISpecs.cgi_new("html4").html.should == expect + "<HTML>"
56
+ CGISpecs.cgi_new("html4").html { "html body" }.should == expect + "<HTML>html body</HTML>"
57
+ end
58
+
59
+ it "returns the doctype declaration for the Transitional version of HTML4" do
60
+ expect = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">'
61
+ CGISpecs.cgi_new("html4Tr").html.should == expect + "<HTML>"
62
+ CGISpecs.cgi_new("html4Tr").html { "html body" }.should == expect + "<HTML>html body</HTML>"
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,68 @@
1
+ require 'cgi'
2
+ require File.expand_path('../fixtures/common', __FILE__)
3
+
4
+ describe "CGI::HtmlExtension#image_button" do
5
+ before(:each) do
6
+ @html = CGISpecs.cgi_new
7
+ end
8
+
9
+ describe "when passed no arguments" do
10
+ it "returns an image-'input'-element without a source image" do
11
+ output = @html.image_button
12
+ output.should equal_element("INPUT", {"SRC" => "", "TYPE" => "image"}, "", :not_closed => true)
13
+ end
14
+
15
+ it "ignores a passed block" do
16
+ output = @html.image_button { "test" }
17
+ output.should equal_element("INPUT", {"SRC" => "", "TYPE" => "image"}, "", :not_closed => true)
18
+ end
19
+ end
20
+
21
+ describe "when passed src" do
22
+ it "returns an image-'input'-element with the passed src" do
23
+ output = @html.image_button("/path/to/image.png")
24
+ output.should equal_element("INPUT", {"SRC" => "/path/to/image.png", "TYPE" => "image"}, "", :not_closed => true)
25
+ end
26
+
27
+ it "ignores a passed block" do
28
+ output = @html.image_button("/path/to/image.png") { "test" }
29
+ output.should equal_element("INPUT", {"SRC" => "/path/to/image.png", "TYPE" => "image"}, "", :not_closed => true)
30
+ end
31
+ end
32
+
33
+ describe "when passed src, name" do
34
+ it "returns an image-'input'-element with the passed src and name" do
35
+ output = @html.image_button("/path/to/image.png", "test")
36
+ output.should equal_element("INPUT", {"SRC" => "/path/to/image.png", "TYPE" => "image", "NAME" => "test"}, "", :not_closed => true)
37
+ end
38
+
39
+ it "ignores a passed block" do
40
+ output = @html.image_button("/path/to/image.png", "test") { "test" }
41
+ output.should equal_element("INPUT", {"SRC" => "/path/to/image.png", "TYPE" => "image", "NAME" => "test"}, "", :not_closed => true)
42
+ end
43
+ end
44
+
45
+ describe "when passed src, name, alt" do
46
+ it "returns an image-'input'-element with the passed src, name and alt" do
47
+ output = @html.image_button("/path/to/image.png", "test", "alternative")
48
+ output.should equal_element("INPUT", {"SRC" => "/path/to/image.png", "TYPE" => "image", "NAME" => "test", "ALT" => "alternative"}, "", :not_closed => true)
49
+ end
50
+
51
+ it "ignores a passed block" do
52
+ output = @html.image_button("/path/to/image.png", "test", "alternative") { "test" }
53
+ output.should equal_element("INPUT", {"SRC" => "/path/to/image.png", "TYPE" => "image", "NAME" => "test", "ALT" => "alternative"}, "", :not_closed => true)
54
+ end
55
+ end
56
+
57
+ describe "when passed Hash" do
58
+ it "returns a image-'input'-element using the passed Hash for attributes" do
59
+ output = @html.image_button("NAME" => "test", "VALUE" => "test-value")
60
+ output.should equal_element("INPUT", {"SRC" => "", "TYPE" => "image", "NAME" => "test", "VALUE" => "test-value"}, "", :not_closed => true)
61
+ end
62
+
63
+ it "ignores a passed block" do
64
+ output = @html.image_button("NAME" => "test", "VALUE" => "test-value") { "test" }
65
+ output.should equal_element("INPUT", {"SRC" => "", "TYPE" => "image", "NAME" => "test", "VALUE" => "test-value"}, "", :not_closed => true)
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,84 @@
1
+ require 'cgi'
2
+ require File.expand_path('../fixtures/common', __FILE__)
3
+
4
+ describe "CGI::HtmlExtension#img" do
5
+ before(:each) do
6
+ @html = CGISpecs.cgi_new
7
+ end
8
+
9
+ describe "when passed no arguments" do
10
+ it "returns an 'img'-element without an src-url or alt-text" do
11
+ output = @html.img
12
+ output.should equal_element("IMG", { "SRC" => "", "ALT" => "" }, "", :not_closed => true)
13
+ end
14
+
15
+ it "ignores a passed block" do
16
+ output = @html.img { "test" }
17
+ output.should equal_element("IMG", { "SRC" => "", "ALT" => "" }, "", :not_closed => true)
18
+ end
19
+ end
20
+
21
+ describe "when passed src" do
22
+ it "returns an 'img'-element with the passed src-url" do
23
+ output = @html.img("/path/to/some/image.png")
24
+ output.should equal_element("IMG", { "SRC" => "/path/to/some/image.png", "ALT" => "" }, "", :not_closed => true)
25
+ end
26
+
27
+ it "ignores a passed block" do
28
+ output = @html.img("/path/to/some/image.png")
29
+ output.should equal_element("IMG", { "SRC" => "/path/to/some/image.png", "ALT" => "" }, "", :not_closed => true)
30
+ end
31
+ end
32
+
33
+ describe "when passed src, alt" do
34
+ it "returns an 'img'-element with the passed src-url and the passed alt-text" do
35
+ output = @html.img("/path/to/some/image.png", "Alternative")
36
+ output.should equal_element("IMG", { "SRC" => "/path/to/some/image.png", "ALT" => "Alternative" }, "", :not_closed => true)
37
+ end
38
+
39
+ it "ignores a passed block" do
40
+ output = @html.img("/path/to/some/image.png", "Alternative") { "test" }
41
+ output.should equal_element("IMG", { "SRC" => "/path/to/some/image.png", "ALT" => "Alternative" }, "", :not_closed => true)
42
+ end
43
+ end
44
+
45
+ describe "when passed src, alt, width" do
46
+ it "returns an 'img'-element with the passed src-url, the passed alt-text and the passed width" do
47
+ output = @html.img("/path/to/some/image.png", "Alternative", 40)
48
+ output.should equal_element("IMG", { "SRC" => "/path/to/some/image.png", "ALT" => "Alternative", "WIDTH" => "40" }, "", :not_closed => true)
49
+ end
50
+
51
+ it "ignores a passed block" do
52
+ output = @html.img("/path/to/some/image.png", "Alternative", 40) { "test" }
53
+ output.should equal_element("IMG", { "SRC" => "/path/to/some/image.png", "ALT" => "Alternative", "WIDTH" => "40" }, "", :not_closed => true)
54
+ end
55
+ end
56
+
57
+ describe "when passed src, alt, width, height" do
58
+ it "returns an 'img'-element with the passed src-url, the passed alt-text, the passed width and the passed height" do
59
+ output = @html.img("/path/to/some/image.png", "Alternative", 40, 60)
60
+ output.should equal_element("IMG", { "SRC" => "/path/to/some/image.png", "ALT" => "Alternative", "WIDTH" => "40", "HEIGHT" => "60" }, "", :not_closed => true)
61
+ end
62
+
63
+ it "ignores a passed block" do
64
+ output = @html.img { "test" }
65
+ output.should equal_element("IMG", { "SRC" => "", "ALT" => "" }, "", :not_closed => true)
66
+ end
67
+ end
68
+
69
+ describe "when passed Hash" do
70
+ ruby_bug "http://redmine.ruby-lang.org/issues/show/255", "1.8.7" do
71
+ it "returns an 'img'-element with the passed Hash as attributes" do
72
+ attributes = { "SRC" => "src", "ALT" => "alt", "WIDTH" => 100, "HEIGHT" => 50 }
73
+ output = @html.img(attributes)
74
+ output.should equal_element("IMG", attributes, "", :not_closed => true)
75
+ end
76
+
77
+ it "ignores a passed block" do
78
+ attributes = { "SRC" => "src", "ALT" => "alt", "WIDTH" => 100, "HEIGHT" => 50 }
79
+ output = @html.img(attributes) { "test" }
80
+ output.should equal_element("IMG", attributes, "", :not_closed => true)
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,63 @@
1
+ require 'cgi'
2
+ require File.expand_path('../fixtures/common', __FILE__)
3
+
4
+ describe "CGI::HtmlExtension#multipart_form" do
5
+ before(:each) do
6
+ @html = CGISpecs.cgi_new
7
+ @html.stub!(:script_name).and_return("/path/to/some/script.rb")
8
+ end
9
+
10
+ describe "when passed no arguments" do
11
+ it "returns a 'form'-element with it's enctype set to multipart" do
12
+ output = @html.multipart_form
13
+ output.should equal_element("FORM", { "ENCTYPE" => "multipart/form-data", "METHOD" => "post" }, "")
14
+ end
15
+
16
+ it "includes the return value of the passed block when passed a block" do
17
+ output = @html.multipart_form { "test" }
18
+ output.should equal_element("FORM", { "ENCTYPE" => "multipart/form-data", "METHOD" => "post" }, "test")
19
+ end
20
+ end
21
+
22
+ describe "when passed action" do
23
+ it "returns a 'form'-element with the passed action" do
24
+ output = @html.multipart_form("/some/other/script.rb")
25
+ output.should equal_element("FORM", { "ENCTYPE" => "multipart/form-data", "METHOD" => "post", "ACTION" => "/some/other/script.rb" }, "")
26
+ end
27
+
28
+ it "includes the return value of the passed block when passed a block" do
29
+ output = @html.multipart_form("/some/other/script.rb") { "test" }
30
+ output.should equal_element("FORM", { "ENCTYPE" => "multipart/form-data", "METHOD" => "post", "ACTION" => "/some/other/script.rb" }, "test")
31
+ end
32
+ end
33
+
34
+ describe "when passed action, enctype" do
35
+ it "returns a 'form'-element with the passed action and enctype" do
36
+ output = @html.multipart_form("/some/other/script.rb", "application/x-www-form-urlencoded")
37
+ output.should equal_element("FORM", { "ENCTYPE" => "application/x-www-form-urlencoded", "METHOD" => "post", "ACTION" => "/some/other/script.rb" }, "")
38
+ end
39
+
40
+ it "includes the return value of the passed block when passed a block" do
41
+ output = @html.multipart_form("/some/other/script.rb", "application/x-www-form-urlencoded") { "test" }
42
+ output.should equal_element("FORM", { "ENCTYPE" => "application/x-www-form-urlencoded", "METHOD" => "post", "ACTION" => "/some/other/script.rb" }, "test")
43
+ end
44
+ end
45
+
46
+ describe "when passed Hash" do
47
+ it "returns a 'form'-element with the passed Hash as attributes" do
48
+ output = @html.multipart_form("ID" => "test")
49
+ output.should equal_element("FORM", { "ENCTYPE" => "multipart/form-data", "METHOD" => "post", "ID" => "test" }, "")
50
+
51
+ output = @html.multipart_form("ID" => "test", "ENCTYPE" => "application/x-www-form-urlencoded", "METHOD" => "get")
52
+ output.should equal_element("FORM", { "ENCTYPE" => "application/x-www-form-urlencoded", "METHOD" => "get", "ID" => "test" }, "")
53
+ end
54
+
55
+ it "includes the return value of the passed block when passed a block" do
56
+ output = @html.multipart_form("ID" => "test") { "test" }
57
+ output.should equal_element("FORM", { "ENCTYPE" => "multipart/form-data", "METHOD" => "post", "ID" => "test" }, "test")
58
+
59
+ output = @html.multipart_form("ID" => "test", "ENCTYPE" => "application/x-www-form-urlencoded", "METHOD" => "get") { "test" }
60
+ output.should equal_element("FORM", { "ENCTYPE" => "application/x-www-form-urlencoded", "METHOD" => "get", "ID" => "test" }, "test")
61
+ end
62
+ end
63
+ end