Skip to content

Instantly share code, notes, and snippets.

@codesnik
Created August 14, 2009 19:36
Show Gist options
  • Save codesnik/168049 to your computer and use it in GitHub Desktop.
Save codesnik/168049 to your computer and use it in GitHub Desktop.
# are you tired of getting "ignoring attempt to close body with div" warning
# messages in integration and functional testing? do you hate to find where exactly,
# in which otherwise passed assert_select it pops out?
#
# this patch is for you, then!
#
# it makes such a warning fatal, writes current test responce body to a temp file
# and gives you a path for further inspect.
#
# put this in lib/patch_testprocess.rb
# and require it from test/test_helper.rb like this
#
# require 'lib/patch_testprocess'
#
# please, contact me if it doesn't work for you in some future Rails version,
# or if you make a gem from it or patch rails core, or whatever relevant. thanks
#
# worked for me on Rails2.3.3
# --
# codesnik <aronaxis@gmail.com>
module ActionController
module TestProcess
def html_document
xml = @response.content_type =~ /xml$/
begin
@html_document ||= HTML::Document.new(@response.body, true, xml)
rescue RuntimeError => e
require 'tmpdir'
path = "#{Dir::tmpdir}/#{rand(0x100000000).to_s(36)}.html"
open(path, 'w') << @response.body
e.message << "\n document saved in #{path}"
raise e
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment