File tree Expand file tree Collapse file tree 8 files changed +122
-0
lines changed Expand file tree Collapse file tree 8 files changed +122
-0
lines changed Original file line number Diff line number Diff line change 1
1
source 'https://rubygems.org'
2
2
3
3
gem 'bundler'
4
+ gem 'money'
4
5
gem 'rspec'
5
6
6
7
group :test do
Original file line number Diff line number Diff line change 5
5
simplecov
6
6
diff-lcs (1.3 )
7
7
docile (1.1.5 )
8
+ i18n (0.8.6 )
8
9
json (2.1.0 )
10
+ money (6.9.0 )
11
+ i18n (>= 0.6.4 , < 0.9 )
9
12
rake (12.0.0 )
10
13
rspec (3.6.0 )
11
14
rspec-core (~> 3.6.0 )
@@ -32,6 +35,7 @@ PLATFORMS
32
35
DEPENDENCIES
33
36
bundler
34
37
codeclimate-test-reporter (~> 1.0.0 )
38
+ money
35
39
rake
36
40
rspec
37
41
simplecov
Original file line number Diff line number Diff line change
1
+ require 'money'
2
+ require_relative 'pack'
3
+ I18n . enforce_available_locales = false
4
+
5
+ # Item class
6
+ class Item
7
+ attr_reader :name
8
+
9
+ def initialize ( name )
10
+ @name = name
11
+ end
12
+ end
Original file line number Diff line number Diff line change
1
+ # Pack class
2
+ class Pack
3
+ attr_reader :qty , :price
4
+
5
+ def initialize ( qty , price )
6
+ @qty = qty
7
+ @price = price
8
+ end
9
+ end
Original file line number Diff line number Diff line change
1
+ require_relative 'item'
2
+
3
+ # Watermelon class
4
+ class Watermelon < Item
5
+ attr_reader :pack
6
+
7
+ OPTIONS = [ 3 , 5 ] . freeze
8
+
9
+ def initialize ( name )
10
+ super ( name )
11
+ @pack = nil
12
+ end
13
+
14
+ def pack_size ( selection )
15
+ return unless OPTIONS . include? ( selection )
16
+
17
+ return @pack = Pack . new ( 3 , Money . new ( 699 , 'NZD' ) ) if selection == 3
18
+ @pack = Pack . new ( 5 , Money . new ( 899 , 'NZD' ) ) if selection == 5
19
+ end
20
+ end
21
+
22
+ # watermelon = Watermelon.new('watermelon')
23
+ # puts watermelon
24
+
25
+ # size = watermelon.pack_size(3)
26
+
27
+ # puts size.qty
28
+ # puts size.price
Original file line number Diff line number Diff line change
1
+ require 'rspec'
2
+ require 'spec_helper'
3
+ require './lib/item'
4
+
5
+ describe Item do
6
+ describe '#initialize' do
7
+ it 'should have a name attribute which is a String' do
8
+ instance = Item . new ( 'Watermelons' )
9
+
10
+ expect ( instance . name ) . to be_a String
11
+ expect ( instance . name ) . to eq 'Watermelons'
12
+ end
13
+ end
14
+ end
Original file line number Diff line number Diff line change
1
+ require 'rspec'
2
+ require 'spec_helper'
3
+ require './lib/pack'
4
+
5
+ describe Pack do
6
+ describe '#initialize' do
7
+ it 'should have a qty attribute which is an Integer' do
8
+ instance = Pack . new ( 3 , 6.99 )
9
+
10
+ expect ( instance . qty ) . to be_a Integer
11
+ expect ( instance . qty ) . to eq 3
12
+ end
13
+
14
+ it 'should have a price attribute which is an instance of Money' do
15
+ instance = Pack . new ( 3 , Money . new ( 699 , 'NZD' ) )
16
+
17
+ expect ( instance . price ) . to be_a Money
18
+ end
19
+ end
20
+ end
Original file line number Diff line number Diff line change
1
+ require 'rspec'
2
+ require 'spec_helper'
3
+ require './lib/watermelon'
4
+
5
+ describe Watermelon do
6
+ describe '#initialize' do
7
+ it 'should have a name attribute which is an String' do
8
+ instance = Watermelon . new ( 'watermelon' )
9
+
10
+ expect ( instance . name ) . to be_a String
11
+ expect ( instance . name ) . to eq 'watermelon'
12
+ end
13
+
14
+ it 'should have a pack attribute which is nil' do
15
+ instance = Watermelon . new ( 'watermelon' )
16
+
17
+ expect ( instance . pack ) . to be_nil
18
+ end
19
+ end
20
+
21
+ describe '#pack_size' do
22
+ it 'should return nil if selection is not present in OPTIONS array' do
23
+ instance = Watermelon . new ( 'watermelon' )
24
+
25
+ expect ( instance . pack_size ( 1 ) ) . to be_nil
26
+ end
27
+
28
+ it 'should return an instance of Pack if selection is present in OPTIONS array' do
29
+ instance = Watermelon . new ( 'watermelon' )
30
+
31
+ expect ( instance . pack_size ( 3 ) ) . to be_a Pack
32
+ end
33
+ end
34
+ end
You can’t perform that action at this time.
0 commit comments