Skip to content

Commit

Permalink
Added tests for whiny nil #1476 [court3nay/marcel]
Browse files Browse the repository at this point in the history
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1507 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
dhh committed Jun 25, 2005
1 parent f16e0ec commit a995f42
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 23 deletions.
3 changes: 1 addition & 2 deletions activesupport/lib/active_support/whiny_nil.rb
Expand Up @@ -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

Expand Down
40 changes: 19 additions & 21 deletions activesupport/test/whiny_nil_test.rb
@@ -1,40 +1,38 @@
require 'test/unit'


## mock to enable testing without activerecord
# mock to enable testing without activerecord
module ActiveRecord
class Base
def save!
end
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
nil.method_thats_not_in_whiners
rescue NoMethodError => nme
assert_match(/nil:NilClass/, nme.message)
end

def test_active_record
begin
nil.save!
rescue NoMethodError => nme
assert(!(nme.message =~ /nil:NilClass/))
end
nil.save!
rescue NoMethodError => nme
assert(!(nme.message =~ /nil:NilClass/))
end

def test_array
begin
nil.each
rescue NoMethodError => nme
assert(!(nme.message =~ /nil:NilClass/))
end
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
end

0 comments on commit a995f42

Please sign in to comment.