Skip to content

Commit

Permalink
Allow Webrat::XML.document to recognize stringlikes that are XML
Browse files Browse the repository at this point in the history
  • Loading branch information
indirect committed Aug 29, 2010
1 parent dcd17ac commit 46b8d91
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions lib/webrat/core/xml.rb
Expand Up @@ -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

Expand Down

0 comments on commit 46b8d91

Please sign in to comment.