File: html_spec.rb

package info (click to toggle)
ruby3.4 3.4.5-1~exp1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 154,784 kB
  • sloc: ruby: 1,259,653; ansic: 829,955; yacc: 28,233; pascal: 7,359; sh: 3,864; python: 1,799; cpp: 1,158; asm: 808; makefile: 801; javascript: 414; lisp: 109; perl: 62; awk: 36; sed: 4; xml: 4
file content (66 lines) | stat: -rw-r--r-- 2,706 bytes parent folder | download | duplicates (7)
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
59
60
61
62
63
64
65
66
require_relative '../../../spec_helper'
require 'cgi'
require_relative 'fixtures/common'

describe "CGI::HtmlExtension#html" do
  before :each do
    @html = CGISpecs.cgi_new
    @html.stub!(:doctype).and_return("<!DOCTYPE SUPA-FUNKAY-RUBYSPEC-DOCTYPE>")
  end

  describe "when passed no arguments" do
    it "returns a self's doctype and an 'html'-element" do
      expected = '<!DOCTYPE SUPA-FUNKAY-RUBYSPEC-DOCTYPE><HTML>'
      @html.html.should == expected
    end

    it "includes the passed block when passed a block" do
      expected = '<!DOCTYPE SUPA-FUNKAY-RUBYSPEC-DOCTYPE><HTML>test</HTML>'
      @html.html { "test" }.should == expected
    end
  end

  describe "when passed 'PRETTY'" do
    it "returns pretty output when the passed String is 'PRETTY" do
      expected = "<!DOCTYPE SUPA-FUNKAY-RUBYSPEC-DOCTYPE>\n<HTML>\n"
      @html.html("PRETTY").should == expected
    end

    it "includes the passed block when passed a block" do
      expected = "<!DOCTYPE SUPA-FUNKAY-RUBYSPEC-DOCTYPE>\n<HTML>\n  test\n</HTML>\n"
      @html.html("PRETTY") { "test" }.should == expected
    end
  end

  describe "when passed a Hash" do
    it "returns an 'html'-element using the passed Hash for attributes" do
      expected = '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"><HTML BLA="TEST">'
      @html.html("DOCTYPE" => '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">', "BLA" => "TEST").should == expected
    end

    it "omits the doctype when the Hash contains a 'DOCTYPE' entry that's false or nil" do
      @html.html("DOCTYPE" => false).should == "<HTML>"
      @html.html("DOCTYPE" => nil).should == "<HTML>"
    end
  end

  describe "when each HTML generation" do
    it "returns the doctype declaration for HTML3" do
      expect = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">'
      CGISpecs.cgi_new("html3").html.should == expect + "<HTML>"
      CGISpecs.cgi_new("html3").html { "html body" }.should == expect + "<HTML>html body</HTML>"
    end

    it "returns the doctype declaration for HTML4" do
      expect = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">'
      CGISpecs.cgi_new("html4").html.should == expect + "<HTML>"
      CGISpecs.cgi_new("html4").html { "html body" }.should == expect + "<HTML>html body</HTML>"
    end

    it "returns the doctype declaration for the Transitional version of HTML4" do
      expect = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">'
      CGISpecs.cgi_new("html4Tr").html.should == expect + "<HTML>"
      CGISpecs.cgi_new("html4Tr").html { "html body" }.should == expect + "<HTML>html body</HTML>"
    end
  end
end