Getting started with variable fixture tests


#1

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

next line causes the error

assert_equal @alpha.id http://alpha.id, @product.id
http://product.id
end

end

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

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


#2

-----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

as well as Mike C.'s article on testing in 1.0:
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-----


#3

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