Forum: Ruby on Rails getting started with variable fixture tests

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Eea3feaacbe44706164289d068d94828?d=identicon&s=25 petermichaux (Guest)
on 2005-11-12 12:49
(Received via mailing list)
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
24d2f8804e6bb4b7ea6bd11e0a586470?d=identicon&s=25 jeremy (Guest)
on 2005-11-12 12:49
(Received via mailing list)
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Nov 8, 2005, at 2:26 PM, Peter Michaux 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 Clark's article on testing in 1.0:
   http://clarkware.com/cgi/blosxom/2005/10/24#Rails1...

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

iD8DBQFDcTVNAQHALep9HFYRAmmPAKDiYYWa5SpwwVLuEXYQtarnGWSLZgCg2S8N
OLIfBFt1gJ+ZXJeNJunQr/A=
=4OMZ
-----END PGP SIGNATURE-----
Eea3feaacbe44706164289d068d94828?d=identicon&s=25 petermichaux (Guest)
on 2005-11-12 12:49
(Received via mailing list)
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
This topic is locked and can not be replied to.