Skip to content

Commit

Permalink
Fallback to diff_strings when assert_equal_* has no syntactic cha…
Browse files Browse the repository at this point in the history
…nges
  • Loading branch information
marcoroth committed Jan 28, 2025
1 parent ef9e495 commit f9cb9e4
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/quickdraw/assertions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def assert_equal_sql(actual, expected)

assert(actual == expected) do
diff = DIFFER.diff_sql(actual, expected)
diff = DIFFER.diff_strings(actual, expected) if no_syntactic_changes?(diff)

"Expected SQL strings to be equal (compared with `actual == expected`):\n\n#{diff}"
end
Expand All @@ -35,6 +36,7 @@ def assert_equal_html(actual, expected)

assert(actual == expected) do
diff = DIFFER.diff_html(actual, expected)
diff = DIFFER.diff_strings(actual, expected) if no_syntactic_changes?(diff)

"Expected HTML strings to be equal (compared with `actual == expected`):\n\n#{diff}"
end
Expand All @@ -47,6 +49,7 @@ def assert_equal_ruby(actual, expected)

assert(actual == expected) do
diff = DIFFER.diff_ruby(actual, expected)
diff = DIFFER.diff_strings(actual, expected) if no_syntactic_changes?(diff)

"Expected Ruby strings to be equal (compared with `actual == expected`):\n\n#{diff}"
end
Expand Down Expand Up @@ -151,4 +154,14 @@ def refute_same(actual, expected)
"expected #{actual.inspect} not to be the same object as #{expected.inspect}"
end
end

private

def syntactic_changes?(diff)
!no_syntactic_changes?(diff)
end

def no_syntactic_changes?(diff)
diff.include?("No syntactic changes.")
end
end

0 comments on commit f9cb9e4

Please sign in to comment.