test/context_test.rb in assert-0.6.0 vs test/context_test.rb in assert-0.7.0
- old
+ new
@@ -8,18 +8,23 @@
@test = Factory.test
@context_class = @test.context_class
@context = @context_class.new(@test)
end
teardown do
- TEST_ASSERT_SUITE.clear
+ TEST_ASSERT_SUITE.tests.clear
end
subject{ @context }
should have_instance_methods :assert, :assert_not, :refute
should have_instance_methods :skip, :pass, :fail, :flunk, :ignore
should have_instance_methods :subject
+ def test_should_collect_context_info
+ assert_match /test\/context_test.rb$/, @__running_test__.context_info.file
+ assert_equal self.class, @__running_test__.context_info.klass
+ end
+
end
class SkipTest < BasicTest
@@ -84,11 +89,11 @@
end
- class FailTest < BasicTest
+ class FailTests < BasicTest
desc "fail method"
setup do
@result = @context.fail
end
subject{ @result }
@@ -96,15 +101,32 @@
should "create a fail result" do
assert_kind_of Assert::Result::Fail, subject
end
should "set the calling backtrace on the result" do
assert_kind_of Array, subject.backtrace
- assert_match /assert\/test\/context_test\.rb/, subject.trace
+ assert_equal Factory.context_info_called_from, subject.trace
end
end
- class StringMessageTest < FailTest
+ class FlunkTest < BasicTest
+ desc "flunk method"
+ setup do
+ @flunk_msg = "It flunked."
+ @result = @context.flunk(@flunk_msg)
+ end
+ subject{ @result }
+
+ should "create a fail result" do
+ assert_kind_of Assert::Result::Fail, subject
+ end
+ should "set the message passed to it on the result" do
+ assert_equal @flunk_msg, subject.message
+ end
+
+ end
+
+ class StringMessageTests < FailTests
desc "with a string message"
setup do
@fail_msg = "Didn't work"
@result = @context.fail(@fail_msg)
end
@@ -113,11 +135,11 @@
assert_equal @fail_msg, subject.message
end
end
- class ProcMessageTest < FailTest
+ class ProcMessageTests < FailTests
desc "with a proc message"
setup do
@fail_msg = ::Proc.new{ "Still didn't work" }
@result = @context.fail(@fail_msg)
end
@@ -128,25 +150,55 @@
end
- class FlunkTest < BasicTest
- desc "flunk method"
+
+
+
+ class SaveRestoreHaltOnFailTests < BasicTest
+ desc "when not halting on fails"
setup do
- @flunk_msg = "It flunked."
- @result = @context.flunk(@flunk_msg)
+ @prev_halt_option = Assert::Test.options.halt_on_fail
+ @prev_halt_envvar = ENV['halt_on_fail']
end
+ teardown do
+ Assert::Test.options.halt_on_fail @prev_halt_option
+ ENV['halt_on_fail'] = @prev_halt_envvar
+ end
+ end
+
+ class HaltOnFailTests < SaveRestoreHaltOnFailTests
+ setup do
+ ENV['halt_on_fail'] = 'true'
+ Assert::Test.options.halt_on_fail true
+ end
+ end
+
+ class HaltFailTests < HaltOnFailTests
+ desc "fail method"
+ setup do
+ @fail_msg = "something failed"
+ begin
+ @context.fail @fail_msg
+ rescue Exception => @exception
+ end
+ @result = Assert::Result::Fail.new(Factory.test("something"), @exception)
+ end
subject{ @result }
- should "create a fail result" do
- assert_kind_of Assert::Result::Fail, subject
+ should "raise a test failure exception when called" do
+ assert_kind_of Assert::Result::TestFailure, @exception
end
+ should "raise the exception with the message passed to it" do
+ assert_equal @fail_msg, @exception.message
+ end
should "set the message passed to it on the result" do
- assert_equal @flunk_msg, subject.message
+ assert_equal @fail_msg, subject.message
end
end
+
class AssertTest < BasicTest
desc "assert method"