Skip to content

Commit f94ac0a

Browse files
committed
Remove quotes from Regexp when printing error messages.
Already found a way to make this look nicer. Since the `@css_selector` is purely for presentation and never hits Nokogiri it doesn't have to be in quotes and we can make it look like the what the user put in. Replaces `div:match\('id',\ "\/wups\/"\)` with `div:match('id', /wups/)`.
1 parent 946a801 commit f94ac0a

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@ def match(matches, attribute, matcher)
1919

2020
private
2121
def matcher_for(value, format_for_presentation)
22-
if format_for_presentation && value.is_a?(Regexp)
23-
value = value.inspect # Inspect Regexps for readability in error messages.
22+
# Nokogiri doesn't like arbitrary values without quotes, hence inspect.
23+
if format_for_presentation
24+
value.inspect # Avoid to_s so Regexps aren't put in quotes.
25+
else
26+
value.to_s.inspect
2427
end
25-
26-
value.to_s.inspect # Nokogiri doesn't like arbitrary values without quotes, hence inspect.
2728
end
2829

2930
def substitutable?(value)

test/selector_assertions_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ def test_nested_assert_select_with_match_failure_shows_nice_regex
239239
assert_select "div:match('id', ?)", /wups/
240240
end
241241

242-
assert_match %Q{div:match('id', "/wups/")}, error.message
242+
assert_match %Q{div:match('id', /wups/)}, error.message
243243
end
244244

245245
def test_feed_item_encoded

0 commit comments

Comments
 (0)