Unit Testing failure

When I run the unit testing code in Unit Testing Models chapter of the
Agile Rails book, I get the
following error:

$ ruby test/unit/cart_test.rb
Loaded suite test/unit/cart_test
Started
F.
Finished in 0.21806 seconds.

  1. Failure:
    test_add_duplicate_product(CartTest) [test/unit/cart_test.rb:22]:
    <4690> expected but was
    <3579>.

2 tests, 3 assertions, 1 failures, 0 errors

require File.dirname(FILE) + ‘/…/test_helper’

class CartTest < Test::Unit::TestCase
fixtures :products

def setup
@cart = Cart.new
@rails = products(:rails_book)
@ruby = products(:ruby_book)
end

def test_add_unique_products
@cart.add_product @rails
@cart.add_product @ruby
assert_equal 2, @cart.items.size
assert_equal @rails.price + @ruby.price, @cart.total_price
end

def test_add_duplicate_product
@cart.add_product @rails
@cart.add_product @ruby
assert_equal 2*@rails.price, @cart.total_price
assert_equal 1, @cart.items.size
assert_equal 2, @cart.items[0].quantity
end

end

Could someone please tell me why I am getting this error? TIA

http://www.ProblemSolvingSkill.net
Hone your problem-solving skills

On Jun 25, 2006, at 10:28 pm, Bala P. wrote:

  1. Failure:
    test_add_duplicate_product(CartTest) [test/unit/cart_test.rb:22]:
    <4690> expected but was
    <3579>.

If I got the line numbers right, I’m guessing that’s because “rails”
costs 2480 and “ruby” costs 1099:

@cart.add_product @rails
@cart.add_product @ruby
assert_equal 2*@rails.price, @cart.total_price

(Also the next 2 lines you wrote assume you added one book twice)

Ashley

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs