Permalink
Browse files

Merge pull request #56 from skyeagle/webrat

---

It escaped CDATA for a xml document in my case.
  • Loading branch information...
2 parents fea21fc + c2254b3 commit 2bac4578334b33c73d820a66f5f9ee1376fd09e6 @indirect indirect committed Nov 19, 2011
Showing with 26 additions and 35 deletions.
  1. +1 −5 lib/webrat/core/scope.rb
  2. +2 −30 lib/webrat/core/xml.rb
  3. +23 −0 spec/public/matchers/have_xpath_spec.rb
View
@@ -322,11 +322,7 @@ def dom # :nodoc:
def page_dom #:nodoc:
return @response.dom if @response.respond_to?(:dom)
- if @session.xml_content_type?
- dom = Webrat::XML.xml_document(@response_body)
- else
- dom = Webrat::XML.html_document(@response_body)
- end
+ dom = Webrat::XML.document(@response_body)
Webrat::XML.define_dom_method(@response, dom)
return dom
View
@@ -11,37 +11,9 @@ def self.document(stringlike) #:nodoc:
elsif Nokogiri::XML::NodeSet === stringlike
stringlike
elsif stringlike.respond_to?(:body)
- Nokogiri::HTML(stringlike.body.to_s)
+ Nokogiri.parse(stringlike.body.to_s)
else
- Nokogiri::HTML(stringlike.to_s)
- end
- end
-
- def self.html_document(stringlike) #:nodoc:
- return stringlike.dom if stringlike.respond_to?(:dom)
-
- if Nokogiri::HTML::Document === stringlike
- stringlike
- elsif Nokogiri::XML::NodeSet === stringlike
- stringlike
- elsif stringlike.respond_to?(:body)
- Nokogiri::HTML(stringlike.body.to_s)
- else
- Nokogiri::HTML(stringlike.to_s)
- end
- end
-
- def self.xml_document(stringlike) #:nodoc:
- return stringlike.dom if stringlike.respond_to?(:dom)
-
- if Nokogiri::HTML::Document === stringlike
- stringlike
- elsif Nokogiri::XML::NodeSet === stringlike
- stringlike
- elsif stringlike.respond_to?(:body)
- Nokogiri::XML(stringlike.body.to_s)
- else
- Nokogiri::XML(stringlike.to_s)
+ Nokogiri.parse(stringlike.to_s)
end
end
@@ -140,3 +140,26 @@
end
end
end
+
+describe "have_xpath for XML" do
+ include Webrat::Matchers
+
+ before(:each) do
+ @body = <<-XML
+ <?xml version="1.0" encoding="UTF-8"?>
+ <response>
+ <message><![CDATA[Bla-bla]]></message>
+ </response>
+ XML
+ end
+
+ it "should be able to match an XPATH" do
+ @body.should have_xpath("//response")
+ end
+
+ it "should be able to match an XPATH with CDATA content" do
+ @body.should have_xpath("//response") do |el|
+ el.should have_xpath("message", :content => "Bla-bla")
+ end
+ end
+end

0 comments on commit 2bac457

Please sign in to comment.