lib/rails/dom/testing/assertions/selector_assertions.rb in rails-dom-testing-1.0.2 vs lib/rails/dom/testing/assertions/selector_assertions.rb in rails-dom-testing-1.0.3

- old
+ new

@@ -59,12 +59,15 @@ raise ArgumentError, "you at least need a selector argument" if args.empty? root = args.size == 1 ? document_root_element : args.shift selector = args.first - catch_invalid_selector do + begin nodeset(root).css(selector) + rescue Nokogiri::CSS::SyntaxError => e + ActiveSupport::Deprecation.warn("The assertion was not run because of an invalid css selector.\n#{e}", caller(2)) + return end end # An assertion that selects elements and makes one or more equality tests. # @@ -165,14 +168,18 @@ root = determine_root_from(args, @selected) selector = HTMLSelector.new(root, args) matches = nil - catch_invalid_selector do + + begin matches = selector.select assert_size_match!(matches.size, selector.equality_tests, selector.source, selector.message) + rescue Nokogiri::CSS::SyntaxError => e + ActiveSupport::Deprecation.warn("The assertion was not run because of an invalid css selector.\n#{e}", caller(2)) + return end nest_selection(matches, &block) if block_given? && !matches.empty? matches @@ -276,19 +283,10 @@ def document_root_element raise NotImplementedError, "Implementing document_root_element makes assert_select work without needing to specify an element to select from." end - def catch_invalid_selector - begin - yield - rescue Nokogiri::CSS::SyntaxError => e - ActiveSupport::Deprecation.warn("The assertion was not run because of an invalid css selector.\n#{e}") - return - end - end - # +equals+ must contain :minimum, :maximum and :count keys def assert_size_match!(size, equals, css_selector, message = nil) min, max, count = equals[:minimum], equals[:maximum], equals[:count] message ||= %(Expected #{count_description(min, max, count)} matching "#{css_selector}", found #{size}.) @@ -308,10 +306,10 @@ args.shift # remove the root, so selector is the first argument possible_root elsif previous_selection previous_selection else - document_root_element + nodeset document_root_element end end def nest_selection(selection) # Set @selected to allow nested assert_select.