# NoMethodError: undefined method while running test

**URL:** <https://discuss.rubyonrails.org/t/nomethoderror-undefined-method-while-running-test/48852>\
**Category:** rubyonrails-talk\
**Created:** [January 25, 2010, 9:29pm UTC](https://discuss.rubyonrails.org/t/nomethoderror-undefined-method-while-running-test/48852 "2010-01-25T21:29:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![11155](https://avatars.discourse-cdn.com/v4/letter/1/d26b3c/32.png) [@11155](https://discuss.rubyonrails.org/u/11155)\
**Post date:** [January 25, 2010, 9:29pm UTC](https://discuss.rubyonrails.org/t/nomethoderror-undefined-method-while-running-test/48852/1 "2010-01-25T21:29:48Z")

</div>

I run the command: ruby test/unit/user\_test.rb

I get the error: NoMethodError: undefined method `authenticate' for #\<Class:0x193dd20\> &nbsp;&nbsp;&nbsp;&nbsp;C:/Ruby19/lib/ruby/gems/1.9.1/gems/activerecord-2.3.5/lib/active_record/base .rb:1959:in `method\_missing' &nbsp;&nbsp;&nbsp;&nbsp;test/unit/user\_test.rb:13:in `test\_auth' The authenticate method is defined in

This is denition of authenticate method in modes/user.rb class UserTest \< ActiveSupport::TestCase &nbsp;&nbsp;# Replace this with your real tests. &nbsp;&nbsp;# test "the truth" do &nbsp;&nbsp;# assert true &nbsp;&nbsp;self.use\_instantiated\_fixtures = true &nbsp;&nbsp;fixtures :users def self.authenticate(login, pass) &nbsp;&nbsp;u=find(:first, :conditions=\>["login = ?", login]) &nbsp;&nbsp;return nil if u.nil? &nbsp;&nbsp;return u if User.encrypt(pass, u.salt)==u.hashed\_password &nbsp;&nbsp;nil end

This is where it is called from user\_test.rb def test\_auth &nbsp;&nbsp;assert\_equal @bob, User.authenticate("rao", "test") end

username rao is already defined in users.yml

Can someone please tell me how to fix this?

---

<div class="post-metadata">

**Author:** ![11155](https://avatars.discourse-cdn.com/v4/letter/1/d26b3c/32.png) [@11155](https://discuss.rubyonrails.org/u/11155)\
**Post date:** [January 25, 2010, 9:34pm UTC](https://discuss.rubyonrails.org/t/nomethoderror-undefined-method-while-running-test/48852/2 "2010-01-25T21:34:35Z")

</div>

Sorry, there was a mistake in my posting. The correction to user\_test.rb def test\_auth &nbsp;&nbsp;&nbsp;assert\_equal @rao, User.authenticate("rao", "test") end where user rao has been defined in users.yml

I get this error NoMethodError: undefined method `authenticate' When the method 'authenticate' is already defined. Why is it unable to find the method?

Vishwa Rao wrote:

---

<div class="post-metadata">

**Author:** ![Colin\_Law1](https://avatars.discourse-cdn.com/v4/letter/c/91b2a8/32.png) [@Colin\_Law1](https://discuss.rubyonrails.org/u/Colin_Law1)\
**Post date:** [January 26, 2010, 11:05am UTC](https://discuss.rubyonrails.org/t/nomethoderror-undefined-method-while-running-test/48852/3 "2010-01-26T11:05:27Z")

</div>

> I run the command: ruby test/unit/user\_test.rb
> 
> I get the error: NoMethodError: undefined method `authenticate' for #\<Class:0x193dd20\> C:/Ruby19/lib/ruby/gems/1.9.1/gems/activerecord-2.3.5/lib/active_record/base .rb:1959:in `method\_missing' test/unit/user\_test.rb:13:in `test\_auth' The authenticate method is defined in
> 
> This is denition of authenticate method in modes/user.rb class UserTest \< ActiveSupport::TestCase # Replace this with your real tests. # test "the truth" do # assert true self.use\_instantiated\_fixtures = true fixtures :users def self.authenticate(login, pass)

You have this inside class UserTest instead of User

Colin
