NoMethodError: undefined method while running test

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:inmethod_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)
u=find(:first, :conditions=>[“login = ?”, login])
return nil if u.nil?
return u if User.encrypt(pass, u.salt)==u.hashed_password
nil
end

This is where it is called from user_test.rb
def test_auth
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?

Sorry, there was a mistake in my posting. The correction to user_test.rb
def test_auth
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 R. wrote:

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:inmethod_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)
u=find(:first, :conditions=>[“login = ?”, login])
return nil if u.nil?
return u if User.encrypt(pass, u.salt)==u.hashed_password
nil
end

This is where it is called from user_test.rb
def test_auth
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?

I didn’t understand what Colin L. explained.

I am new to ruby on rails and would like some help on this issue.

my error message is
test/unit/user_test.rb:4: undefined method `use_instantiated_fixtures=’
for UserTest:Class (NoMethodError)

2010/1/25 Vishwa R. [email protected]:

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs