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

Ability to verify order? #15

Closed drsharp closed 7 years ago

drsharp commented 12 years ago

Hello!

Is there any way to verify order? For example, if I have:

<div><span>one</span><span>two</span></div>

and test it with:

output.should have_tag(:div) do
  with_tag(:span, :text => 'one')
  with_tag(:span, :text => 'two')
end

it passes. But if I then change it to:

<div><span>two</span><span>one</span></div>

it still passes.

I can't see a way to verify that the first span MUST come before the second in the HTML. Any thoughts?

kucaahbe commented 12 years ago

not yet, but this is "should be" feature, I'm going to add it in near future

drsharp commented 12 years ago

kucaahbe: you might look at how this gem does ordering: https://github.com/mbklein/equivalent-xml

I'd love rspec-html-matchers to include something similar... a tag like:

:element_order => true

Then, my above test could be something like:

output.should have_tag(:div), :element_order => true do
  with_tag(:span, :text => 'one')
  with_tag(:span, :text => 'two')
end

and that would fail if my output text was:

<div><span>two</span><span>one</span></div>

:-)

randoum commented 7 years ago

I'll close this old issue, as there is no sorting option. Anyone's welcome to open a PR on this. Thanks