# Dont understand unit test self.use\_instantiated\_fixtures

**URL:** <https://www.ruby-forum.com/t/dont-understand-unit-test-self-use-instantiated-fixtures/107473>\
**Category:** Rails\
**Created:** [June 22, 2007, 3:11am UTC](https://www.ruby-forum.com/t/dont-understand-unit-test-self-use-instantiated-fixtures/107473 "2007-06-22T03:11:12Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mjt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ea5d25/32.png) [@mjt](https://www.ruby-forum.com/u/mjt)\
**Post date:** [June 22, 2007, 3:11am UTC](https://www.ruby-forum.com/t/dont-understand-unit-test-self-use-instantiated-fixtures/107473/1 "2007-06-22T03:11:12Z")

</div>

Hi all,

I am trying to do some tests based on a tutorial here  
[http://www.aidanf.net/rails\_user\_authentication\_tutorial](http://www.aidanf.net/rails_user_authentication_tutorial)

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”)  
end

# 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 =  
“nonbobpasswd”  
assert @longbob.save  
# check that the new password works  
assert\_equal @longbob, User.authenticate(“longbob”,  
“nonbobpasswd”)  
# 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 @longbob.save  
assert\_equal @longbob, User.authenticate(“longbob”, “longtest”)  
assert\_nil User.authenticate(“longbob”, “nonbobpasswd”)  
end

# 2 other tests that work below here omitted

# …

end

This is the error listing I get

> ruby user\_test.rb  
> Loaded suite user\_test  
> Started  
> F…F  
> Finished in 0.279297 seconds.

1. Failure:  
test\_auth(UserTest) [user\_test.rb:10]:  
\<#\<User:0x99f7b18  
@attributes=  
{“salt”=\>“813762200.1356”,  
“name”=\>“bob”,  
“hashed\_password”=\>“69f50afebdc75388afbe144e3355b6c08066a0bc”,  
“lastname”=\>“bob”,  
“firstname”=\>“bob”,  
“id”=\>“1000001”,  
“email”=\>“removed\_email\_address@domain.invalid”}\>\> expected but was  
.

2. Failure:  
test\_passwordchange(UserTest) [user\_test.rb:22]:  
\<#\<User:0x99affc0  
@attributes=  
{“salt”=\>“808396800.134522”,  
“name”=\>“longbob”,  
“hashed\_password”=\>“f1bd0a176e98e973b03529ee89303e24acca00c6”,  
“lastname”=\>“bob”,  
“firstname”=\>“long”,  
“id”=\>“1000003”,  
“email”=\>“removed\_email\_address@domain.invalid”}\>\> 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  
> Started  
> …E  
> Finished in 0.149724 seconds.

1. Error:  
test\_passwordchange(UserTest):  
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  
whole  
content of this method is not providing good testing …

And test\_passwordchange seems to be completely missing an instance  
variable.

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

mjt
