Browse the Ruby on Rails Community.

You are here: Browse Railsplugins Assert Select

Assert Select

= assert_select plugin for Rails

Adds the assert_select method for use in Rails functional tests. Simplifies content testing using CSS selectors.

You can use assert_select to select elements from the controller response page and perform equality tests.

You can test that the selected element(s) exist, has specific text content, or test the number of elements selected.

Elements are selected using CSS selectors. You can use the same CSS selectors to style the HTML page and test its content.

See Test::Unit::AssertSelect and HTML::Selector for more information.

Examples
  1. At least one form element assert_select “form”
  1. Form element includes four input fields assert_select “form input”, 4
  1. Page title is “Welcome” assert_select “title”, “Welcome”
  1. Page title is “Welcome” and there is only one title element assert_select “title”, {:count=>1, :text=>”Welcome”}, “Wrong title or more than one title element”
  1. Page contains no forms assert_select “form”, false, “This page must contain no forms”
  1. Test the content and style assert_select “body div.header ul.menu”
  1. All input fields in the form have a name assert_select “form input” do |elements| elements.each do |element| assert not element.attributes[“name”].empty? end end
License

Copyright© 2006 Assaf Arkin, under Creative Commons Attribution and/or MIT License

Developed for http://co.mments.com

Code and documention: http://labnotes.org

NOTE: This description has been extracted from the Plugin README and so the formatting may need updating to make browser friendly