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:
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!
Should that be @cart in the two lines above? Looks like a simple typo -
but they can be the most frustrating!
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’
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
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.