-
-
Notifications
You must be signed in to change notification settings - Fork 193
/
html_spec.rb
118 lines (100 loc) · 4.68 KB
/
html_spec.rb
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
require 'spec_helper'
describe 'Html test' do
it 'ignores an invalid tag by default' do
html = "#{FIXTURES_DIR}/html/invalid_tag.html"
proofer = run_proofer(html, :file)
expect(proofer.failed_tests).to eq []
end
it "doesn't fail for html5 tags" do
html = "#{FIXTURES_DIR}/html/html5_tags.html"
proofer = run_proofer(html, :file, { :check_html => true })
expect(proofer.failed_tests).to eq []
end
it "doesn't fail for svg elements" do
html = "#{FIXTURES_DIR}/html/svg_elements.html"
proofer = run_proofer(html, :file, { :check_html => true })
expect(proofer.failed_tests).to eq []
end
it 'works for custom tags' do
html = "#{FIXTURES_DIR}/html/invalid_tag.html"
proofer = run_proofer(html, :file, { :check_html => true, :validation => { :report_invalid_tags => true} })
expect(proofer.failed_tests).to eq []
end
it 'fails for an unmatched end tag' do
html = "#{FIXTURES_DIR}/html/unmatched_end_tag.html"
proofer = run_proofer(html, :file, { :check_html => true })
expect(proofer.failed_tests.first).to include("@3:1: That tag isn't allowed here Currently open tags: html, body..\n</div>\n^ (line 3)")
end
it 'allows an unescaped ampersand in attribute' do
html = "#{FIXTURES_DIR}/html/unescaped_ampersand_in_attribute.html"
proofer = run_proofer(html, :file, { :check_html => true })
expect(proofer.failed_tests).to eq []
end
it 'fails for mismatch between opening and ending tag' do
html = "#{FIXTURES_DIR}/html/opening_and_ending_tag_mismatch.html"
proofer = run_proofer(html, :file, { :check_html => true })
expect(proofer.failed_tests.first).to include("@3:31: That tag isn't allowed here Currently open tags: html, body, p, strong..\n<p>The quick <strong>brown fox</p>\n ^ (line 3)")
end
it 'fails for div inside head' do
html = "#{FIXTURES_DIR}/html/div_inside_head.html"
proofer = run_proofer(html, :file, { :check_html => true })
expect(proofer.failed_tests.first).to include("@5:1: That tag isn't allowed here Currently open tags: html, body..\n</head>\n^ (line 5)")
end
it 'fails for missing closing quotation mark in href' do
html = "#{FIXTURES_DIR}/html/missing_closing_quotes.html"
proofer = run_proofer(html, :file, { :check_html => true })
expect(proofer.failed_tests.to_s).to include("@6:1: Tokenizer error with an unimplemented error message.\\n\\n^ (line 6)\"]")
end
it "doesn't fail for single ampersand" do
html = "#{FIXTURES_DIR}/html/single_amp.html"
proofer = run_proofer(html, :file, { :check_html => true })
expect(proofer.failed_tests).to eq []
end
it "allows single ampersand" do
html = "#{FIXTURES_DIR}/html/single_amp.html"
proofer = run_proofer(html, :file, { :check_html => true, :validation => { :report_missing_names => true } })
expect(proofer.failed_tests).to eq []
end
it 'ignores embeded scripts when asked' do
opts = { :check_html => true, :validation => { :report_script_embeds => false } }
ignorableScript = "#{FIXTURES_DIR}/html/ignore_script_embeds.html"
proofer = run_proofer(ignorableScript, :file, opts)
expect(proofer.failed_tests).to eq []
end
it 'reports embeded scripts when asked' do
opts = { :check_html => true, :validation => { :report_script_embeds => true } }
ignorableScript = "#{FIXTURES_DIR}/html/ignore_script_embeds.html"
proofer = run_proofer(ignorableScript, :file, opts)
expect(proofer.failed_tests).to eq []
end
it 'does not fail for weird iframe sources' do
opts = { :check_html => true }
weird_iframe = "#{FIXTURES_DIR}/html/weird_iframe.html"
proofer = run_proofer(weird_iframe, :file, opts)
expect(proofer.failed_tests).to eq []
end
it 'does not fail for weird onclick sources' do
opts = { :check_html => true }
weird_onclick = "#{FIXTURES_DIR}/html/weird_onclick.html"
proofer = run_proofer(weird_onclick, :file, opts)
expect(proofer.failed_tests).to eq []
end
it 'validates normal looking government HTML' do
opts = { :check_html => true }
normal_looking_page = "#{FIXTURES_DIR}/html/normal_looking_page.html"
proofer = run_proofer(normal_looking_page, :file, opts)
expect(proofer.failed_tests).to eq []
end
it 'does not fail for tag picture' do
opts = { :check_html => true }
normal_looking_page = "#{FIXTURES_DIR}/html/tag_picture.html"
proofer = run_proofer(normal_looking_page, :file, opts)
expect(proofer.failed_tests).to eq []
end
it 'ignores namespaces' do
opts = { :check_html => true }
ignorableNamespace = "#{FIXTURES_DIR}/html/ignore_namespace.html"
proofer = run_proofer(ignorableNamespace, :file, opts)
expect(proofer.failed_tests).to eq []
end
end