I'm currently using RSpec to write view specs using have_tag and with_tag; these methods are really just wrappers for Rails' assert_select method, so I am filing this request here.
Specifically, assert_select allows me to test for the presence of multiple tags, but it doesn't allow me to test that the tags appear in a specific order.
Take the following RSpec example, for instance, which aims to test that alternating (odd, even, odd, even) rows are rendered to the view:
it 'should display the login names, display names and email address in alternating rows' do
response.should have_tag('div.odd>div') do
with_tag('div', 'example login name 1')
with_tag('div', 'example display name 1')
with_tag('div', 'example email address 1')
end
response.should have_tag('div.even>div') do
with_tag('div', 'example login name 2')
with_tag('div', 'example display name 2')
with_tag('div', 'example email address 2')
end
end
I can change the order of the have_tag blocks and I can also change the order of the with_tag calls within each block without breaking the specs. Or to put it alternatively, my view can render the "odd" and "even" divs in a different order, or the nested divs inside each, without breaking the specs.
In many cases, this might not matter. But what if I want to test for alternating divs (odd, even, odd even)? I can add multiple have_tag assertions but their order won't be considered, so I'm not really testing the alternation, only for existence.
I originally posted a question about this to the RSpec users mailing list:
http://rubyforge.org/pipermail/rspec-users/2007-May/001639.html
I was advised that assert_select would need to be extended to implement order-sensitivity, hence this enhancement request.