Skip to content
This repository
Browse code

"raise NoMethodError" raises NoMethodError. Raise it with NoMethodErr…

…or.new instead.

Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
  • Loading branch information...
commit 5c97d4ff29cfd944da751f01177a3024626d57bb 1 parent 5cf9323
Mike Gunderloy authored October 25, 2008 lifo committed October 25, 2008
2  activerecord/lib/active_record/attribute_methods.rb
@@ -233,7 +233,7 @@ def method_missing(method_id, *args, &block)
233 233
       method_name = method_id.to_s
234 234
 
235 235
       if self.class.private_method_defined?(method_name)
236  
-        raise NoMethodError("Attempt to call private method", method_name, args)
  236
+        raise NoMethodError.new("Attempt to call private method", method_name, args)
237 237
       end
238 238
 
239 239
       # If we haven't generated any methods yet, generate them, then
11  activerecord/test/cases/attribute_methods_test.rb
@@ -233,8 +233,9 @@ def test_read_attributes_respect_access_control
233 233
 
234 234
     topic = @target.new(:title => "The pros and cons of programming naked.")
235 235
     assert !topic.respond_to?(:title)
236  
-    assert_raise(NoMethodError) { topic.title }
237  
-    topic.send(:title)
  236
+    exception = assert_raise(NoMethodError) { topic.title }
  237
+    assert_equal "Attempt to call private method", exception.message
  238
+    assert_equal "I'm private", topic.send(:title)
238 239
   end
239 240
 
240 241
   def test_write_attributes_respect_access_control
@@ -242,7 +243,8 @@ def test_write_attributes_respect_access_control
242 243
 
243 244
     topic = @target.new
244 245
     assert !topic.respond_to?(:title=)
245  
-    assert_raise(NoMethodError) { topic.title = "Pants"}
  246
+    exception = assert_raise(NoMethodError) { topic.title = "Pants"}
  247
+    assert_equal "Attempt to call private method", exception.message
246 248
     topic.send(:title=, "Very large pants")
247 249
   end
248 250
 
@@ -251,7 +253,8 @@ def test_question_attributes_respect_access_control
251 253
 
252 254
     topic = @target.new(:title => "Isaac Newton's pants")
253 255
     assert !topic.respond_to?(:title?)
254  
-    assert_raise(NoMethodError) { topic.title? }
  256
+    exception = assert_raise(NoMethodError) { topic.title? }
  257
+    assert_equal "Attempt to call private method", exception.message
255 258
     assert topic.send(:title?)
256 259
   end
257 260
 

2 notes on commit 5c97d4f

Mislav Marohnić

“raise NoMethodError” raises NoMethodError — well, duh!!

Pratik
Owner

I meant, raise NoMethodError(“Something”) raises NoMethodError :)

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