Skip to content

Instantly share code, notes, and snippets.

@theRealNG
Last active February 7, 2024 00:31
Show Gist options
  • Save theRealNG/a646ca30141c7172e794641e92aaef1d to your computer and use it in GitHub Desktop.
Save theRealNG/a646ca30141c7172e794641e92aaef1d to your computer and use it in GitHub Desktop.
Shopping Cart test cases using RSpec
require "rspec"
describe "ShoppingCart" do
before { @cart = ShoppingCart.new }
describe "#total_price_with_taxes" do
it "calculates the total price with taxes" do
# Mocking external calls
allow(TaxCalculator).to receive(:calculate_tax).and_return(1.50)
allow(InventoryService).to receive(:check_stock).and_return(true)
@cart.add_item(Item.new("Apple", 10.00))
expect(@cart.total_price_with_taxes).to eq(11.50)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment