aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--spec/spec_helper.rb7
-rw-r--r--spec/views/body_view_spec.rb5
2 files changed, 12 insertions, 0 deletions
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index b61eec4df..c56e15f4c 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -35,6 +35,7 @@ def rebuild_xapian_index
Kernel.system(rebuild_name) or raise "failed to launch rebuild-xapian-index"
end
+# Validate an entire HTML page
def validate_html(html)
$tempfilecount = $tempfilecount + 1
tempfilename = File.join(Dir::tmpdir, "railshtmlvalidate."+$$.to_s+"."+$tempfilecount.to_s+".html")
@@ -48,6 +49,12 @@ def validate_html(html)
return true
end
+# Validate HTML fragment by wrapping it as the <body> of a page
+def validate_as_body(html)
+ validate_html('<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">' +
+ "<html><head><title>Test</title></head><body>#{html}</body></html>")
+end
+
# Monkeypatch! Validate HTML in tests.
$html_validation_script = "/usr/bin/validate" # from Debian package wdg-html-validator
if $tempfilecount.nil?
diff --git a/spec/views/body_view_spec.rb b/spec/views/body_view_spec.rb
index 9020912c0..644d14250 100644
--- a/spec/views/body_view_spec.rb
+++ b/spec/views/body_view_spec.rb
@@ -32,6 +32,11 @@ describe "when viewing a body" do
response.should be_success
end
+ it "should be valid HTML" do
+ render "body/show"
+ validate_as_body response.body
+ end
+
it "should show the body's name" do
render "body/show"
response.should have_tag("h1", "Test Quango")