Forum: Ruby on Rails Testing a model method - private method?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
2b2c2a705ed12f8fb327c7b4c56456c6?d=identicon&s=25 Sean Hussey (seanhussey)
on 2006-01-25 21:59
(Received via mailing list)
Hi everyone,

I'm trying to test a method in my model:

def html_email
  return "<a href='mailto:" + + "'>" + + "</a>"

The method works ok.  But when I try to test it:

    assert_equal ("<a href='mailto:" + people(:staff1_person).email +
"'>" + people(:staff1_person).email + "</a>"), @person.html_email

I get a failure:

  1) Error:
NoMethodError: private method `html_email' called for
    test/unit/person_test.rb:32:in `test_html_email'

The method works without errors (that I can see) when using it in a
view.  Why not in a test?


Bc80625db60e9db4394c51d6c1892b49?d=identicon&s=25 Derrick Spell (Guest)
on 2006-01-25 22:02
(Received via mailing list)
Somewhere above the html_email method you have the keyword
'private'.  You need to move the html_email method above the private
keyword or it will only be accessible by member functions of your model.

-Derrick Spell
2b2c2a705ed12f8fb327c7b4c56456c6?d=identicon&s=25 Sean Hussey (seanhussey)
on 2006-01-25 22:08
(Received via mailing list)
That wasn't it, but it clued me into what it was.  The method was
defined AFTER the Person class definition ended.

What's the statute of limitations on calling oneself a newbie?  I'm
going to have to finish off these posts with "Sorry, I'm a doofus"

Thanks, Derrick!  :)

This topic is locked and can not be replied to.