module Asciidoctor::DocTest::MinitestDiffy

Module to be included into Minitest::Test to use Diffy for diff.

Public Class Methods

included(base) click to toggle source

@private

# File lib/asciidoctor/doctest/minitest_diffy.rb, line 13
def self.included(base)
  base.make_my_diffs_pretty!
end

Public Instance Methods

diff(exp, act) click to toggle source

Returns diff between exp and act (if needed) using Diffy.

@note Overrides method from Minitest::Assertions.

# File lib/asciidoctor/doctest/minitest_diffy.rb, line 21
def diff(exp, act)
  expected = mu_pp_for_diff(exp)
  actual = mu_pp_for_diff(act)

  if need_diff? expected, actual
    ::Diffy::Diff.new(expected, actual, context: 3).to_s
  else
    "Expected: #{mu_pp(exp)}\n  Actual: #{mu_pp(act)}"
  end
end
need_diff?(expected, actual) click to toggle source

Returns true if diff should be printed (using Diffy) for the given content, false otherwise.

@param expected [String] @param actual [String]

# File lib/asciidoctor/doctest/minitest_diffy.rb, line 39
def need_diff?(expected, actual)
  expected.include?("\n") ||
    actual.include?("\n") ||
    expected.size > 30    ||
    actual.size > 30      ||
    expected == actual
end