Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

"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 ffmike authored lifo committed
2  activerecord/lib/active_record/attribute_methods.rb
View
@@ -233,7 +233,7 @@ def method_missing(method_id, *args, &block)
method_name = method_id.to_s
if self.class.private_method_defined?(method_name)
- raise NoMethodError("Attempt to call private method", method_name, args)
+ raise NoMethodError.new("Attempt to call private method", method_name, args)
end
# If we haven't generated any methods yet, generate them, then
11 activerecord/test/cases/attribute_methods_test.rb
View
@@ -233,8 +233,9 @@ def test_read_attributes_respect_access_control
topic = @target.new(:title => "The pros and cons of programming naked.")
assert !topic.respond_to?(:title)
- assert_raise(NoMethodError) { topic.title }
- topic.send(:title)
+ exception = assert_raise(NoMethodError) { topic.title }
+ assert_equal "Attempt to call private method", exception.message
+ assert_equal "I'm private", topic.send(:title)
end
def test_write_attributes_respect_access_control
@@ -242,7 +243,8 @@ def test_write_attributes_respect_access_control
topic = @target.new
assert !topic.respond_to?(:title=)
- assert_raise(NoMethodError) { topic.title = "Pants"}
+ exception = assert_raise(NoMethodError) { topic.title = "Pants"}
+ assert_equal "Attempt to call private method", exception.message
topic.send(:title=, "Very large pants")
end
@@ -251,7 +253,8 @@ def test_question_attributes_respect_access_control
topic = @target.new(:title => "Isaac Newton's pants")
assert !topic.respond_to?(:title?)
- assert_raise(NoMethodError) { topic.title? }
+ exception = assert_raise(NoMethodError) { topic.title? }
+ assert_equal "Attempt to call private method", exception.message
assert topic.send(:title?)
end

2 comments on commit 5c97d4f

Mislav Marohnić

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

Pratik
Collaborator

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

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