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

Use Minitest::Assertion#diff for content failure messages #106

Merged
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
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