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

I'd like to have your opinion on this... #19

Closed jmuheim closed 12 years ago

jmuheim commented 12 years ago

Hey there, dear developer of this gem.

I'm very new to testing HTML using RSpec and I have a fundamental understanding problem, it seems, and as you seem to have some experience already with RSpec, please take a look at these two topics on StackOverflow and tell me your opinion:

RSpec have_tag() combined with without_tag() / with_tag() RSpec: nested have_tag / with_tag calls

Thanks a lot, I'm really thankful for this.

kucaahbe commented 12 years ago

about formtastic tests:

jmuheim commented 12 years ago

Thanks for your opinion. I know that it's another library, and my question was more, whether the way that I'd like to go (which is: to have the possibility to encapsulate the tests to reduce redundancy) is possible anyhow? Because as far as I see this isn't, whether with your library, nor with any other I know.

kucaahbe commented 12 years ago

as for scope question, this:

specify do
  '<p class="qwe rty" id="qwerty"><strong><em><span>Para</span></em></strong>graph</p>'.should have_tag('p > strong > em') do
      without_tag('em')
  end
end

actually is not going to work as you expect (as you already saw) due to technical implementation of this gem, and I'm not sure is this bug or feature:). There could be two ways to resolve this issue:

  1. To change the implementation, so without_tag('em') will try to match '<span>Para</span>', but this could lead to tests failures for someone
  2. add something like this:

    specify do
     '<p class="qwe rty" id="qwerty"><strong><em><span>Para</span></em></strong>graph</p>'.should have_tag('p > strong > em', :inside_matched => true) do
       without_tag('em')
     end
    end

    so without_tag('em') will try to match '<span>Para</span>' instead of '<em><span>Para</span></em>'

kucaahbe commented 12 years ago

and, yes, it is possible to encapsulate the tests, you could try, just keep in mind scope I described above hope my answers was helpful...

jmuheim commented 12 years ago

Okay, thanks a lot for your efforts. I don't have time to implement the functionality above, so I just stick to the functionalities that are provided.

Have a nice weekend! :-)

kucaahbe commented 12 years ago

Thanks!:)