I’d like to do an assert_select where only ONE of the matching elements
needs to match the :text.
It seems counterintuitive to me to require them all to match, which
precludes me from testing the existence of a particular tag (h1) with
some particular text if other instances of the same tag exist.
I know that I can narrow down the field by using more detailed
selectors, but it sure would be nice to be able to optionally use :text
as an additional selector (and then be able to determine the number of
elements matching the selector and containing the text, or matching the
text RegExp).
Use assert_select to select the node around the target node you need.
Then do this:
assert_select ‘some node’ do |node|
assert_xml node.to_s
assert_xpath ‘match_me[ . = “contents” ]’
end
Problem: XPath can’t do RegExps (last time I checked). But it can do
any other kind of query you can think of, competitive with query
systems like SQL SELECT.