Module: Asciidoctor::DocTest::MinitestDiffy

Included in:
Tester::MinitestSingleTest
Defined in:
lib/asciidoctor/doctest/minitest_diffy.rb

Overview

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



14
15
16
# File 'lib/asciidoctor/doctest/minitest_diffy.rb', line 14

def self.included(base)
  base.make_my_diffs_pretty!
end

Instance Method Details

#diff(exp, act) ⇒ Object

Note:

Overrides method from Minitest::Assertions.

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



22
23
24
25
26
27
28
29
30
31
# File 'lib/asciidoctor/doctest/minitest_diffy.rb', line 22

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) ⇒ Boolean

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

Parameters:

  • expected (String)
  • actual (String)

Returns:

  • (Boolean)


40
41
42
43
44
45
46
# File 'lib/asciidoctor/doctest/minitest_diffy.rb', line 40

def need_diff?(expected, actual)
  expected.include?("\n") ||
    actual.include?("\n") ||
    expected.size > 30    ||
    actual.size > 30      ||
    expected == actual
end