Skip to content
Open
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
4 changes: 4 additions & 0 deletions History.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### Fixed

* `assert_selector` can accept `Hash` instance as locator [Sean Doyle]

# Version 3.40.0
Release date: 2024-01-26

Expand Down
2 changes: 1 addition & 1 deletion lib/capybara/node/matchers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,7 @@ def _verify_text(type = nil, expected_text, **query_options) # rubocop:disable S
def _set_query_session_options(*query_args)
query_args, query_options = query_args.dup, {}
# query_options = query_args.pop if query_options.empty? && query_args.last.is_a?(Hash)
query_options = query_args.pop if query_args.last.is_a?(Hash)
query_options = query_args.pop if query_args.last.is_a?(Hash) && query_args.last.keys.none?(String)
Copy link
Contributor Author

@seanpdoyle seanpdoyle Sep 17, 2025

Choose a reason for hiding this comment

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

I'm pretty dissatisfied with this solution. Since it's related to positional-to-keyword argument coercion, I wonder if there's a more wholistic approach that could be take to resolve this. For example, this would still fail for symbol keys that aren't filter options:

assert_selector :table_row, First: "John", Last: "Doe"

query_options[:session_options] = session_options
[query_args, query_options]
end
Expand Down
3 changes: 2 additions & 1 deletion spec/minitest_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ def test_assert_table
assert_table('agent_table')
assert_no_table('not_on_form')
refute_table('not_on_form')
assert_selector(:table_row, 'First Name' => 'Thomas')
end

def test_assert_all_of_selectors
Expand Down Expand Up @@ -170,6 +171,6 @@ def test_assert_sibling
reporter.start
MinitestTest.run reporter, {}
reporter.report
expect(output.string).to include('23 runs, 56 assertions, 0 failures, 0 errors, 1 skips')
expect(output.string).to include('23 runs, 57 assertions, 0 failures, 0 errors, 1 skips')
end
end