From 6fd74dc00e8207b981d982bc8b5842859c2589a6 Mon Sep 17 00:00:00 2001 From: Timm Date: Thu, 1 Aug 2013 22:41:12 +0200 Subject: Updated documentation to state more things about css selectors with substitution values. --- .../lib/action_dispatch/testing/assertions/selector.rb | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'actionpack/lib/action_dispatch') 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 -- cgit v1.2.3