test/unit/test_tests.rb in assert-2.3.1 vs test/unit/test_tests.rb in assert-2.3.2
- old
+ new
@@ -5,11 +5,11 @@
class BasicTests < Assert::Context
desc "a test obj"
setup do
@test_code = lambda{ assert(true) }
- @context_class = Factory.context_class { desc "context class" }
+ @context_class = Factory.context_class{ desc "context class" }
@context_info = Factory.context_info(@context_class)
@test = Factory.test("should do something amazing", @context_info, @test_code)
end
teardown do
TEST_ASSERT_SUITE.tests.clear
@@ -49,65 +49,95 @@
setup do
@test = Factory.test("pass fail ignore test", @context_info) do
ignore("something")
assert(true)
assert(false)
- ignore("something else")
- assert(34)
- assert(nil)
end
+ @test.context_class.setup do
+ ignore("something")
+ assert(true)
+ assert(false)
+ end
+ @test.context_class.teardown do
+ ignore("something")
+ assert(true)
+ assert(false)
+ end
@test.run
end
subject{ @test }
should "know its pass results" do
assert_kind_of Array, subject.pass_results
- assert_equal 2, subject.pass_results.size
+ assert_equal 3, subject.pass_results.size
subject.pass_results.each do |result|
assert_kind_of Assert::Result::Pass, result
end
assert_equal subject.pass_results.size, subject.result_count(:pass)
end
should "know its fail results" do
assert_kind_of Array, subject.fail_results
- assert_equal 2, subject.fail_results.size
+ assert_equal 3, subject.fail_results.size
subject.fail_results.each do |result|
assert_kind_of Assert::Result::Fail, result
end
assert_equal subject.fail_results.size, subject.result_count(:fail)
end
should "know its ignore results" do
assert_kind_of Array, subject.ignore_results
- assert_equal 2, subject.ignore_results.size
+ assert_equal 3, subject.ignore_results.size
subject.ignore_results.each do |result|
assert_kind_of Assert::Result::Ignore, result
end
assert_equal subject.ignore_results.size, subject.result_count(:ignore)
end
should "know the total number of results" do
- assert_equal(6, subject.result_count)
+ assert_equal(9, subject.result_count)
end
end
class SkipHandlingTests < BasicTests
setup do
- @test = Factory.test("skip test", @context_info) { skip }
+ @test = Factory.test("skip test", @context_info){ skip }
@test.run
end
subject{ @test }
- should "know its skip results" do
- assert_kind_of Array, subject.skip_results
- assert_equal 1, subject.skip_results.size
- subject.skip_results.each do |result|
- assert_kind_of Assert::Result::Skip, result
+ should "capture skip results" do
+ assert_skipped(subject)
+ end
+
+ should "capture skips in the context setup" do
+ test = Factory.test("setup skip test", @context_info){ }
+ test.context_class.setup{ skip }
+ test.run
+
+ assert_skipped(test)
+ end
+
+ should "capture skips in the context teardown" do
+ test = Factory.test("teardown skip test", @context_info){ }
+ test.context_class.teardown{ skip }
+ test.run
+
+ assert_skipped(test)
+ end
+
+ private
+
+ def assert_skipped(test)
+ with_backtrace(caller) do
+ assert_equal 1, test.skip_results.size, 'too many/few skip results'
+ test.skip_results.each do |result|
+ assert_kind_of Assert::Result::Skip, result, 'result is not a skip result'
+ end
+ assert_equal test.skip_results.size, test.result_count(:skip), 'skip result not counted'
end
- assert_equal subject.skip_results.size, subject.result_count(:skip)
end
end
class ErrorHandlingTests < BasicTests
@@ -117,21 +147,72 @@
end
@test.run
end
subject{ @test }
- should "know its error results" do
- assert_kind_of Array, subject.error_results
- assert_equal 1, subject.error_results.size
- subject.error_results.each do |result|
- assert_kind_of Assert::Result::Error, result
+ should "capture error results" do
+ assert_errored(subject)
+ end
+
+ should "capture errors in the context setup" do
+ test = Factory.test("setup error test", @context_info){ }
+ test.context_class.setup{ raise 'an error' }
+ test.run
+
+ assert_errored(test)
+ end
+
+ should "capture errors in the context teardown" do
+ test = Factory.test("teardown error test", @context_info){ }
+ test.context_class.teardown{ raise 'an error' }
+ test.run
+
+ assert_errored(test)
+ end
+
+ private
+
+ def assert_errored(test)
+ with_backtrace(caller) do
+ assert_equal 1, subject.error_results.size, 'too many/few error results'
+ test.error_results.each do |result|
+ assert_kind_of Assert::Result::Error, result, 'result is not an error result'
+ end
+ assert_equal test.error_results.size, test.result_count(:error), 'error result not counted'
end
- assert_equal subject.error_results.size, subject.result_count(:error)
end
end
+ class SignalExceptionHandlingTests < BasicTests
+ setup do
+ @test = Factory.test("signal test", @context_info) do
+ raise SignalException, "USR1"
+ end
+ end
+ subject{ @test }
+
+ should "raise any signal exceptions and not capture as an error" do
+ assert_raises(SignalException){ subject.run }
+ end
+
+ should "raises signal exceptions in the context setup" do
+ test = Factory.test("setup signal test", @context_info){ }
+ test.context_class.setup{ raise SignalException, 'INT' }
+
+ assert_raises(SignalException){ test.run }
+ end
+
+ should "raises signal exceptions in the context teardown" do
+ test = Factory.test("teardown signal test", @context_info){ }
+ test.context_class.teardown{ raise SignalException, "TERM" }
+
+ assert_raises(SignalException){ test.run }
+ end
+
+ end
+
class ComparingTests < BasicTests
desc "<=> another test"
setup do
@test = Factory.test("mmm")
end
@@ -155,14 +236,14 @@
end
class CaptureOutTests < BasicTests
desc "when capturing std out"
setup do
- @test = Factory.test("stdout") {
+ @test = Factory.test("stdout") do
puts "std out from the test"
assert true
- }
+ end
@orig_capture = Assert.config.capture_output
Assert.config.capture_output true
end
teardown do
Assert.config.capture_output @orig_capture
@@ -180,11 +261,11 @@
setup do
@test = Factory.test("fullstdouttest") do
puts "std out from the test"
assert a_method_an_assert_calls
end
- @test.context_class.setup { puts "std out from the setup" }
- @test.context_class.teardown { puts "std out from the teardown" }
+ @test.context_class.setup{ puts "std out from the setup" }
+ @test.context_class.teardown{ puts "std out from the teardown" }
@test.context_class.send(:define_method, "a_method_an_assert_calls") do
puts "std out from a method an assert called"
end
end