Module: MiniTest::Assertions
- Defined in:
- lib/nandoc/extlib/minitest.rb
Instance Method Summary collapse
-
#assert_no_diff(exp, act, msg = nil, opts = {}) ⇒ Object
Fails unless
exp == act
.
Instance Method Details
#assert_no_diff(exp, act, msg = nil, opts = {}) ⇒ Object
Fails unless exp == act
. On failure use diff to show the diff, if exp
and act
are of the same class and
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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/nandoc/extlib/minitest.rb', line 13 def assert_no_diff exp, act, msg=nil, opts={} if opts.kind_of?(String) opts = {:sep=>opts} end opts = {:sep=>"\n"}.merge(opts) msg = (msg) do exp_kind, act_kind = [exp,act].map do |x| [String, Array].detect{|c| x.kind_of?(c)} end if exp_kind != act_kind "Expecting #{exp_kind.inspect} had #{act_kind.inspect}" elsif exp_kind.nil? "Will only do diff for strings and arrays, not #{exp.class}" else differ = DiffToString.gitlike! if exp_kind == String use_exp = exp.split(opts[:sep], -1) use_act = act.split(opts[:sep], -1) else use_exp = exp use_act = act end diff = Diff::LCS.diff(use_exp, use_act) if diff.empty? fail("test test fail -- never expecting empty diff here") else differ.arr1 = use_exp differ.arr2 = use_act # awful differ.diff_to_str(diff, :context=>3) end end end if re = opts[:ignoring] exp, act = [exp, act].map do |str| str.kind_of?(String) ? str.gsub(re, re.source) : str end end assert(exp == act, msg) end |