File: form_spec.rb

package info (click to toggle)
ruby2.5 2.5.5-3%2Bdeb10u4
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 101,532 kB
  • sloc: ruby: 732,598; ansic: 669,262; xml: 25,363; yacc: 20,963; javascript: 6,680; sh: 3,610; lisp: 2,627; makefile: 596; python: 198; sed: 76; perl: 62; awk: 36; asm: 35
file content (58 lines) | stat: -rw-r--r-- 2,766 bytes parent folder | download | duplicates (2)
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 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