test/result_test.rb in assert-0.6.0 vs test/result_test.rb in assert-0.7.0

- old
+ new

@@ -29,16 +29,17 @@ end class BaseTest < Assert::Context desc "a base result" setup do - @result = Assert::Result::Base.new("a test name", "a message", ["line 1", "line2"]) + @test = Factory.test("a test name") + @result = Assert::Result::Base.new(@test, "a message", ["line 1", "line2"]) end subject{ @result } - should have_readers :test_name, :message, :backtrace - should have_instance_methods :to_sym, :to_s, :trace + should have_readers :test, :message, :backtrace + should have_instance_methods :test_name, :name, :to_sym, :to_s, :trace Assert::Result.types.keys.each do |type| should "respond to the instance method ##{type}?" do assert_respond_to "#{type}?", subject end @@ -46,12 +47,16 @@ should "not be #{type}" do assert_equal false, subject.send("#{type}?") end end + should "know its test" do + assert_equal @test, subject.test + end + should "nil out empty messages" do - assert_equal nil, Assert::Result::Base.new("a test name", "").message + assert_equal nil, Assert::Result::Base.new(@test, "").message end should "show only its class and message when inspected" do assert_equal "#<#{subject.class} @message=#{subject.message.inspect}>", subject.inspect end @@ -81,11 +86,12 @@ end class PassTest < Assert::Context desc "a pass result" setup do - @result = Assert::Result::Pass.new("test", "passed", []) + @test = Factory.test("a test name") + @result = Assert::Result::Pass.new(@test, "passed", []) end subject { @result } should "be pass?" do assert_equal true, subject.pass? @@ -96,99 +102,111 @@ assert_equal false, subject.send("#{type}?") end end should "know its to_sym" do - assert_equal :passed, subject.to_sym + assert_equal :pass, subject.to_sym end + should "know its name" do + assert_equal "Pass", subject.name + end + should "include PASS in its to_s" do assert subject.to_s.include?("PASS") end end - class FailTest < Assert::Context - desc "a fail result" + class IgnoreTest < Assert::Context + desc "an ignore result" setup do - @result = Assert::Result::Fail.new("test", "failed", []) + @test = Factory.test("a test name") + @result = Assert::Result::Ignore.new(@test, "ignored", []) end subject { @result } - should "be fail?" do - assert_equal true, subject.fail? + should "be ignore?" do + assert_equal true, subject.ignore? end - Assert::Result.types.keys.reject{|k| k == :fail}.each do |type| + Assert::Result.types.keys.reject{|k| k == :ignore}.each do |type| should "not be #{type}?" do assert_equal false, subject.send("#{type}?") end end should "know its to_sym" do - assert_equal :failed, subject.to_sym + assert_equal :ignore, subject.to_sym end - should "include FAIL in its to_s" do - assert subject.to_s.include?("FAIL") + should "know its name" do + assert_equal "Ignore", subject.name end + + should "include IGNORE in its to_s" do + assert subject.to_s.include?("IGNORE") + end end - class IgnoreTest < Assert::Context - desc "an ignore result" + class FailureRuntimeErrorTest < Assert::Context + + should "be a runtime error" do + assert_kind_of RuntimeError, Assert::Result::TestFailure.new + end + + end + + class FailTest < Assert::Context + desc "a fail result" setup do - @result = Assert::Result::Ignore.new("test", "ignored", []) + @test = Factory.test("a test name") + @result = Assert::Result::Fail.new(@test, "failed", []) end subject { @result } - should "be ignore?" do - assert_equal true, subject.ignore? + should "be fail?" do + assert_equal true, subject.fail? end - Assert::Result.types.keys.reject{|k| k == :ignore}.each do |type| + Assert::Result.types.keys.reject{|k| k == :fail}.each do |type| should "not be #{type}?" do assert_equal false, subject.send("#{type}?") end end should "know its to_sym" do - assert_equal :ignored, subject.to_sym + assert_equal :fail, subject.to_sym end - should "include IGNORE in its to_s" do - assert subject.to_s.include?("IGNORE") + should "know its name" do + assert_equal "Fail", subject.name end - end - class FromExceptionTest < Assert::Context - before do - begin - raise Exception, "test error" - rescue Exception => err - @exception = err - end - @result = Assert::Result::FromException.new("test", @exception) + should "include FAIL in its to_s" do + assert subject.to_s.include?("FAIL") end - subject{ @result } - - should "have the same backtrace as the original exception it was created from" do - assert_equal @exception.backtrace, subject.backtrace - end - end class SkippedRuntimeErrorTest < Assert::Context should "be a runtime error" do assert_kind_of RuntimeError, Assert::Result::TestSkipped.new end end - class SkipTest < FromExceptionTest + class SkipTest < Assert::Context desc "a skip result" setup do - @result = Assert::Result::Skip.new("test", @exception) + @test = Factory.test("a test name") + @exception = nil + begin + raise TestSkipped, "test ski[" + rescue Exception => err + @exception = err + end + @result = Assert::Result::Skip.new(@test, @exception) end subject { @result } should "be skip?" do assert_equal true, subject.skip? @@ -199,22 +217,33 @@ assert_equal false, subject.send("#{type}?") end end should "know its to_sym" do - assert_equal :skipped, subject.to_sym + assert_equal :skip, subject.to_sym end + should "know its name" do + assert_equal "Skip", subject.name + end + should "include SKIP in its to_s" do assert subject.to_s.include?("SKIP") end end - class ErrorTest < FromExceptionTest + class ErrorTest < Assert::Context desc "an error result" setup do - @result = Assert::Result::Error.new("test", @exception) + @test = Factory.test("a test name") + @exception = nil + begin + raise Exception, "test error" + rescue Exception => err + @exception = err + end + @result = Assert::Result::Error.new(@test, @exception) end subject { @result } should "be error?" do assert_equal true, subject.error? @@ -225,10 +254,14 @@ assert_equal false, subject.send("#{type}?") end end should "know its to_sym" do - assert_equal :errored, subject.to_sym + assert_equal :error, subject.to_sym + end + + should "know its name" do + assert_equal "Error", subject.name end should "include ERRORED in its to_s" do assert subject.to_s.include?("ERROR") end