Implement the calculate_total
method so that the tests pass. The method should accept an order represented as an Array of Hashes and calculate the total cost of the order. Each Hash should represent a line item of the order with a key for the quantity and a key for the unit price of the item. After calculating the total of the order and additional tax rate of 5% should be added. The return value should be a string, the total formatted as a price with 2 decimal points and a dollar sign, such as $1.99
.
-
Don't hard code the tax rate as a magic number. If you aren't sure how to avoid that, refer to this slide on when to use constants
-
Make sure you know how to create an Array of Hashes first. If you are not sure, re-read the slides on Arrays and Hashes
-
Not sure how to format a float as a dollar amount? Re-read the slide on string formatting
-
To call the
calculate_total
method with no line items, you have to pass in an empty array. Can you make it so that if can work with no argument at all? -
To call the
calculate_total
method with multiple line items, you have to pass in an array of hashes. Can you make it so that it will work with each Hash as an argument to the method? -
Read about RSpec. Convert the Minitest tests in to RSpec specs.