# Getting started with variable fixture tests

**URL:** <https://www.ruby-forum.com/t/getting-started-with-variable-fixture-tests/49808>\
**Category:** Rails\
**Created:** [November 12, 2005, 12:49pm UTC](https://www.ruby-forum.com/t/getting-started-with-variable-fixture-tests/49808 "2005-11-12T12:49:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![petermichaux](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/46a35a/32.png) [@petermichaux](https://www.ruby-forum.com/u/petermichaux)\
**Post date:** [November 12, 2005, 12:49pm UTC](https://www.ruby-forum.com/t/getting-started-with-variable-fixture-tests/49808/1 "2005-11-12T12:49:23Z")

</div>

Hi,

I’m trying to use a variable fixture test (like the Rails book page 148)

I am getting the following error.

1. Error:  
test\_read(ProductTest):  
RuntimeError: Called id for nil, which would mistakenly be 4 – if you  
really wanted the id of nil, use object\_id  
test/unit/product\_test.rb:13:in `test\_read’

What am I doing wrong?

Thanks,  
Peter

########## product\_test.rb ##############

class ProductTest \< Test::Unit::TestCase  
fixtures :products

def setup  
@product = Product.find(2)  
end

def test\_read  
assert\_kind\_of Product, @product  
assert\_equal 2, @product.id [http://product.id](http://product.id)

# next line causes the error

assert\_equal @alpha.id [http://alpha.id](http://alpha.id), @product.id  
[http://product.id](http://product.id)  
end

end

########## products.yml ###############

gamma:  
id: 1  
name: gamma  
alpha:  
id: 2  
name: alpha  
beta:  
id: 3  
name: beta

---

<div class="post-metadata">

**Author:** ![petermichaux](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/46a35a/32.png) [@petermichaux](https://www.ruby-forum.com/u/petermichaux)\
**Post date:** [November 12, 2005, 12:49pm UTC](https://www.ruby-forum.com/t/getting-started-with-variable-fixture-tests/49808/2 "2005-11-12T12:49:25Z")

</div>

-----BEGIN PGP SIGNED MESSAGE-----  
Hash: SHA1

On Nov 8, 2005, at 2:26 PM, Peter M. wrote:

> What am I doing wrong?

Please check out the testing section of the 1.0 upgrade guide at  
[http://manuals.rubyonrails.org/read/chapter/118#page319](http://manuals.rubyonrails.org/read/chapter/118#page319)

as well as Mike C.'s article on testing in 1.0:  
[http://clarkware.com/cgi/blosxom/2005/10/24#Rails10FastTesting](http://clarkware.com/cgi/blosxom/2005/10/24#Rails10FastTesting)

jeremy  
-----BEGIN PGP SIGNATURE-----  
Version: GnuPG v1.4.2 (Darwin)

iD8DBQFDcTVNAQHALep9HFYRAmmPAKDiYYWa5SpwwVLuEXYQtarnGWSLZgCg2S8N  
OLIfBFt1gJ+ZXJeNJunQr/A=  
=4OMZ  
-----END PGP SIGNATURE-----

---

<div class="post-metadata">

**Author:** ![petermichaux](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/46a35a/32.png) [@petermichaux](https://www.ruby-forum.com/u/petermichaux)\
**Post date:** [November 12, 2005, 12:49pm UTC](https://www.ruby-forum.com/t/getting-started-with-variable-fixture-tests/49808/3 "2005-11-12T12:49:27Z")

</div>

Hi Jeremy,

Thanks for the help. I’m learning but it takes some time to get used to  
such  
a new and still quickly developing framework like Rails. I appreciate  
the  
pointers.

Peter
