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

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

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
end

I’m guessing you missed the two times you typed “@card” instead of
@cart”…

-Brian

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