+
+
+
-
+
+ 1
+
+
+
+
+
+
+
require 'spec_helper'
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+ 1
+
+
+
+
+
+
+
RSpec.describe FoodTruck do
+
+
+
+
+
-
+
+ 1
+
+
+
+
+
+
+
before :each do
+
+
+
+
+
-
+
+ 7
+
+
+
+
+
+
+
@food_truck = FoodTruck.new("Rocky Mountain Pies")
+
+
+
+
+
-
+
+ 7
+
+
+
+
+
+
+
@item1 = Item.new({name: 'Peach Pie (Slice)', price: "$3.75"})
+
+
+
+
+
-
+
+ 7
+
+
+
+
+
+
+
@item2 = Item.new({name: 'Apple Pie (Slice)', price: '$2.50'})
+
+
+
+
+
-
+
+ 7
+
+
+
+
+
+
+
@item3 = Item.new({name: "Peach-Raspberry Nice Cream", price: "$5.30"})
+
+
+
+
+
-
+
+ 7
+
+
+
+
+
+
+
@item4 = Item.new({name: "Banana Nice Cream", price: "$4.25"})
+
+
+
+
+
-
+
+
+
+
+
+
+
end
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+ 1
+
+
+
+
+
+
+
it 'exists and has attributes' do
+
+
+
+
+
-
+
+ 1
+
+
+
+
+
+
+
expect(@food_truck).to be_an_instance_of(FoodTruck)
+
+
+
+
+
-
+
+ 1
+
+
+
+
+
+
+
expect(@food_truck.name).to eq("Rocky Mountain Pies")
+
+
+
+
+
-
+
+ 1
+
+
+
+
+
+
+
expect(@food_truck.inventory).to eq({})
+
+
+
+
+
-
+
+
+
+
+
+
+
end
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+ 1
+
+
+
+
+
+
+
it 'can check stock of an item' do
+
+
+
+
+
-
+
+ 1
+
+
+
+
+
+
+
expect(@food_truck.check_stock(@item1)).to eq(0)
+
+
+
+
+
-
+
+
+
+
+
+
+
end
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+ 1
+
+
+
+
+
+
+
it 'can stock items' do
+
+
+
+
+
-
+
+ 1
+
+
+
+
+
+
+
@food_truck.stock(@item1, 30)
+
+
+
+
+
-
+
+ 1
+
+
+
+
+
+
+
expect(@food_truck.inventory).to eq({@item1 => 30})
+
+
+
+
+
-
+
+ 1
+
+
+
+
+
+
+
expect(@food_truck.check_stock(@item1)).to eq(30)
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+ 1
+
+
+
+
+
+
+
@food_truck.stock(@item1, 25)
+
+
+
+
+
-
+
+ 1
+
+
+
+
+
+
+
expect(@food_truck.check_stock(@item1)).to eq(55)
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+ 1
+
+
+
+
+
+
+
@food_truck.stock(@item2, 12)
+
+
+
+
+
-
+
+ 1
+
+
+
+
+
+
+
expect(@food_truck.inventory).to eq({@item1 => 55, @item2 => 12})
+
+
+
+
+
-
+
+
+
+
+
+
+
end
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+ 1
+
+
+
+
+
+
+
it 'can calculate potential revenue' do
+
+
+
+
+
-
+
+ 1
+
+
+
+
+
+
+
@food_truck.stock(@item1, 35)
+
+
+
+
+
-
+
+ 1
+
+
+
+
+
+
+
@food_truck.stock(@item2, 7)
+
+
+
+
+
-
+
+ 1
+
+
+
+
+
+
+
expect(@food_truck.potential_revenue).to eq(148.75)
+
+
+
+
+
-
+
+
+
+
+
+
+
end
+
+
+
+
+
-
+
+
+
+
+
+
+
#edge cases
+
+
+
+
+
-
+
+ 1
+
+
+
+
+
+
+
it 'can stock the same item multiple times' do
+
+
+
+
+
-
+
+ 1
+
+
+
+
+
+
+
@food_truck.stock(@item1, 30)
+
+
+
+
+
-
+
+ 1
+
+
+
+
+
+
+
@food_truck.stock(@item1, 20)
+
+
+
+
+
-
+
+ 1
+
+
+
+
+
+
+
expect(@food_truck.check_stock(@item1)).to eq(50)
+
+
+
+
+
-
+
+
+
+
+
+
+
end
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+ 1
+
+
+
+
+
+
+
it 'returns 0 for items not stocked' do
+
+
+
+
+
-
+
+ 1
+
+
+
+
+
+
+
expect(@food_truck.check_stock(@item3)).to eq(0)
+
+
+
+
+
-
+
+
+
+
+
+
+
end
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+ 1
+
+
+
+
+
+
+
it 'calculates potential revenue with empty inventory' do
+
+
+
+
+
-
+
+ 1
+
+
+
+
+
+
+
expect(@food_truck.potential_revenue).to eq(0)
+
+
+
+
+
-
+
+
+
+
+
+
+
end
+
+
+
+
+
-
+
+
+
+
+
+
+
end
+
+
+
+
+