Readded some documentation about substitution values.

This commit is contained in:
Timm 2013-07-24 13:12:27 +02:00
parent e4772cc71e
commit 9eada2daf8
2 changed files with 15 additions and 5 deletions

@ -35,7 +35,8 @@ module SelectorAssertions
# root element and any of its children.
# Returns empty Nokogiri::XML::NodeSet if no match is found.
#
# The selector may be a CSS selector expression (String).
# The selector may be a CSS selector expression (String) or an expression
# with substitution values (Array).
#
# # Selects all div tags
# divs = css_select("div")
@ -96,7 +97,8 @@ def css_select(*args)
# assert_select "li", 8
# end
#
# The selector may be a CSS selector expression (String).
# The selector may be a CSS selector expression (String) or an expression
# with substitution values (Array).
#
# === Equality Tests
#
@ -145,6 +147,14 @@ def css_select(*args)
#
# # Test the content and style
# assert_select "body div.header ul.menu"
#
# # Use substitution values
# assert_select "ol>li#?", /item-\d+/
#
# # All input fields in the form have a name
# assert_select "form input" do
# assert_select "[name=?]", /.+/ # Not empty
# end
def assert_select(*args, &block)
@selected ||= nil

@ -597,13 +597,13 @@ end
Testing the response to your request by asserting the presence of key HTML elements and their content is a useful way to test the views of your application. The `assert_select` assertion allows you to do this by using a simple yet powerful syntax.
NOTE: You may find references to `assert_tag` in other documentation. This has been removed in 4.1. Use `assert_select` instead.
NOTE: You may find references to `assert_tag` in other documentation. This has been removed in 4.2. Use `assert_select` instead.
There are two forms of `assert_select`:
`assert_select(selector, [equality], [message])` ensures that the equality condition is met on the selected elements through the selector. The selector may be a CSS selector expression (String) or an expression with substitution values.
`assert_select(element, selector, [equality], [message])` ensures that the equality condition is met on all the selected elements through the selector starting from the _element_ (instance of `Nokogiri::XML::Node`) and its descendants.
`assert_select(element, selector, [equality], [message])` ensures that the equality condition is met on all the selected elements through the selector starting from the _element_ (instance of `Nokogiri::XML::Node` or `Nokogiri::XML::NodeSet`) and its descendants.
For example, you could verify the contents on the title element in your response with:
@ -633,7 +633,7 @@ assert_select "ol" do
end
```
The `assert_select` assertion is quite powerful. For more advanced usage, refer to its [documentation](http://api.rubyonrails.org/classes/ActionDispatch/Assertions/SelectorAssertions.html).
The `assert_select` assertion is quite powerful. For more advanced usage, refer to its [documentation](https://github.com/rails/rails-dom-testing/blob/master/lib/rails/dom/testing/assertions/selector_assertions.rb).
#### Additional View-Based Assertions