diff options
Diffstat (limited to 'actionpack/lib/action_dispatch')
-rw-r--r-- | actionpack/lib/action_dispatch/testing/assertions/selector.rb | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/actionpack/lib/action_dispatch/testing/assertions/selector.rb b/actionpack/lib/action_dispatch/testing/assertions/selector.rb index 59bd6dc3b4..235934f5f1 100644 --- a/actionpack/lib/action_dispatch/testing/assertions/selector.rb +++ b/actionpack/lib/action_dispatch/testing/assertions/selector.rb @@ -427,25 +427,23 @@ module ActionDispatch @regexes = [] end - def add(regex) + def add_regex(regex) + return regex unless regex.is_a?(Regexp) @regexes.push(regex) - id_for(regex) + last_id.to_s # avoid implicit conversions of Fixnum to String end - def id_for(regex) - @regexes.index(regex).to_s # to_s to store it in selector string + def last_id + @regexes.count - 1 end def match(matches, attribute, id) - matches.find_all { |node| node[attribute] =~ @regexes[id.to_i] } + matches.find_all { |node| node[attribute] =~ @regexes[id] } end def substitute!(selector, values) - while selector.index(@substitute) - break if values.empty? - value = values.shift - value = add(value) if value.is_a?(Regexp) - selector.sub!(@substitute, value) + while !values.empty? && selector.index(@substitute) + selector.sub!(@substitute, add_regex(values.shift)) end selector end |