Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
"raise NoMethodError" raises NoMethodError. Raise it with NoMethodErr…
…or.new instead.

Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
  • Loading branch information
Mike Gunderloy authored and lifo committed Oct 25, 2008
1 parent 5cf9323 commit 5c97d4f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion activerecord/lib/active_record/attribute_methods.rb
Expand Up @@ -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
Expand Down
11 changes: 7 additions & 4 deletions activerecord/test/cases/attribute_methods_test.rb
Expand Up @@ -233,16 +233,18 @@ 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
privatize("title=(value)")

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

Expand All @@ -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

Expand Down

2 comments on commit 5c97d4f

@mislav
Copy link
Member

@mislav mislav commented on 5c97d4f Oct 25, 2008

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@lifo
Copy link
Member

@lifo lifo commented on 5c97d4f Oct 25, 2008

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Please sign in to comment.