Improve various test coverage. Closes #8676 [kamal]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7117 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
Jeremy Kemper 2007-06-25 18:22:31 +00:00
parent 2cda5096b8
commit 3aadfcef88
7 changed files with 52 additions and 1 deletions

@ -45,6 +45,7 @@ def test_datetime_format
@logger.formatter = Logger::Formatter.new
@logger.datetime_format = "%Y-%m-%d"
@logger.debug 'debug'
assert_equal "%Y-%m-%d", @logger.datetime_format
assert_match(/D, \[\d\d\d\d-\d\d-\d\d#\d+\] DEBUG -- : debug/, @out.string)
end
end

@ -4,8 +4,20 @@ class BlankTest < Test::Unit::TestCase
BLANK = [nil, false, '', ' ', " \n\t \r ", [], {}]
NOT = [true, 0, 1, 'a', [nil], { nil => 0 }]
class EmptyObject
def empty?
true
end
alias :strip :empty?
end
class NoStripObject < EmptyObject; undef :strip; end
class NoEmptyStripObject < NoStripObject; undef :empty?; end
def test_blank
BLANK.each { |v| assert v.blank? }
NOT.each { |v| assert !v.blank? }
assert EmptyObject.new.blank?
assert NoStripObject.new.blank?
assert !NoEmptyStripObject.new.blank?
end
end

@ -205,4 +205,20 @@ def test_array_inheritance_
assert_equal 1, @sub.a.keys.size
assert_equal 0, @klass.a.keys.size
end
def test_reset_inheritable_attributes
@klass.class_inheritable_accessor :a
@klass.a = 'a'
@sub = eval("class Inheriting < @klass; end; Inheriting")
assert_equal 'a', @klass.a
assert_equal 'a', @sub.a
@klass.reset_inheritable_attributes
@sub = eval("class NotInheriting < @klass; end; NotInheriting")
assert_equal nil, @klass.a
assert_equal nil, @sub.a
end
end

@ -33,4 +33,14 @@ def test_removing_class_in_two_level_namespace
Class.remove_class(Y::Z::C)
assert_raises(NameError) { Y::Z::C.is_a?(Class) }
end
def test_retrieving_subclasses
@parent = eval("class D; end; D")
@sub = eval("class E < D; end; E")
@subofsub = eval("class F < E; end; F")
assert @parent.subclasses.all? { |i| [@sub.to_s, @subofsub.to_s].include?(i) }
assert_equal 2, @parent.subclasses.size
assert_equal [@subofsub.to_s], @sub.subclasses
assert_equal [], @subofsub.subclasses
end
end

@ -104,6 +104,7 @@ def test_chaining_duration_operations
class NumericExtSizeTest < Test::Unit::TestCase
def test_unit_in_terms_of_another
relationships = {
1024.bytes => 1.kilobyte,
1024.kilobytes => 1.megabyte,
3584.0.kilobytes => 3.5.megabytes,
3584.0.megabytes => 3.5.gigabytes,

@ -25,4 +25,8 @@ def test_json_decoding
end
end
end
def test_failed_json_decoding
assert_raises(ActiveSupport::JSON::ParseError) { ActiveSupport::JSON.decode(%({: 1})) }
end
end

@ -80,6 +80,8 @@ def test_all_sorted
def test_index
assert_nil TimeZone["bogus"]
assert_not_nil TimeZone["Central Time (US & Canada)"]
assert_not_nil TimeZone[8]
assert_raises(ArgumentError) { TimeZone[false] }
end
def test_new
@ -88,4 +90,9 @@ def test_new
assert_same a, b
assert_nil TimeZone.new("bogus")
end
def test_us_zones
assert TimeZone.us_zones.include?(TimeZone["Hawaii"])
assert !TimeZone.us_zones.include?(TimeZone["Kuala Lumpur"])
end
end