Changeset 2602
- Timestamp:
- 10/15/05 02:24:05 (3 years ago)
- Files:
-
- trunk/activesupport/CHANGELOG (modified) (1 diff)
- trunk/activesupport/lib/active_support/whiny_nil.rb (modified) (1 diff)
- trunk/activesupport/test/whiny_nil_test.rb (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activesupport/CHANGELOG
r2578 r2602 1 1 *SVN* 2 3 * Updated whiny nil to be more concise and useful. [Nicholas Seckar] 2 4 3 5 * Added Enumerable#first_match [Nicholas Seckar] trunk/activesupport/lib/active_support/whiny_nil.rb
r1660 r2602 25 25 private 26 26 def method_missing(method, *args, &block) 27 if @@method_class_map.include?(method) 28 raise_nil_warning_for @@method_class_map[method], caller 29 else 30 super 31 end 27 raise_nil_warning_for @@method_class_map[method], method, caller 32 28 end 33 29 34 def raise_nil_warning_for(klass, with_caller = nil) 35 raise NoMethodError, NIL_WARNING_MESSAGE % klass, with_caller || caller 30 def raise_nil_warning_for(klass = nil, selector = nil, with_caller = nil) 31 message = "You have a nil object when you didn't expect it!" 32 message << "\nYou might have expected an instance of #{klass}." if klass 33 message << "\nThe error occured while evaluating nil.#{selector}" if selector 34 35 raise NoMethodError, message, with_caller || caller 36 36 end 37 38 NIL_WARNING_MESSAGE = <<-end_message unless const_defined?(:NIL_WARNING_MESSAGE)39 WARNING: You have a nil object when you probably didn't expect it! Odds are you40 want an instance of %s instead.41 42 Look in the callstack to see where you're working with an object that could be nil.43 Investigate your methods and make sure the object is what you expect!44 end_message45 37 end 46 38 trunk/activesupport/test/whiny_nil_test.rb
r1507 r2602 16 16 nil.method_thats_not_in_whiners 17 17 rescue NoMethodError => nme 18 assert_match(/nil :NilClass/, nme.message)18 assert_match(/nil.method_thats_not_in_whiners/, nme.message) 19 19 end 20 20 … … 23 23 rescue NoMethodError => nme 24 24 assert(!(nme.message =~ /nil:NilClass/)) 25 assert_match(/nil\.save!/, nme.message) 25 26 end 26 27 … … 29 30 rescue NoMethodError => nme 30 31 assert(!(nme.message =~ /nil:NilClass/)) 32 assert_match(/nil\.each/, nme.message) 31 33 end 32 34