Module: Asciidoctor::DocTest::MinitestDiffy
- Included in:
- Test
- 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
-
#diff(exp, act) ⇒ Object
Returns diff between
expandact(if needed) using Diffy. -
#need_diff?(expected, actual) ⇒ Boolean
Returns
trueif diff should be printed (using Diffy) for the given content,falseotherwise.
Class Method Details
.included(base) ⇒ Object
11 12 13 |
# File 'lib/asciidoctor/doctest/minitest_diffy.rb', line 11 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.
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/asciidoctor/doctest/minitest_diffy.rb', line 19 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.
37 38 39 40 41 42 43 |
# File 'lib/asciidoctor/doctest/minitest_diffy.rb', line 37 def need_diff?(expected, actual) expected.include?("\n") || actual.include?("\n") || expected.size > 30 || actual.size > 30 || expected == actual end |