Forum: Ruby on Rails dont understand unit test self.use_instantiated_fixtures

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.
C81a0fee0654e4ee6d08b54654c324d5?d=identicon&s=25 mjt (Guest)
on 2007-06-22 03:11
(Received via mailing list)
Hi all,

I am trying to do some tests based on a tutorial here

here is the two tests that seem to 'blow up' when I have the
use_instantiated_fixtures line in place.

require File.dirname(__FILE__) + '/../test_helper'

class UserTest < Test::Unit::TestCase
  self.use_instantiated_fixtures = true
  fixtures :users

  # test basic authentication
  def test_auth
    # check that we can login a valid user
     assert_equal @bob, User.authenticate("bob", "test1")
    # wrong username
    assert_nil   User.authenticate("notbob", "test1")
    # wrong pwd
    assert_nil   User.authenticate("bob", "wrongpass")
    # both wrong
    assert_nil   User.authenticate("notbob", "wrongpass")

  # can we change passwords
  def test_passwordchange
    # check that it exists in the first place
    assert_equal @longbob, User.authenticate("longbob", "longtest")
    # change password
    @longbob.password = @longbob.password_confirmation =
    # check that the new password works
    assert_equal @longbob, User.authenticate("longbob",
    # check that old password doesnt work any more
    assert_nil   User.authenticate("longbob", "longtest")
    #change it back again
    @longbob.password = @longbob.password_confirmation = "longtest"
    assert_equal @longbob, User.authenticate("longbob", "longtest")
    assert_nil   User.authenticate("longbob", "nonbobpasswd")

# 2 other tests that work below here omitted
# ......

This is the error listing I get

> ruby user_test.rb
Loaded suite user_test
Finished in 0.279297 seconds.

  1) Failure:
test_auth(UserTest) [user_test.rb:10]:
   "email"=>""}>> expected but was

  2) Failure:
test_passwordchange(UserTest) [user_test.rb:22]:
   "email"=>""}>> expected but was

4 tests, 11 assertions, 2 failures, 0 errors

Now if i comment out the line I get this instead

> ruby user_test.rb
Loaded suite user_test
Finished in 0.149724 seconds.

  1) Error:
NoMethodError: You have a nil object when you didn't expect it!
The error occurred while evaluating nil.password_confirmation=
    user_test.rb:24:in `test_passwordchange'

4 tests, 14 assertions, 0 failures, 1 errors

Having tried other good and bad values in test_auth I reckon that the
content of this method is not providing good testing ....

And test_passwordchange seems to be completely missing an instance

What am I missing ??
I am using Rails version 1.2.3

This topic is locked and can not be replied to.