Skip to content

Commit

Permalink
Merge pull request #96 from ghiculescu/wrong-message-arg
Browse files Browse the repository at this point in the history
Raise an error if the last arg is the wrong format
  • Loading branch information
rafaelfranca authored Nov 2, 2021
2 parents 8f5acdf + 4ab6bfd commit b97b9de
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
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

0 comments on commit b97b9de

Please sign in to comment.