Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Report the correct value of nil.id in the exception message

as different ruby implementations may have different values,
for example Rubinius returns 53 for nil.id.

[#6444 state:resolved]
  • Loading branch information...
commit 5e7ce47fb9ab50858fe067a6eb6c0462c5c5681e 1 parent 31f09f9
@pixeltrix pixeltrix authored
View
2  activesupport/lib/active_support/whiny_nil.rb
@@ -37,7 +37,7 @@ def self.add_whiner(klass)
# Raises a RuntimeError when you attempt to call +id+ on +nil+.
def id
- raise RuntimeError, "Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id", caller
+ raise RuntimeError, "Called id for nil, which would mistakenly be #{object_id} -- if you really wanted the id of nil, use object_id", caller
end
private
View
2  activesupport/test/whiny_nil_test.rb
@@ -33,9 +33,11 @@ def test_array
end
def test_id
+ nil.stubs(:object_id).returns(999)
nil.id
rescue RuntimeError => nme
assert_no_match(/nil:NilClass/, nme.message)
+ assert_match(/999/, nme.message)
end
def test_no_to_ary_coercion

1 comment on commit 5e7ce47

@fxn
Owner

Good tidbit!

Please sign in to comment.
Something went wrong with that request. Please try again.