Skip to content

Commit 925b83c

Browse files
committed
Define order and basket classes
1 parent 828dc25 commit 925b83c

4 files changed

Lines changed: 50 additions & 0 deletions

File tree

lib/basket.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Basket class
2+
class Basket
3+
attr_reader :current_order
4+
5+
def initialize
6+
@current_order = nil
7+
end
8+
end

lib/order.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Order class
2+
class Order
3+
attr_reader :items, :basket
4+
5+
def initialize(basket)
6+
@items = []
7+
@basket = basket
8+
end
9+
end

spec/basket_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
require 'rspec'
2+
require 'spec_helper'
3+
require './lib/basket'
4+
5+
describe Basket do
6+
describe '#initialize' do
7+
it 'should have a current_order attribute which is a nil' do
8+
instance = Basket.new
9+
10+
expect(instance.current_order).to be_nil
11+
end
12+
end
13+
end

spec/order_spec.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
require 'rspec'
2+
require 'spec_helper'
3+
require './lib/order'
4+
5+
describe Order do
6+
describe '#initialize' do
7+
it 'should have a items attribute which is an empty Array' do
8+
instance = Order.new(Basket.new)
9+
10+
expect(instance.items).to be_a Array
11+
expect(instance.items).to be_empty
12+
end
13+
14+
it 'should have a basket attribute which is an instance of Basket' do
15+
instance = Order.new(Basket.new)
16+
17+
expect(instance.basket).to be_a Basket
18+
end
19+
end
20+
end

0 commit comments

Comments
 (0)