Alternative to assert_tag that uses CSS selectors for a more readable and concise syntax.
Examples:
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
The patch adds HTML::Selector to the html-scanner library, supporting CSS Level 3 selectors including pseudo classes and substitution values (see example above).
The patch adds the following methods to Test::Unit::TestCase:
* assert_select for -- Assertions on the result of a view or enclosing assertion (for nested assertions).
* css_select -- Selects elements without asserting.
* assert_select_rjs -- Extracts HTML from an RJS update or insert.
* assert_select_feed -- Supports assertions on an RSS or Atom feed.
* assert_select_encoded -- Used for encoded content in RSS/Atom feeds.
* assert_select_email -- For HTML e-mails.
The last four are convenient methods for extracting different types of output. Use assert_select within a block to make assertions on the output.
For more info see Testing with CSS selectors, assert_select plugin for Rails and All posts on assert_select.