Skip to content

Instantly share code, notes, and snippets.

@metaskills
Created July 6, 2010 17:19
Show Gist options
  • Save metaskills/465647 to your computer and use it in GitHub Desktop.
Save metaskills/465647 to your computer and use it in GitHub Desktop.
module Webrat
class Session
def formatted_error
doc = Nokogiri::HTML(response_body)
exception_name = doc.css('head title').inner_html.squish
exception_msg = doc.css('body h1').inner_html.squish
exception_detail1 = "".tap do |detail|
d = doc.css('body p')[0]
detail << d.content.strip
detail << d.next_sibling.content.squish
end
exception_detail2 = "".tap do |detail|
d = doc.css('body p')[1]
detail << d.content.strip
detail << d.next_sibling.css('code').first.content.strip
end
app_trace = doc.css('#Application-Trace pre code').inner_html
[exception_name, exception_msg, exception_detail1, exception_detail2, app_trace].join("\n")
rescue
"Could not format page exception. Perhaps try to use Nokogiri on this: \n#{response_body}"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment