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

Raise an error if the last arg is the wrong format #96

Merged
merged 1 commit into from
Nov 2, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ def initialize(values, previous_selection = nil, &root_fallback)
@tests = extract_equality_tests
@message = @values.shift

if @message.is_a?(Hash)
raise ArgumentError, "Last argument was a Hash, which would be used for the assertion message. You probably want this to be a String, or you have the wrong type of arguments."
end

if @values.shift
raise ArgumentError, "Not expecting that last argument, you either have too many arguments, or they're the wrong type"
end
Expand Down
10 changes: 10 additions & 0 deletions test/selector_assertions_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,16 @@ def test_body_class_can_be_tested_with_html
assert_select '.foo'
end

def test_assert_select_with_extra_argument
render_html '<html><head><title>Welcome</title></head><body><div></div></body></html>'

assert_raises ArgumentError do
assert_select "title", "Welcome", count: 1
end

assert_select "title", text: "Welcome", count: 1
end

protected
def render_html(html)
fake_render(:html, html)
Expand Down