Skip to content

Commit c0688b4

Browse files
authored
Merge pull request #90 from seanpdoyle/substitution-types
Expand Substitution Matching Types support
2 parents 1cfcd00 + 288aa9e commit c0688b4

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,14 @@ def css_select(*args)
9696
# assert_select "li", 8
9797
# end
9898
#
99-
# The selector may be a CSS selector expression (String) or an expression
99+
# The selector may be a CSS selector expression (String, Symbol, or Numeric) or an expression
100100
# with substitution values (Array).
101101
# Substitution uses a custom pseudo class match. Pass in whatever attribute you want to match (enclosed in quotes) and a ? for the substitution.
102102
# assert_select returns nil if called with an invalid css selector.
103103
#
104+
# assert_select "div:match('id', ?)", "id_string"
105+
# assert_select "div:match('id', ?)", :id_string
106+
# assert_select "div:match('id', ?)", 1
104107
# assert_select "div:match('id', ?)", /\d+/
105108
#
106109
# === Equality Tests

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)