Skip to content

Commit f2a7eb4

Browse files
committed
Remove substitution_ids and interpret every matcher as a Regexp.
1 parent 2427c8f commit f2a7eb4

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

lib/rails/dom/testing/assertions/selector_assertions/substitution_context.rb

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,21 @@
11
class SubstitutionContext
22
def initialize
33
@substitute = '?'
4-
@regexes = []
54
end
65

76
def substitute!(selector, values)
87
while !values.empty? && substitutable?(values.first) && selector.index(@substitute)
9-
selector.sub! @substitute, substitution_id_for(values.shift)
8+
selector.sub! @substitute, matcher_for(values.shift)
109
end
1110
end
1211

13-
def match(matches, attribute, substitution_id)
14-
matches.find_all { |node| node[attribute] =~ @regexes[substitution_id] }
12+
def match(matches, attribute, matcher)
13+
matches.find_all { |node| node[attribute] =~ Regexp.new(matcher) }
1514
end
1615

1716
private
18-
def substitution_id_for(value)
19-
if value.is_a?(Regexp)
20-
@regexes << value
21-
@regexes.size - 1
22-
else
23-
value
24-
end.inspect # Nokogiri doesn't like arbitrary values without quotes, hence inspect.
17+
def matcher_for(value)
18+
value.to_s.inspect # Nokogiri doesn't like arbitrary values without quotes, hence inspect.
2519
end
2620

2721
def substitutable?(value)

0 commit comments

Comments
 (0)