Module: Difftastic::Patches::AssertPredicate

Defined in:
lib/minitest/difftastic/patches/assert_predicate.rb

Instance Method Summary collapse

Instance Method Details

#assert_predicate(object, predicate, msg = nil) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/minitest/difftastic/patches/assert_predicate.rb', line 6

def assert_predicate(object, predicate, msg = nil)
  msg ||= message(nil, "") {
    pretty = Difftastic.pretty(object)

    expected = <<~RUBY
      #{pretty}.#{predicate}

      # => true
    RUBY

    actual = <<~RUBY
      #{pretty}.#{predicate}

      # => false
    RUBY

    differ = ::Difftastic::Differ.new(
      color: :always,
      tab_width: 2,
      syntax_highlight: :on,
      left_label: "Expected",
      right_label: "Actual",
      context: expected.lines.count
    )

    "\n#{differ.diff_ruby(expected, actual)}"
  }

  super
rescue StandardError
  super
end