Basic Product class
This commit is contained in:
+19
@@ -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
|
||||||
@@ -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
|
||||||
Reference in New Issue
Block a user