aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorNicholas Seckar <nseckar@gmail.com>2005-10-15 02:24:05 +0000
committerNicholas Seckar <nseckar@gmail.com>2005-10-15 02:24:05 +0000
commit43c34e20d2698e04c398496e4cbc4e2271619297 (patch)
tree58d68866ce6829c33cd948c71521aba9f4c4e536 /activesupport
parent07b4ea2e4b30b0a57129a3e24902602d08cf5cc7 (diff)
downloadrails-43c34e20d2698e04c398496e4cbc4e2271619297.tar.gz
rails-43c34e20d2698e04c398496e4cbc4e2271619297.tar.bz2
rails-43c34e20d2698e04c398496e4cbc4e2271619297.zip
Updated whiny nil to be more concise and useful.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2602 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/CHANGELOG2
-rw-r--r--activesupport/lib/active_support/whiny_nil.rb22
-rw-r--r--activesupport/test/whiny_nil_test.rb4
3 files changed, 12 insertions, 16 deletions
diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG
index 486e0ae780..e6709f0d3e 100644
--- a/activesupport/CHANGELOG
+++ b/activesupport/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Updated whiny nil to be more concise and useful. [Nicholas Seckar]
+
* Added Enumerable#first_match [Nicholas Seckar]
* Fixed that Time#change should also reset usec when also resetting minutes #2459 [ikeda@dream.big.or.jp]
diff --git a/activesupport/lib/active_support/whiny_nil.rb b/activesupport/lib/active_support/whiny_nil.rb
index 9beba568c7..61cbe98e2b 100644
--- a/activesupport/lib/active_support/whiny_nil.rb
+++ b/activesupport/lib/active_support/whiny_nil.rb
@@ -24,23 +24,15 @@ class NilClass
private
def method_missing(method, *args, &block)
- if @@method_class_map.include?(method)
- raise_nil_warning_for @@method_class_map[method], caller
- else
- super
- end
+ raise_nil_warning_for @@method_class_map[method], method, caller
end
- def raise_nil_warning_for(klass, with_caller = nil)
- raise NoMethodError, NIL_WARNING_MESSAGE % klass, with_caller || caller
+ def raise_nil_warning_for(klass = nil, selector = nil, with_caller = nil)
+ message = "You have a nil object when you didn't expect it!"
+ message << "\nYou might have expected an instance of #{klass}." if klass
+ message << "\nThe error occured while evaluating nil.#{selector}" if selector
+
+ raise NoMethodError, message, with_caller || caller
end
-
- NIL_WARNING_MESSAGE = <<-end_message unless const_defined?(:NIL_WARNING_MESSAGE)
-WARNING: You have a nil object when you probably didn't expect it! Odds are you
-want an instance of %s instead.
-
-Look in the callstack to see where you're working with an object that could be nil.
-Investigate your methods and make sure the object is what you expect!
- end_message
end
diff --git a/activesupport/test/whiny_nil_test.rb b/activesupport/test/whiny_nil_test.rb
index a3bedd7c14..9ed31bfef5 100644
--- a/activesupport/test/whiny_nil_test.rb
+++ b/activesupport/test/whiny_nil_test.rb
@@ -15,19 +15,21 @@ class WhinyNilTest < Test::Unit::TestCase
def test_unchanged
nil.method_thats_not_in_whiners
rescue NoMethodError => nme
- assert_match(/nil:NilClass/, nme.message)
+ assert_match(/nil.method_thats_not_in_whiners/, nme.message)
end
def test_active_record
nil.save!
rescue NoMethodError => nme
assert(!(nme.message =~ /nil:NilClass/))
+ assert_match(/nil\.save!/, nme.message)
end
def test_array
nil.each
rescue NoMethodError => nme
assert(!(nme.message =~ /nil:NilClass/))
+ assert_match(/nil\.each/, nme.message)
end
def test_id