test/unit/context_tests.rb in assert-2.14.0 vs test/unit/context_tests.rb in assert-2.15.0
- old
+ new
@@ -9,11 +9,13 @@
class UnitTests < Assert::Context
desc "Assert::Context"
setup do
@test = Factory.test
@context_class = @test.context_class
- @context = @context_class.new(@test, @test.config)
+ @callback_result = nil
+ @result_callback = proc{ |result| @callback_result = result }
+ @context = @context_class.new(@test, @test.config, @result_callback)
end
subject{ @context }
# DSL methods
should have_cmeths :description, :desc, :describe, :subject, :suite
@@ -40,20 +42,33 @@
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)
+ @result = Factory.skip_result(@exception)
end
subject{ @result }
should "raise a test skipped exception and set its message" do
assert_kind_of Assert::Result::TestSkipped, @exception
assert_equal @skip_msg, @exception.message
assert_equal @skip_msg, subject.message
end
+ should "not call the result callback" do
+ assert_nil @callback_result
+ end
+
+ should "use any given called from arg as the exception backtrace" do
+ assert_not_equal 1, @exception.backtrace.size
+
+ called_from = Factory.string
+ begin; @context.skip(@skip_msg, called_from); rescue Exception => exception; end
+ assert_equal 1, exception.backtrace.size
+ assert_equal called_from, exception.backtrace.first
+ end
+
end
class IgnoreTests < UnitTests
desc "ignore method"
setup do
@@ -65,10 +80,14 @@
should "create an ignore result and set its message" do
assert_kind_of Assert::Result::Ignore, subject
assert_equal @ignore_msg, subject.message
end
+ should "call the result callback" do
+ assert_equal @result, @callback_result
+ end
+
end
class PassTests < UnitTests
desc "pass method"
setup do
@@ -80,10 +99,14 @@
should "create a pass result and set its message" do
assert_kind_of Assert::Result::Pass, subject
assert_equal @pass_msg, subject.message
end
+ should "call the result callback" do
+ assert_equal @result, @callback_result
+ end
+
end
class FlunkTests < UnitTests
desc "flunk method"
setup do
@@ -95,10 +118,14 @@
should "create a fail result and set its message" do
assert_kind_of Assert::Result::Fail, subject
assert_equal @flunk_msg, subject.message
end
+ should "call the result callback" do
+ assert_equal @result, @callback_result
+ end
+
end
class FailTests < UnitTests
desc "fail method"
setup do
@@ -116,17 +143,21 @@
fail_msg = "Didn't work"
result = @context.fail(fail_msg)
assert_equal fail_msg, result.message
end
+ should "call the result callback" do
+ assert_equal @result, @callback_result
+ end
+
end
- class HaltOnFailTests < FailTests
- desc "when halting on fails"
+ class HaltOnFailTests < UnitTests
+ desc "failing when halting on fails"
setup do
@halt_config = Assert::Config.new(:halt_on_fail => true)
- @context = @context_class.new(@test, @halt_config)
+ @context = @context_class.new(@test, @halt_config, @result_callback)
@fail_msg = "something failed"
end
subject{ @result }
should "raise an exception with the failure's message" do
@@ -136,14 +167,18 @@
exception
end
assert_kind_of Assert::Result::TestFailure, err
assert_equal @fail_msg, err.message
- result = Assert::Result::Fail.new(Factory.test("something"), err)
+ result = Assert::Result::Fail.for_test(Factory.test("something"), err)
assert_equal @fail_msg, result.message
end
+ should "not call the result callback" do
+ assert_nil @callback_result
+ end
+
end
class AssertTests < UnitTests
desc "assert method"
setup do
@@ -152,11 +187,11 @@
end
should "return a pass result given a `true` assertion" do
result = subject.assert(true, @fail_desc){ @what_failed }
assert_kind_of Assert::Result::Pass, result
- assert_nil result.message
+ assert_equal '', result.message
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
@@ -191,11 +226,11 @@
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
+ assert_equal '', 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
@@ -223,11 +258,11 @@
setup do
expected = @expected = "amazing"
@context_class = Factory.modes_off_context_class do
subject{ @something = expected }
end
- @context = @context_class.new(@test, @test.config)
+ @context = @context_class.new(@test, @test.config, proc{ |result| })
@subject = @context.subject
end
subject{ @subject }
should "instance evaluate the block set with the class setup method" do
@@ -246,10 +281,10 @@
should "replace the fail results from the block with the given backtrace" do
@context.fail 'not affected'
begin
@context.with_backtrace(@from_bt, &@from_block)
rescue Assert::Result::TestSkipped => e
- @test.results << Assert::Result::Skip.new(@test, e)
+ @test.results << Assert::Result::Skip.for_test(@test, e)
end
assert_equal 5, @test.results.size
norm_fail, with_ignore, with_fail, with_pass, with_skip = @test.results