summaryrefslogtreecommitdiff
path: root/spec/ruby/library/cgi/htmlextension/form_spec.rb
blob: 8c0ac97735fcee186a03ea9b4d04e94e216190e7 (plain)
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
require_relative '../../../spec_helper'
require 'cgi'
require_relative 'fixtures/common'

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