Hello,
assert_have_xpath
is given a
stringlike
which happens to be
Nokogiri::XML::NodeSet
.
This gets bitten by some special logic which destroys XPath
statements that happen to start with “///”. (This is an
XPath idiom for “anywhere in the document”.)
The result is an (undeserved)
Nokogiri::XML::XPath::SyntaxError ... Invalid
expression
.
I attach a couple of tests as a patch. The first test works
fine, the second exposes this bug.
The problem is caused by the following code stance in
webrat-0.6.0/lib/webrat/core/matchers/have_xpath.rb
:
def nokogiri_matches(stringlike)
if Nokogiri::XML::NodeSet === stringlike
@query = query.gsub(%r'^//', './/')
else
@query = query
end
This gsub
comes with no comment. So it remains
somewhat unclear (at least to me) why this is done that way. In my
humble opinion, messing with XPath provided by the user can hardly
fail to constitute a bug.
For a workaround,add a space. “ ///” works as
expected.
With best regards, and thank you for providing fine
software,
Andreas