Switch to using Nokogiri.parse for XML/XHTML autodetection [#66 state:resolved]

This commit is contained in:
Bryan Helmkamp 2008-11-22 16:46:03 -05:00
parent bb5eac701d
commit a8e02a6b6e
5 changed files with 28 additions and 13 deletions

View File

@ -10,11 +10,11 @@ module Webrat
elsif Nokogiri::XML::NodeSet === stringlike elsif Nokogiri::XML::NodeSet === stringlike
stringlike stringlike
elsif StringIO === stringlike elsif StringIO === stringlike
Nokogiri::HTML(stringlike.string) Nokogiri.parse(stringlike.string)
elsif stringlike.respond_to?(:body) elsif stringlike.respond_to?(:body)
Nokogiri::HTML(stringlike.body.to_s) Nokogiri.parse(stringlike.body.to_s)
else else
Nokogiri::HTML(stringlike.to_s) Nokogiri.parse(stringlike.to_s)
end end
end end

View File

@ -91,12 +91,14 @@ describe "click_button" do
it "should submit the form with the specified button" do it "should submit the form with the specified button" do
@session.response_body = <<-EOS @session.response_body = <<-EOS
<form method="get" action="/form1"> <html>
<input type="submit" /> <form method="get" action="/form1">
</form> <input type="submit" />
<form method="get" action="/form2"> </form>
<input type="submit" value="Form2" /> <form method="get" action="/form2">
</form> <input type="submit" value="Form2" />
</form>
</html>
EOS EOS
@session.should_receive(:get).with("/form2", {}) @session.should_receive(:get).with("/form2", {})
@session.click_button "Form2" @session.click_button "Form2"

View File

@ -254,8 +254,10 @@ describe "click_link" do
it "should choose the shortest link text match" do it "should choose the shortest link text match" do
@session.response_body = <<-EOS @session.response_body = <<-EOS
<a href="/page1">Linkerama</a> <html>
<a href="/page2">Link</a> <a href="/page1">Linkerama</a>
<a href="/page2">Link</a>
</html>
EOS EOS
@session.should_receive(:get).with("/page2", {}) @session.should_receive(:get).with("/page2", {})
@ -264,7 +266,9 @@ describe "click_link" do
it "should treat non-breaking spaces as spaces" do it "should treat non-breaking spaces as spaces" do
@session.response_body = <<-EOS @session.response_body = <<-EOS
<a href="/page1">This&nbsp;is&nbsp;a&nbsp;link</a> <html>
<a href="/page1">This&nbsp;is&nbsp;a&nbsp;link</a>
</html>
EOS EOS
@session.should_receive(:get).with("/page1", {}) @session.should_receive(:get).with("/page1", {})
@ -284,10 +288,12 @@ describe "click_link" do
it "should click link within a selector" do it "should click link within a selector" do
@session.response_body = <<-EOS @session.response_body = <<-EOS
<html>
<a href="/page1">Link</a> <a href="/page1">Link</a>
<div id="container"> <div id="container">
<a href="/page2">Link</a> <a href="/page2">Link</a>
</div> </div>
</html>
EOS EOS
@session.should_receive(:get).with("/page2", {}) @session.should_receive(:get).with("/page2", {})

View File

@ -18,7 +18,6 @@ describe Webrat::Matchers do
describe "#have_xpath" do describe "#have_xpath" do
it "should work with non-HTML documents" do it "should work with non-HTML documents" do
pending "Bugfix"
xml = '<foo bar="baz"></foo>' xml = '<foo bar="baz"></foo>'
xml.should have_xpath('/foo[@bar="baz"]') xml.should have_xpath('/foo[@bar="baz"]')
end end

View File

@ -7,12 +7,14 @@ describe "within" do
it "should work when nested" do it "should work when nested" do
@session.response_body = <<-EOS @session.response_body = <<-EOS
<html>
<div> <div>
<a href="/page1">Link</a> <a href="/page1">Link</a>
</div> </div>
<div id="container"> <div id="container">
<div><a href="/page2">Link</a></div> <div><a href="/page2">Link</a></div>
</div> </div>
</html>
EOS EOS
@session.should_receive(:get).with("/page2", {}) @session.should_receive(:get).with("/page2", {})
@ -25,10 +27,12 @@ describe "within" do
it "should click links within a scope" do it "should click links within a scope" do
@session.response_body = <<-EOS @session.response_body = <<-EOS
<html>
<a href="/page1">Link</a> <a href="/page1">Link</a>
<div id="container"> <div id="container">
<a href="/page2">Link</a> <a href="/page2">Link</a>
</div> </div>
</html>
EOS EOS
@session.should_receive(:get).with("/page2", {}) @session.should_receive(:get).with("/page2", {})
@ -39,6 +43,7 @@ describe "within" do
it "should submit forms within a scope" do it "should submit forms within a scope" do
@session.response_body = <<-EOS @session.response_body = <<-EOS
<html>
<form id="form1" action="/form1"> <form id="form1" action="/form1">
<label>Email: <input type="text" name="email" /> <label>Email: <input type="text" name="email" />
<input type="submit" value="Add" /> <input type="submit" value="Add" />
@ -47,6 +52,7 @@ describe "within" do
<label>Email: <input type="text" name="email" /> <label>Email: <input type="text" name="email" />
<input type="submit" value="Add" /> <input type="submit" value="Add" />
</form> </form>
</html>
EOS EOS
@session.should_receive(:get).with("/form2", "email" => "test@example.com") @session.should_receive(:get).with("/form2", "email" => "test@example.com")
@ -58,11 +64,13 @@ describe "within" do
it "should not find buttons outside of the scope" do it "should not find buttons outside of the scope" do
@session.response_body = <<-EOS @session.response_body = <<-EOS
<html>
<form action="/form1"> <form action="/form1">
<input type="submit" value="Add" /> <input type="submit" value="Add" />
</form> </form>
<form id="form2" action="/form2"> <form id="form2" action="/form2">
</form> </form>
</html>
EOS EOS
@session.within "#form2" do @session.within "#form2" do