2007-02-09 09:04:31 +01:00
|
|
|
# Stub to enable testing without Active Record
|
2007-01-22 14:43:50 +01:00
|
|
|
module ActiveRecord
|
|
|
|
class Base
|
|
|
|
def save!
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-05-18 06:22:34 +02:00
|
|
|
require 'abstract_unit'
|
2007-02-09 09:04:31 +01:00
|
|
|
require 'active_support/whiny_nil'
|
2007-01-22 14:43:50 +01:00
|
|
|
|
|
|
|
class WhinyNilTest < Test::Unit::TestCase
|
|
|
|
def test_unchanged
|
|
|
|
nil.method_thats_not_in_whiners
|
|
|
|
rescue NoMethodError => nme
|
2009-12-01 02:38:34 +01:00
|
|
|
assert(nme.message =~ /nil:NilClass/)
|
2007-01-22 14:43:50 +01:00
|
|
|
end
|
2007-02-09 09:04:31 +01:00
|
|
|
|
2007-01-22 14:43:50 +01:00
|
|
|
def test_active_record
|
|
|
|
nil.save!
|
|
|
|
rescue NoMethodError => nme
|
|
|
|
assert(!(nme.message =~ /nil:NilClass/))
|
|
|
|
assert_match(/nil\.save!/, nme.message)
|
|
|
|
end
|
2007-02-09 09:04:31 +01:00
|
|
|
|
2007-01-22 14:43:50 +01:00
|
|
|
def test_array
|
|
|
|
nil.each
|
|
|
|
rescue NoMethodError => nme
|
|
|
|
assert(!(nme.message =~ /nil:NilClass/))
|
|
|
|
assert_match(/nil\.each/, nme.message)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_id
|
|
|
|
nil.id
|
|
|
|
rescue RuntimeError => nme
|
|
|
|
assert(!(nme.message =~ /nil:NilClass/))
|
|
|
|
end
|
2009-12-01 02:38:34 +01: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
|
2007-01-22 14:43:50 +01:00
|
|
|
end
|