Basic Product class

This commit is contained in:
David Underwood
2026-07-21 09:39:05 -04:00
parent 33fff52042
commit b65eca8356
2 changed files with 37 additions and 0 deletions
+19
View File
@@ -0,0 +1,19 @@
class Product
def initialize(price: 0.00, id:, description: '')
@price = price
@id = id
@description = description
end
def price
@price
end
def id
@id
end
def description
@description
end
end
+18
View File
@@ -0,0 +1,18 @@
require "minitest/autorun"
require "product.rb"
class ProductTest < Minitest::Test
def test_that_missing_id_raises_an_error
assert_raises ArgumentError do
Product.new()
end
end
def test_that_initializing_a_product_sets_instance_variables
product = Product.new(id: 'PICO2', price: 4.00)
assert_equal 'PICO2', product.id
assert_equal 4.00, product.price
end
end