mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Added tests for whiny nil #1476 [court3nay/marcel]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1507 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
f16e0ec3eb
commit
a995f42be0
2 changed files with 20 additions and 23 deletions
|
@ -6,9 +6,8 @@
|
|||
# by the framework users will see a message explaining what type of object
|
||||
# was expected.
|
||||
|
||||
|
||||
class NilClass
|
||||
WHINERS = [ ActiveRecord::Base, Array ]
|
||||
WHINERS = [ ::ActiveRecord::Base, ::Array ]
|
||||
|
||||
@@method_class_map = Hash.new
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
require 'test/unit'
|
||||
|
||||
|
||||
## mock to enable testing without activerecord
|
||||
# mock to enable testing without activerecord
|
||||
module ActiveRecord
|
||||
class Base
|
||||
def save!
|
||||
|
@ -9,32 +8,31 @@ module ActiveRecord
|
|||
end
|
||||
end
|
||||
|
||||
require 'active_support/whiny_nil'
|
||||
|
||||
|
||||
require File.dirname(__FILE__) + '/../lib/active_support/inflector'
|
||||
require File.dirname(__FILE__) + '/../lib/active_support/whiny_nil'
|
||||
|
||||
class WhinyNilTest < Test::Unit::TestCase
|
||||
def test_unchanged
|
||||
begin
|
||||
nil.method_thats_not_in_whiners
|
||||
rescue NoMethodError => nme
|
||||
assert_match(/nil:NilClass/, nme.message)
|
||||
end
|
||||
end
|
||||
|
||||
def test_active_record
|
||||
begin
|
||||
nil.save!
|
||||
rescue NoMethodError => nme
|
||||
assert(!(nme.message =~ /nil:NilClass/))
|
||||
end
|
||||
end
|
||||
|
||||
def test_array
|
||||
begin
|
||||
nil.each
|
||||
rescue NoMethodError => nme
|
||||
assert(!(nme.message =~ /nil:NilClass/))
|
||||
end
|
||||
|
||||
def test_id
|
||||
nil.id
|
||||
rescue RuntimeError => nme
|
||||
assert(!(nme.message =~ /nil:NilClass/))
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue