Skip to content

Commit

Permalink
Merge pull request #106 from flavorjones/flavorjones-better-failure-diff
Browse files Browse the repository at this point in the history
Use Minitest::Assertion#diff for content failure messages
  • Loading branch information
rafaelfranca committed Jun 26, 2023
2 parents 8deceed + a7157c2 commit 55fd781
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/rails/dom/testing/assertions/selector_assertions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ def document_root_element
def assert_size_match!(size, equals, css_selector, message = nil)
min, max, count = equals[:minimum], equals[:maximum], equals[:count]

message ||= %(Expected #{count_description(min, max, count)} matching "#{css_selector}", found #{size}.)
message ||= %(Expected #{count_description(min, max, count)} matching #{css_selector.inspect}, found #{size})
if count
assert_equal count, size, message
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
class HTMLSelector #:nodoc:
attr_reader :css_selector, :tests, :message

include Minitest::Assertions

def initialize(values, previous_selection = nil, &root_fallback)
@values = values
@root = extract_root(previous_selection, root_fallback)
Expand Down Expand Up @@ -52,7 +54,7 @@ def filter(matches)
content.sub!(/\A\n/, '') if text_matches && match.name == "textarea"

next if regex_matching ? (content =~ match_with) : (content == match_with)
content_mismatch ||= sprintf("<%s> expected but was\n<%s>", match_with, content)
content_mismatch ||= diff(match_with, content)
true
end

Expand Down

0 comments on commit 55fd781

Please sign in to comment.