aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfrancis <francis>2008-02-11 14:35:11 +0000
committerfrancis <francis>2008-02-11 14:35:11 +0000
commit3fd61dd559b1f2c656b793829f0181ed640abfe2 (patch)
tree782ce5336a78b429381f3b33c2fa3567702b8b9d
parent46f4d659b6dc24ae39e05b34f48359ef2f4b9586 (diff)
Validate all HTML responses when running test code.
-rw-r--r--config/environment.rb1
-rw-r--r--spec/spec_helper.rb26
2 files changed, 26 insertions, 1 deletions
diff --git a/config/environment.rb b/config/environment.rb
index 81257c0aa..53d1fa2ed 100644
--- a/config/environment.rb
+++ b/config/environment.rb
@@ -128,4 +128,3 @@ module ActiveRecord
end
end
end
-
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index b1427f71d..7ac73dac2 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -30,5 +30,31 @@ def receive_incoming_mail(email_name, email_to)
RequestMailer.receive(content)
end
+# Monkeypatch! Validate HTML in tests.
+$tempfilecount = 0
+module ActionController
+ module TestProcess
+ alias :original_process :process
+
+ def process(action, parameters = nil, session = nil, flash = nil)
+ # Call original process function
+ self.original_process(action, parameters, session, flash)
+
+ # And then validate if HTML
+ if @response.content_type == "text/html" and @response.response_code != 302
+ $tempfilecount = $tempfilecount + 1
+ tempfilename = File.join(Dir::tmpdir, "railshtmlvalidate."+$$.to_s+"."+$tempfilecount.to_s+".html")
+ File.open(tempfilename, "w+") do |f|
+ f.puts @response.body
+ end
+ if not system("/usr/bin/validate", tempfilename)
+ raise "HTML validation error in " + tempfilename + " HTTP status: " + @response.response_code.to_s
+ end
+ File.unlink(tempfilename)
+ end
+ end
+ end
+end
+