From 7212c29802e34fe7368d5b484a479c31fad49c5d Mon Sep 17 00:00:00 2001 From: Juanjo Bazan Date: Tue, 30 Mar 2010 23:18:44 +0200 Subject: new assertion: assert_blank Signed-off-by: Xavier Noria --- activesupport/test/test_test.rb | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'activesupport/test') diff --git a/activesupport/test/test_test.rb b/activesupport/test/test_test.rb index 1928da51ca..390670570d 100644 --- a/activesupport/test/test_test.rb +++ b/activesupport/test/test_test.rb @@ -86,6 +86,34 @@ class AssertDifferenceTest < ActiveSupport::TestCase end end +class EmptyTrue + def empty?() true; end +end + +class EmptyFalse + def empty?() false; end +end + +class AssertBlankTest < ActiveSupport::TestCase + BLANK = [ EmptyTrue.new, nil, false, '', ' ', " \n\t \r ", [], {} ] + NOT_BLANK = [ EmptyFalse.new, Object.new, true, 0, 1, 'j', [nil], { nil => 0 } ] + + def test_assert_blank_true + BLANK.each { |v| assert_blank v } + end + + def test_assert_blank_false + NOT_BLANK.each { |v| + begin + assert_blank v + fail 'should not get to here' + rescue Exception => e + assert_match(/is not blank/, e.message) + end + } + end +end + # These should always pass if ActiveSupport::Testing.const_defined?(:Default) class NotTestingThingsTest < Test::Unit::TestCase -- cgit v1.2.3