Closed speckins closed 2 years ago
Using String#gsub
would fix the "replacing the replacement" problem, but the block form behaves differently than the replacement-as-argument form and requires an additional #sub
to "unescape" the backslashes.
def substitute!(selector, values, format_for_presentation = false)
selector.gsub @substitute do |match|
next match[0] if values.empty? || !substitutable?(values.first)
matcher_for(values.shift, format_for_presentation).sub '\\\\', '\\'
end
end
When passing multiple patterns to #assert_select, an invalid selector is built because of the question mark (?) included in the substitution, "(?-mix:pattern)".
Here's a test case. I ran it from the test/ directory of this repo with Ruby 2.5.1.
The problem is in
SubstitutionContext#substitute!
whenformat_for_presentation
is false. On the first iteration, the first question mark is replaced with a string that also contains a question mark:On the second iteration, instead of replacing the next question mark, the one from the replacement is itself replaced: