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
stringlike
elsif StringIO === stringlike
Nokogiri::HTML(stringlike.string)
Nokogiri.parse(stringlike.string)
elsif stringlike.respond_to?(:body)
Nokogiri::HTML(stringlike.body.to_s)
Nokogiri.parse(stringlike.body.to_s)
else
Nokogiri::HTML(stringlike.to_s)
Nokogiri.parse(stringlike.to_s)
end
end

View File

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

View File

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

View File

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

View File

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