2006-07-08 14:14:49 -04:00
|
|
|
# Stub to enable testing without Active Record
|
2005-06-20 07:15:46 -04:00
|
|
|
module ActiveRecord
|
|
|
|
class Base
|
|
|
|
def save!
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-01-05 08:31:04 -05:00
|
|
|
require 'abstract_unit'
|
2006-07-08 14:14:49 -04:00
|
|
|
require 'active_support/whiny_nil'
|
2005-06-20 07:15:46 -04:00
|
|
|
|
|
|
|
class WhinyNilTest < Test::Unit::TestCase
|
|
|
|
def test_unchanged
|
2005-06-25 07:15:38 -04:00
|
|
|
nil.method_thats_not_in_whiners
|
|
|
|
rescue NoMethodError => nme
|
2009-11-13 15:15:49 -05:00
|
|
|
assert(nme.message =~ /nil:NilClass/)
|
2005-06-20 07:15:46 -04:00
|
|
|
end
|
2006-07-08 14:14:49 -04:00
|
|
|
|
2005-06-20 07:15:46 -04:00
|
|
|
def test_active_record
|
2005-06-25 07:15:38 -04:00
|
|
|
nil.save!
|
|
|
|
rescue NoMethodError => nme
|
|
|
|
assert(!(nme.message =~ /nil:NilClass/))
|
2005-10-14 22:24:05 -04:00
|
|
|
assert_match(/nil\.save!/, nme.message)
|
2005-06-20 07:15:46 -04:00
|
|
|
end
|
2006-07-08 14:14:49 -04:00
|
|
|
|
2005-06-20 07:15:46 -04:00
|
|
|
def test_array
|
2005-06-25 07:15:38 -04:00
|
|
|
nil.each
|
|
|
|
rescue NoMethodError => nme
|
|
|
|
assert(!(nme.message =~ /nil:NilClass/))
|
2005-10-14 22:24:05 -04:00
|
|
|
assert_match(/nil\.each/, nme.message)
|
2005-06-25 07:15:38 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_id
|
|
|
|
nil.id
|
|
|
|
rescue RuntimeError => nme
|
|
|
|
assert(!(nme.message =~ /nil:NilClass/))
|
2005-06-20 07:15:46 -04:00
|
|
|
end
|
2009-11-13 15:15:49 -05:00
|
|
|
|
|
|
|
def test_no_to_ary_coercion
|
|
|
|
nil.to_ary
|
|
|
|
rescue NoMethodError => nme
|
|
|
|
assert(nme.message =~ /nil:NilClass/)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_no_to_str_coercion
|
|
|
|
nil.to_str
|
|
|
|
rescue NoMethodError => nme
|
|
|
|
assert(nme.message =~ /nil:NilClass/)
|
|
|
|
end
|
2005-06-25 07:15:38 -04:00
|
|
|
end
|