method
diff
ruby latest stable - Class:
MiniTest::Assertions
Method deprecated or moved
This method is deprecated or moved on the latest stable version. The last existing version (v2_1_10) is shown here.
diff(exp, act)public
Returns a diff between exp and act. If there is no known diff command or if it doesn’t make sense to diff the output (single line, short output), then it simply returns a basic comparison between the two.
# File lib/minitest/unit.rb, line 119
def diff exp, act
require "tempfile"
expect = mu_pp_for_diff exp
butwas = mu_pp_for_diff act
result = nil
need_to_diff =
MiniTest::Assertions.diff &&
(expect.include?("\n") ||
butwas.include?("\n") ||
expect.size > 30 ||
butwas.size > 30 ||
expect == butwas)
return "Expected: #{mu_pp exp}\n Actual: #{mu_pp act}" unless
need_to_diff
Tempfile.open("expect") do |a|
a.puts expect
a.flush
Tempfile.open("butwas") do |b|
b.puts butwas
b.flush
result = `#{MiniTest::Assertions.diff} #{a.path} #{b.path}`
result.sub!(/^\-\-\- .+/, "--- expected")
result.sub!(/^\+\+\+ .+/, "+++ actual")
if result.empty? then
klass = exp.class
result = [
"No visible difference in the #{klass}#inspect output.\n",
"You should look at the implementation of #== on ",
"#{klass} or its members.\n",
expect,
].join
end
end
end
result
end Related methods
- Instance methods
- _assertions
- _assertions=
- assert
- assert_empty
- assert_equal
- assert_in_delta
- assert_in_epsilon
- assert_includes
- assert_instance_of
- assert_kind_of
- assert_match
- assert_nil
- assert_operator
- assert_output
- assert_predicate
- assert_raises
- assert_respond_to
- assert_same
- assert_send
- assert_silent
- assert_throws
- capture_io
- capture_subprocess_io
- diff
- exception_details
- flunk
- message
- mu_pp
- mu_pp_for_diff
- pass
- refute
- refute_empty
- refute_equal
- refute_in_delta
- refute_in_epsilon
- refute_includes
- refute_instance_of
- refute_kind_of
- refute_match
- refute_nil
- refute_operator
- refute_predicate
- refute_respond_to
- refute_same
- skip
- skipped?
- synchronize
- Class methods
- diff
- diff=