Hi
Im getting this error when running a simple unit test from the book im
learning. I have even copy pasted the code and am not sure why this is
not working
the error is
1) Error:
test_read_with_fixture_variable(ProductTest):
RuntimeError: Called id for nil, which would mistakenly be 4 -- if you
really wanted the id of nil, use object_id
product_test.rb:63:in `test_read_with_fixture_variable''
My YAML file is
version_control_book:
id: 1
title: Pragmatic Version Control
description: How to use version control
image_url: http://.../sk_svn_small.jpg
price: 29.95
date_available: 2005-01-26 00:00:00
My test unit is
class ProductTest < Test::Unit::TestCase
fixtures :products
def setup
@product = Product.find(1)
end
def test_read_with_fixture_variable
assert_kind_of Product, @product
assert_equal @version_control_book.id, @product.id
assert_equal @version_control_book.title, @product.title
assert_equal @version_control_book.description, @product.description
assert_equal @version_control_book.image_url, @product.image_url
assert_equal @version_control_book.price, @product.price
assert_equal @version_control_book.date_available,
@product.date_available
end
end
Ive checked the value of @product.id and it seems its correctly getting
extracted from the database but im not sure why the instance variable
@version_control_book is not getting loaded.
Thanks heaps
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
@version_control_book is not initialized because the default is no longer to instantiate all fixtures in that way (there''s a setting in test_helper that controls that) because it''s a lot slower. instead use products(: version_control_book) Fred -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
You haven''t assigned anything to @version_control_book. I think you need to do something like this to get it from the fixtures: @version_control_book = products(:version_control_book) -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
EXCELLENT! It worked :) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---