public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
"raise NoMethodError" raises NoMethodError. Raise it with NoMethodError.new 
instead.

Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
ffmike (author)
Sat Oct 25 02:19:39 -0700 2008
lifo (committer)
Sat Oct 25 02:22:44 -0700 2008
commit  5c97d4ff29cfd944da751f01177a3024626d57bb
tree    4142a8173f00fa3ff1e03e513d18aeef89be3042
parent  5cf932344a4482a0cfbda57e9f69ebe64e70a261
...
233
234
235
236
 
237
238
239
...
233
234
235
 
236
237
238
239
0
@@ -233,7 +233,7 @@ module ActiveRecord
0
       method_name = method_id.to_s
0
 
0
       if self.class.private_method_defined?(method_name)
0
-        raise NoMethodError("Attempt to call private method", method_name, args)
0
+        raise NoMethodError.new("Attempt to call private method", method_name, args)
0
       end
0
 
0
       # If we haven't generated any methods yet, generate them, then
...
233
234
235
236
237
 
 
 
238
239
240
...
242
243
244
245
 
 
246
247
248
...
251
252
253
254
 
 
255
256
257
...
233
234
235
 
 
236
237
238
239
240
241
...
243
244
245
 
246
247
248
249
250
...
253
254
255
 
256
257
258
259
260
0
@@ -233,8 +233,9 @@ class AttributeMethodsTest < ActiveRecord::TestCase
0
 
0
     topic = @target.new(:title => "The pros and cons of programming naked.")
0
     assert !topic.respond_to?(:title)
0
-    assert_raise(NoMethodError) { topic.title }
0
-    topic.send(:title)
0
+    exception = assert_raise(NoMethodError) { topic.title }
0
+    assert_equal "Attempt to call private method", exception.message
0
+    assert_equal "I'm private", topic.send(:title)
0
   end
0
 
0
   def test_write_attributes_respect_access_control
0
@@ -242,7 +243,8 @@ class AttributeMethodsTest < ActiveRecord::TestCase
0
 
0
     topic = @target.new
0
     assert !topic.respond_to?(:title=)
0
-    assert_raise(NoMethodError) { topic.title = "Pants"}
0
+    exception = assert_raise(NoMethodError) { topic.title = "Pants"}
0
+    assert_equal "Attempt to call private method", exception.message
0
     topic.send(:title=, "Very large pants")
0
   end
0
 
0
@@ -251,7 +253,8 @@ class AttributeMethodsTest < ActiveRecord::TestCase
0
 
0
     topic = @target.new(:title => "Isaac Newton's pants")
0
     assert !topic.respond_to?(:title?)
0
-    assert_raise(NoMethodError) { topic.title? }
0
+    exception = assert_raise(NoMethodError) { topic.title? }
0
+    assert_equal "Attempt to call private method", exception.message
0
     assert topic.send(:title?)
0
   end
0
 

Comments

mislav Sat Oct 25 02:42:28 -0700 2008

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

lifo Sat Oct 25 03:04:55 -0700 2008

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