Hi everyone, I''m trying to test a method in my model: def html_email return "<a href=''mailto:" + self.email + "''>" + self.email + "</a>" end 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: test_html_email(PersonTest): NoMethodError: private method `html_email'' called for #<Person:0x256b460> /Applications/Locomotive/Bundles/rails-1.0.0-max.bundle/Contents/Resources/ports/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/base.rb:1501:in `method_missing'' 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? Thanks, Sean
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 On Jan 25, 2006, at 3:56 PM, Sean Hussey wrote:> Hi everyone, > > I''m trying to test a method in my model: > > def html_email > return "<a href=''mailto:" + self.email + "''>" + self.email + "</a>" > end > > 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: > test_html_email(PersonTest): > NoMethodError: private method `html_email'' called for #<Person: > 0x256b460> > /Applications/Locomotive/Bundles/rails-1.0.0-max.bundle/ > Contents/Resources/ports/lib/ruby/gems/1.8/gems/activerecord-1.13.2/ > lib/active_record/base.rb:1501:in > `method_missing'' > 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? > > Thanks, > > Sean > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
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" instead. Thanks, Derrick! :) Sean On 1/25/06, Derrick Spell <derrickspell@cdmplus.com> wrote:> 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 > > > On Jan 25, 2006, at 3:56 PM, Sean Hussey wrote: > > > Hi everyone, > > > > I''m trying to test a method in my model: > > > > def html_email > > return "<a href=''mailto:" + self.email + "''>" + self.email + "</a>" > > end > > > > 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: > > test_html_email(PersonTest): > > NoMethodError: private method `html_email'' called for #<Person: > > 0x256b460> > > /Applications/Locomotive/Bundles/rails-1.0.0-max.bundle/ > > Contents/Resources/ports/lib/ruby/gems/1.8/gems/activerecord-1.13.2/ > > lib/active_record/base.rb:1501:in > > `method_missing'' > > 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? > > > > Thanks, > > > > Sean > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >