test/unit/utils_tests.rb in assert-2.4.0 vs test/unit/utils_tests.rb in assert-2.5.0

- old
+ new

@@ -1,9 +1,10 @@ require 'assert' require 'assert/utils' require 'tempfile' +require 'assert/config' module Assert::Utils class UnitTests < Assert::Context desc "Assert::Utils" @@ -13,59 +14,52 @@ end should have_imeths :show, :show_for_diff should have_imeths :tempfile should have_imeths :stdlib_pp_proc, :default_use_diff_proc, :syscmd_diff_proc + should have_imeths :git_changed_proc end class ShowTests < UnitTests desc "`show`" setup do - @orig_pp_objs = Assert.config.pp_objects - @orig_pp_proc = Assert.config.pp_proc - @new_pp_proc = Proc.new{ |input| 'herp derp' } + @pp_config = Assert::Config.new({ + :pp_objects => true, + :pp_proc => Proc.new{ |input| 'herp derp' } + }) end - teardown do - Assert.config.pp_proc(@orig_pp_proc) - Assert.config.pp_objects(@orig_pp_objs) - end should "use `inspect` to show objs when `pp_objects` setting is false" do - Assert.config.pp_objects(false) - @objs.each do |obj| - assert_equal obj.inspect, subject.show(obj) + assert_equal obj.inspect, subject.show(obj, Factory.modes_off_config) end end should "use `pp_proc` to show objs when `pp_objects` setting is true" do - Assert.config.pp_objects(true) - Assert.config.pp_proc(@new_pp_proc) - @objs.each do |obj| - assert_equal @new_pp_proc.call(obj), subject.show(obj) + assert_equal @pp_config.pp_proc.call(obj), subject.show(obj, @pp_config) end end end - class ShowForDiffTests < UnitTests + class ShowForDiffTests < ShowTests desc "`show_for_diff`" setup do @w_newlines = { :string => "herp derp, derp herp\nherpderpedia" } @w_obj_id = Struct.new(:a, :b).new('aye', 'bee') end should "call show, escaping newlines" do exp_out = "{:string=>\"herp derp, derp herp\nherpderpedia\"}" - assert_equal exp_out, subject.show_for_diff(@w_newlines) + assert_equal exp_out, subject.show_for_diff(@w_newlines, Factory.modes_off_config) end should "make any obj ids generic" do exp_out = "#<struct #<Class:0xXXXXXX> a=\"aye\", b=\"bee\">" - assert_equal exp_out, subject.show_for_diff(@w_obj_id) + assert_equal exp_out, subject.show_for_diff(@w_obj_id, Factory.modes_off_config) end end class TempfileTests < UnitTests @@ -86,16 +80,16 @@ class StdlibPpProcTests < UnitTests desc "`stdlib_pp_proc`" should "build a pp proc that uses stdlib `PP.pp` to pretty print objects" do - exp_obj_pps = @objs.map{ |o| "\n#{PP.pp(o, '', 79).strip}\n" } + exp_obj_pps = @objs.map{ |o| PP.pp(o, '', 79).strip } act_obj_pps = @objs.map{ |o| subject.stdlib_pp_proc.call(o) } assert_equal exp_obj_pps, act_obj_pps cust_width = 1 - exp_obj_pps = @objs.map{ |o| "\n#{PP.pp(o, '', cust_width).strip}\n" } + exp_obj_pps = @objs.map{ |o| PP.pp(o, '', cust_width).strip } act_obj_pps = @objs.map{ |o| subject.stdlib_pp_proc(cust_width).call(o) } assert_equal exp_obj_pps, act_obj_pps end end @@ -129,20 +123,20 @@ @diff_a = File.read(@diff_a_file) @diff_b = File.read(@diff_b_file) end should "use the diff syscmd to output the diff between the exp/act show output" do - exp_diff_out = `diff --unified=-1 #{@diff_a_file} #{@diff_b_file}`.tap do |out| + exp_diff_out = `diff --unified=-1 #{@diff_a_file} #{@diff_b_file}`.strip.tap do |out| out.sub!(/^\-\-\- .+/, "--- expected") out.sub!(/^\+\+\+ .+/, "+++ actual") end assert_equal exp_diff_out, subject.syscmd_diff_proc.call(@diff_a, @diff_b) end should "allow you to specify a custom syscmd" do cust_syscmd = 'diff' - exp_diff_out = `#{cust_syscmd} #{@diff_a_file} #{@diff_b_file}`.tap do |out| + exp_diff_out = `#{cust_syscmd} #{@diff_a_file} #{@diff_b_file}`.strip.tap do |out| out.sub!(/^\-\-\- .+/, "--- expected") out.sub!(/^\+\+\+ .+/, "+++ actual") end assert_equal exp_diff_out, subject.syscmd_diff_proc(cust_syscmd).call(@diff_a, @diff_b)