small medium large xlarge

Generic-user-small
21 Jan 2014, 16:46
victor sosa (1 post)

Hi,

I need some help here, I am getting this error running the rake test:

1) Failure: CartTest#test_cart_should_create_a_new_line_item_when_adding_a_new_product [/home/vns/workspace/depot/test/models/cart_test.rb:16]: Expected: 1 Actual: 0

2) Failure: CartTest#test_cart_should_update_an_existing_line_item_when_adding_an_existing_product [/home/vns/workspace/depot/test/models/cart_test.rb: 26]: Expected: 1 Actual: 0

It looks like the product is not been added ONLY in the test case, because the code is working perfectly when I run the server. It is just the test case that is not working.

products.yml

one:
  title: MyString
  description: MyText
  image_url: MyString
  price: 9.99

two:
  title: MyString
  description: MyText
  image_url: MyString
  price: 9.99

cart_test.rb

class CartTest < ActiveSupport::TestCase
  # test "the truth" do
  #   assert true
  # end

  def new_cart_with_one_product(product_name)
    cart = Cart.new
    cart.add_product(products(product_name).id)
    cart
  end

  test 'cart should create a new line item when adding a new product' do
    cart = new_cart_with_one_product(:one)
    assert_equal 1, cart.line_items.count
    # Add a new product
    cart.add_product(products(:ruby).id)
    assert_equal 2, cart.line_items.count
  end

  test 'cart should update an existing line item when adding an existing product' do
    cart = new_cart_with_one_product(:one)
    # Re-add the same product
    cart.add_product(products(:one).id)
    assert_equal 1, cart.line_items.count
  end  
end
You must be logged in to comment