From 46b8d91c962e802fbcb14ee0bcf03aab1afa180a Mon Sep 17 00:00:00 2001 From: Andre Arko Date: Sun, 29 Aug 2010 13:00:46 -0700 Subject: [PATCH] Allow Webrat::XML.document to recognize stringlikes that are XML --- lib/webrat/core/xml.rb | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/webrat/core/xml.rb b/lib/webrat/core/xml.rb index 7ce42ac7..b23655a7 100644 --- a/lib/webrat/core/xml.rb +++ b/lib/webrat/core/xml.rb @@ -6,14 +6,17 @@ module XML #:nodoc: def self.document(stringlike) #:nodoc: return stringlike.dom if stringlike.respond_to?(:dom) - if Nokogiri::HTML::Document === stringlike - stringlike - elsif Nokogiri::XML::NodeSet === stringlike + case stringlike + when Nokogiri::HTML::Document, Nokogiri::XML::NodeSet stringlike - elsif stringlike.respond_to?(:body) - Nokogiri::HTML(stringlike.body.to_s) else - Nokogiri::HTML(stringlike.to_s) + stringlike = stringlike.body if stringlike.respond_to?(:body) + + if stringlike.to_s =~ /\<\?xml/ + Nokogiri::XML(stringlike.to_s) + else + Nokogiri::HTML(stringlike.to_s) + end end end