diff options
author | Timm <kaspth@gmail.com> | 2013-07-30 14:45:12 +0200 |
---|---|---|
committer | Timm <kaspth@gmail.com> | 2014-06-16 21:03:57 +0200 |
commit | 22aa73b3ee1491b5a1b4271b4f85b53c40f11ff3 (patch) | |
tree | 2864b43899137ac63755d5b65c97c1e423bba83e /actionpack/lib/action_dispatch/testing | |
parent | 99ac0cdcad5584fb1347866532749355dc597429 (diff) | |
download | rails-22aa73b3ee1491b5a1b4271b4f85b53c40f11ff3.tar.gz rails-22aa73b3ee1491b5a1b4271b4f85b53c40f11ff3.tar.bz2 rails-22aa73b3ee1491b5a1b4271b4f85b53c40f11ff3.zip |
Cleaned up SubstitutionContext class.
Diffstat (limited to 'actionpack/lib/action_dispatch/testing')
-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 |