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

Fix deep nesting #55

Closed misaka closed 7 years ago

misaka commented 8 years ago

As mentioned in issue #24, nesting using with_tag doesn't restrict it's search to the parent have_tag or with_tag that it's nested inside of. This PR proposes a fix by passing a parameter to the block have_tag receives, which can then be used to run new have_tag expectations constrained to the parent tag. So now you can write this:

    expect(rendered).to have_tag('div') do |div|
      expect(div).to have_tag 'ul.numeric'
      expect(div).to have_tag 'ul.alpha'
    end

(see included specs for more examples).

This isn't quite as nice and concise as just using with_tag without an expect, but the problem with that approach is that while with_tag can constrain the scope to a parent matcher, it doesn't have a way to unconstrain it after it's run the block so that the next with_tag isn't constrained to the same context.

kucaahbe commented 8 years ago

thanks for PR @misaka ! What do you think about maintaining this repo? Don't have enough time to maintain it, so could grant all the credentials (move this repo to you and provide access to rubygems)

randoum commented 7 years ago

@kucaahbe @misaka I suspect, though I'm not entirely sure, that this PR created a bug. Kindly see #58