Nate
2006-May-19 02:08 UTC
[Rails] new to rails; problem with testing section in Agile book
Hello, I should give the expected disclaimer that I am brand new to rails and am going through the Agile web development with Rails book right now. I am in the testing section and I can''t get past an error. this is my cart_test.rb test file: require File.dirname(__FILE__) + ''/../test_helper'' class CartTest < Test::Unit::TestCase fixtures :products def setup @cart = Cart.new end # Replace this with your real tests. def test_add_unique_products @cart.add_product products(:version_control_book) @cart.add_product products(:automation_book) assert_equal products(:version_control_book).price + products(:automation_book).price, @cart.total_price assert_equal 2, @cart.items.size end def test_add_duplicate_product @card.add_product products(:version_control_book) @card.add_product products(:version_control_book) assert_equal 2*products(:version_control_book).price, @cart.total_price assert_equal 1, @cart.items.size end end and I am getting this error: 1) Error: test_add_duplicate_product(CartTest): NoMethodError: You have a nil object when you didn''t expect it! The error occured while evaluating nil.add_product test/unit/cart_test.rb:17:in `test_add_duplicate_product'' If there is more information i need to post please let me know. Any help is appreciated! Thanks, Nate -- Posted via http://www.ruby-forum.com/.
Simon Robson
2006-May-19 02:24 UTC
[Rails] new to rails; problem with testing section in Agile book
Hi Nate, Nate wrote:> def test_add_duplicate_product > @card.add_product products(:version_control_book) > @card.add_product products(:version_control_book)Should that be @cart in the two lines above? Looks like a simple typo - but they can be the most frustrating!> 1) Error: > test_add_duplicate_product(CartTest): > NoMethodError: You have a nil object when you didn''t expect it! > The error occured while evaluating nil.add_product > test/unit/cart_test.rb:17:in `test_add_duplicate_product'' >Simon
Brian Hughes
2006-May-19 02:30 UTC
[Rails] new to rails; problem with testing section in Agile book
On May 18, 2006, at 10:08 PM, Nate wrote:> def test_add_duplicate_product > @card.add_product products(:version_control_book) > @card.add_product products(:version_control_book) > assert_equal 2*products(:version_control_book).price, > @cart.total_price > assert_equal 1, @cart.items.size > endI''m guessing you missed the two times you typed "@card" instead of "@cart"... -Brian
Nate
2006-May-19 06:50 UTC
[Rails] Re: new to rails; problem with testing section in Agile book
Brian and Simon, I must say that I am COMPLETELY embarassed! I had been looking at that for multiple hours and couldn''t find it at all. I thought it had something to do with the book written pre rails 1.0 so i did some research about the changes made in the newer version and learned about use_transitional_fixtures vs use_instantiated_fixtures. Anyway, that last part is irrelavant; thanks so much for find my glaring mistake, i wish i could erase this post! LOL thanks again, Nate -- Posted via http://www.ruby-forum.com/.