Skip to content

Instantly share code, notes, and snippets.

@voxxit
Created March 9, 2013 00:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save voxxit/5121566 to your computer and use it in GitHub Desktop.
Save voxxit/5121566 to your computer and use it in GitHub Desktop.
ShoppingCart

Shopping Cart

In this example, we'll ask you to build a ShoppingCart class which contains multiple items, and provides a method of adding, removing and updating items belonging to a cart. The ShoppingCart class is a plain Ruby class, which should only use objects which belong to the standard Ruby library.

First, fork this example. Click 'Fork' above. Then, you'll clone, edit, add, commit and push your changes as necessary. Notify us with a link to your forked example when you're finished.

Please first develop tests (either using TDD or BDD libraries of your choice -- we like Test::Unit and RSpec, but you're free to use whatever method you're comfortable with) before you write actual code. We're a test-driven shop.

Acceptance Criteria

The ShoppingCart class should contain an array of items, and each item should have an ID, a price and a quantity.

Here are some stories you should complete:

  1. Should be able to add an item to the shopping cart
  2. Should be able to remove an item from the shopping cart
  3. Should be able to update the quantity and price of an item in the shopping cart
  4. Should be able to calculate the total for the shopping cart
  5. Should be able to empty the shopping cart
  6. Should remove an item from the cart if the quantity falls below zero
  7. Should ensure an item's price is always greater than or equal to zero

If you have any questions, please email joshua.delsman@rovicorp.com.

class ShoppingCart
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment