kucaahbe / rspec-html-matchers

Old school have_tag, with_tag(and more) matchers for rspec 3 (Nokogiri powered)
http://rubygems.org/gems/rspec-html-matchers
MIT License
199 stars 90 forks source link

Make it possible to require a single element to match all nested requirements. #76

Open expeehaa opened 3 years ago

expeehaa commented 3 years ago

If the title is too hard to understand, please take a look at this example.

expect('<div><p>test</p></div><div><h2>test2</h2></div>').to have_tag('div') do 
  with_tag 'p' 
  with_tag 'h2' 
end

The string consists of 2 divs, where one has a p tag and the other one has a h2 tag. Intuitively, I would expect the expectation to fail because the string does not have a div tag with tags p and h2. However, it does not fail.

It would be great if there was an option to require all nested matchers to be true for a single element of the outer scope instead of being true for any element of the outer scope.

I might try to implement it myself and create a pull request.