
assert_select is up for inclusion in Rails core. It simplified my life, and I hope we can do the same for other Rails developers. So head over to the Ruby on Rails blog and voice your opinion.
And incidentally, I just did a major new release of assert_select, adding some features I needed for my recent test cases. The most important one, it’s now easier to test lists, tables, forms and anything that has structure and repetition using nested assertions.
For example:
assert_select “form[action=http://test.host/login]†do
assert_select “input[name=username]â€
assert_select “input[name=password]â€
end
assert_select “ol>li†do
# List item has an ID we can relate to.
assert_select “li#?â€, /item-\d+/
assert_select “pâ€
# And a link to that resource.
assert_select “a[href=?]â€, /item\/\d+/
end
Testing flash[:notice]:
assert_select "div#notice", flash[:notice] || false
Testing for text will now match (string or regular expression) every selected element against that text. And as you can see from the above examples, it’s now easier to work with substitution values.
Install and use with:
./script/plugins install http://labnotes.org/svn/public/ruby/rails_plugins/assert_select