Skip to content

Commit 0f01be0

Browse files
committed
Expand Substitution Matching Types support
Add substitution support for `Symbol` and `Numeric`. It can be convenient to pass in the value of an `ActiveRecord::Base#id`, or a `Symbol` declared elsewhere in the test.
1 parent 1cfcd00 commit 0f01be0

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ def matcher_for(value, format_for_presentation)
2828
end
2929

3030
def substitutable?(value)
31-
value.is_a?(String) || value.is_a?(Regexp)
31+
[ Symbol, Numeric, String, Regexp ].any? { |type| value.is_a? type }
3232
end
3333
end

test/selector_assertions_test.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,16 @@ def test_substitution_values
135135
end
136136
end
137137

138+
def test_substitution_values_with_values_other_than_string_or_regexp
139+
render_html %Q{<div id="id_string">symbol</div><div id="1">numeric</div>}
140+
assert_select "div:match('id', ?)", :id_string do |elements|
141+
assert_equal 1, elements.size
142+
end
143+
assert_select "div:match('id', ?)", 1 do |elements|
144+
assert_equal 1, elements.size
145+
end
146+
end
147+
138148
def test_assert_select_root_html
139149
render_html '<a></a>'
140150

0 commit comments

Comments
 (0)