diff options
author | Timm <kaspth@gmail.com> | 2013-08-01 22:41:12 +0200 |
---|---|---|
committer | Timm <kaspth@gmail.com> | 2014-06-16 21:04:00 +0200 |
commit | 6fd74dc00e8207b981d982bc8b5842859c2589a6 (patch) | |
tree | 3226f0d24fc26db0a2833aee2807dfef9116a459 /actionpack/lib | |
parent | 9020abe0e92c78085ba2b826d442701921ff88ac (diff) | |
download | rails-6fd74dc00e8207b981d982bc8b5842859c2589a6.tar.gz rails-6fd74dc00e8207b981d982bc8b5842859c2589a6.tar.bz2 rails-6fd74dc00e8207b981d982bc8b5842859c2589a6.zip |
Updated documentation to state more things about css selectors with substitution values.
Diffstat (limited to 'actionpack/lib')
-rw-r--r-- | actionpack/lib/action_dispatch/testing/assertions/selector.rb | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/actionpack/lib/action_dispatch/testing/assertions/selector.rb b/actionpack/lib/action_dispatch/testing/assertions/selector.rb index 167c80cd98..fea9b8daa0 100644 --- a/actionpack/lib/action_dispatch/testing/assertions/selector.rb +++ b/actionpack/lib/action_dispatch/testing/assertions/selector.rb @@ -33,10 +33,12 @@ module ActionDispatch # If called with two arguments, uses the first argument as the root # element and the second argument as the selector. Attempts to match the # root element and any of its children. - # Returns empty Nokogiri::XML::NodeSet if no match is found. + # Returns an empty Nokogiri::XML::NodeSet if no match is found. # # The selector may be a CSS selector expression (String) or an expression # with substitution values (Array). + # Substitution uses a custom pseudo class match. + # Pass in whatever attribute you want to match (enclosed in quotes) and a ? for the substitution. # # # Selects all div tags # divs = css_select("div") @@ -56,6 +58,9 @@ module ActionDispatch # inputs = css_select(form, "input") # ... # end + # + # # Selects div tags with ids matching regex + # css_select "div:match('id', ?)", /\d+/ def css_select(*args) raise ArgumentError, "you at least need a selector" if args.empty? @@ -103,6 +108,9 @@ module ActionDispatch # # The selector may be a CSS selector expression (String) or an expression # with substitution values (Array). + # Substitution uses a custom pseudo class match. Pass in whatever attribute you want to match (enclosed in quotes) and a ? for the substitution. + # + # assert_select "div:match('id', ?)", /\d+/ # # === Equality Tests # @@ -153,11 +161,11 @@ module ActionDispatch # assert_select "body div.header ul.menu" # # # Use substitution values - # assert_select "ol>li#?", /item-\d+/ + # assert_select "ol>li:match('id', ?)", /item-\d+/ # # # All input fields in the form have a name # assert_select "form input" do - # assert_select "[name=?]", /.+/ # Not empty + # assert_select ":match('name', ?)", /.+/ # Not empty # end def assert_select(*args, &block) @selected ||= nil |