Skip to content

Commit

Permalink
Expand Substitution Matching Types support
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
seanpdoyle committed Dec 3, 2020
1 parent 1cfcd00 commit 0f01be0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ def matcher_for(value, format_for_presentation)
end

def substitutable?(value)
value.is_a?(String) || value.is_a?(Regexp)
[ Symbol, Numeric, String, Regexp ].any? { |type| value.is_a? type }
end
end
10 changes: 10 additions & 0 deletions test/selector_assertions_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,16 @@ def test_substitution_values
end
end

def test_substitution_values_with_values_other_than_string_or_regexp
render_html %Q{<div id="id_string">symbol</div><div id="1">numeric</div>}
assert_select "div:match('id', ?)", :id_string do |elements|
assert_equal 1, elements.size
end
assert_select "div:match('id', ?)", 1 do |elements|
assert_equal 1, elements.size
end
end

def test_assert_select_root_html
render_html '<a></a>'

Expand Down

0 comments on commit 0f01be0

Please sign in to comment.