test/unit/context_tests.rb in assert-2.3.3 vs test/unit/context_tests.rb in assert-2.4.0

- old
+ new

@@ -1,11 +1,13 @@ require 'assert' require 'assert/context' +require 'assert/utils' + class Assert::Context - class BasicTests < Assert::Context + class UnitTests < Assert::Context desc "Assert context" setup do @test = Factory.test @context_class = @test.context_class @context = @context_class.new(@test) @@ -25,11 +27,11 @@ assert_equal self.class, this.context_info.klass end end - class SkipTests < BasicTests + class SkipTests < UnitTests desc "skip method" setup do @skip_msg = "I need to implement this in the future." begin; @context.skip(@skip_msg); rescue Exception => @exception; end @result = Factory.skip_result("something", @exception) @@ -42,11 +44,11 @@ assert_equal @skip_msg, subject.message end end - class IgnoreTests < BasicTests + class IgnoreTests < UnitTests desc "ignore method" setup do @ignore_msg = "Ignore this for now, will do later." @result = @context.ignore(@ignore_msg) end @@ -57,11 +59,11 @@ assert_equal @ignore_msg, subject.message end end - class PassTests < BasicTests + class PassTests < UnitTests desc "pass method" setup do @pass_msg = "That's right, it works." @result = @context.pass(@pass_msg) end @@ -72,11 +74,11 @@ assert_equal @pass_msg, subject.message end end - class FlunkTests < BasicTests + class FlunkTests < UnitTests desc "flunk method" setup do @flunk_msg = "It flunked." @result = @context.flunk(@flunk_msg) end @@ -87,11 +89,11 @@ assert_equal @flunk_msg, subject.message end end - class FailTests < BasicTests + class FailTests < UnitTests desc "fail method" setup do @result = @context.fail end subject{ @result } @@ -135,11 +137,11 @@ assert_equal @fail_msg, result.message end end - class AssertTests < BasicTests + class AssertTests < UnitTests desc "assert method" setup do @fail_desc = "my fail desc" @what_failed = "what failed" end @@ -151,10 +153,21 @@ end should "return a fail result given a `false` assertion" do result = subject.assert(false, @fail_desc){ @what_failed } assert_kind_of Assert::Result::Fail, result + end + + should "pp the assertion value in the fail message by default" do + exp_default_what = "Failed assert: assertion was `#{Assert::U.show(false)}`." + result = subject.assert(false, @fail_desc) + + assert_equal [@fail_desc, exp_default_what].join("\n"), result.message + end + + should "use a custom fail message if one is given" do + result = subject.assert(false, @fail_desc){ @what_failed } assert_equal [@fail_desc, @what_failed].join("\n"), result.message end should "return a pass result given a \"truthy\" assertion" do assert_kind_of Assert::Result::Pass, subject.assert(34) @@ -164,27 +177,32 @@ assert_kind_of Assert::Result::Fail, subject.assert(nil) end end - class AssertNotTests < BasicTests + class AssertNotTests < UnitTests desc "assert_not method" setup do @fail_desc = "my fail desc" - @what_failed = "Failed assert_not: assertion was <true>." end + should "return a pass result given a `false` assertion" do + result = subject.assert_not(false, @fail_desc) + assert_kind_of Assert::Result::Pass, result + assert_nil result.message + end + should "return a fail result given a `true` assertion" do result = subject.assert_not(true, @fail_desc) assert_kind_of Assert::Result::Fail, result - assert_equal [@fail_desc, @what_failed].join("\n"), result.message end - should "return a pass result given a `false` assertion" do - result = subject.assert_not(false, @fail_desc) - assert_kind_of Assert::Result::Pass, result - assert_nil result.message + should "pp the assertion value in the fail message by default" do + exp_default_what = "Failed assert_not: assertion was `#{Assert::U.show(true)}`." + result = subject.assert_not(true, @fail_desc) + + assert_equal [@fail_desc, exp_default_what].join("\n"), result.message end should "return a fail result given a \"truthy\" assertion" do assert_kind_of Assert::Result::Fail, subject.assert_not(34) end @@ -193,11 +211,11 @@ assert_kind_of Assert::Result::Pass, subject.assert_not(nil) end end - class SubjectTests < BasicTests + class SubjectTests < UnitTests desc "subject method" setup do expected = @expected = "amazing" @context_class = Factory.context_class do subject{ @something = expected } @@ -211,11 +229,11 @@ assert_equal @expected, subject end end - class WithBacktraceTests < BasicTests + class WithBacktraceTests < UnitTests desc "with_backtrace method" setup do @from_bt = ['called_from_here'] @from_block = proc { ignore; fail; pass; skip 'todo' } end @@ -238,10 +256,10 @@ assert_equal @from_bt, with_skip.backtrace end end - class InspectTests < BasicTests + class InspectTests < UnitTests desc "inspect method" setup do @expected = "#<#{@context.class}>" @inspect = @context.inspect end