Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expand Substitution Matching Types support #90

Merged
merged 1 commit into from
Dec 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/rails/dom/testing/assertions/selector_assertions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,14 @@ def css_select(*args)
# assert_select "li", 8
# end
#
# The selector may be a CSS selector expression (String) or an expression
# The selector may be a CSS selector expression (String, Symbol, or Numeric) or an expression
# with substitution values (Array).
# Substitution uses a custom pseudo class match. Pass in whatever attribute you want to match (enclosed in quotes) and a ? for the substitution.
# assert_select returns nil if called with an invalid css selector.
#
# assert_select "div:match('id', ?)", "id_string"
# assert_select "div:match('id', ?)", :id_string
# assert_select "div:match('id', ?)", 1
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kaspth is this what you had in mind?

# assert_select "div:match('id', ?)", /\d+/
#
# === Equality Tests
Expand Down
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