ruby/spec/rubyspec/library/cgi/htmlextension/form_spec.rb
eregon 95e8c48dd3 Add in-tree mspec and ruby/spec
* For easier modifications of ruby/spec by MRI developers.
* .gitignore: track changes under spec.
* spec/mspec, spec/rubyspec: add in-tree mspec and ruby/spec.
  These files can therefore be updated like any other file in MRI.
  Instructions are provided in spec/README.
  [Feature #13156] [ruby-core:79246]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58595 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-07 12:04:49 +00:00

58 lines
2.7 KiB
Ruby

require File.expand_path('../../../../spec_helper', __FILE__)
require 'cgi'
require File.expand_path('../fixtures/common', __FILE__)
describe "CGI::HtmlExtension#form" do
before :each do
@html = CGISpecs.cgi_new
@html.stub!(:script_name).and_return("/path/to/some/script")
end
describe "when passed no arguments" do
it "returns a 'form'-element" do
output = @html.form
output.should equal_element("FORM", {"ENCTYPE" => "application/x-www-form-urlencoded", "METHOD" => "post", "ACTION" => "/path/to/some/script"}, "")
end
it "includes the return value of the passed block when passed a block" do
output = @html.form { "test" }
output.should equal_element("FORM", {"ENCTYPE" => "application/x-www-form-urlencoded", "METHOD" => "post", "ACTION" => "/path/to/some/script"}, "test")
end
end
describe "when passed method" do
it "returns a 'form'-element with the passed method" do
output = @html.form("get")
output.should equal_element("FORM", {"ENCTYPE" => "application/x-www-form-urlencoded", "METHOD" => "get", "ACTION" => "/path/to/some/script"}, "")
end
it "includes the return value of the passed block when passed a block" do
output = @html.form("get") { "test" }
output.should equal_element("FORM", {"ENCTYPE" => "application/x-www-form-urlencoded", "METHOD" => "get", "ACTION" => "/path/to/some/script"}, "test")
end
end
describe "when passed method, action" do
it "returns a 'form'-element with the passed method and the passed action" do
output = @html.form("get", "/some/other/script")
output.should equal_element("FORM", {"ENCTYPE" => "application/x-www-form-urlencoded", "METHOD" => "get", "ACTION" => "/some/other/script"}, "")
end
it "includes the return value of the passed block when passed a block" do
output = @html.form("get", "/some/other/script") { "test" }
output.should equal_element("FORM", {"ENCTYPE" => "application/x-www-form-urlencoded", "METHOD" => "get", "ACTION" => "/some/other/script"}, "test")
end
end
describe "when passed method, action, enctype" do
it "returns a 'form'-element with the passed method, action and enctype" do
output = @html.form("get", "/some/other/script", "multipart/form-data")
output.should equal_element("FORM", {"ENCTYPE" => "multipart/form-data", "METHOD" => "get", "ACTION" => "/some/other/script"}, "")
end
it "includes the return value of the passed block when passed a block" do
output = @html.form("get", "/some/other/script", "multipart/form-data") { "test" }
output.should equal_element("FORM", {"ENCTYPE" => "multipart/form-data", "METHOD" => "get", "ACTION" => "/some/other/script"}, "test")
end
end
end