-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgilded_rose_spec.rb
137 lines (120 loc) · 4.89 KB
/
gilded_rose_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
require File.join(File.dirname(__FILE__), 'gilded_rose')
describe GildedRose do
describe "#update_quality" do
context "Generic Item" do
context "when quality less then 50" do
it "decreases quality in 1 when sell in is above 0" do
items = [GenericItem.new("Generic Item", 11, 40)]
GildedRose.new(items).update_quality()
expect(items[0].sell_in).to eq 10
expect(items[0].quality).to eq 39
end
it "decreases quality in 2 when sell in is below 1" do
items = [GenericItem.new("Generic Item", 0, 40)]
GildedRose.new(items).update_quality()
expect(items[0].sell_in).to eq -1
expect(items[0].quality).to eq 38
end
end
end
context "Conjured Item" do
context "when quality less then 50" do
it "decreases quality in 2" do
items = [ConjuredItem.new("Conjured Item", 11, 40)]
GildedRose.new(items).update_quality()
expect(items[0].sell_in).to eq 10
expect(items[0].quality).to eq 38
end
end
end
context "Aged Brie" do
context "when quality is above 50" do
it "quality keeps the same if sell in is above 0" do
items = [AgedBrieItem.new("Aged Brie", 10, 50)]
GildedRose.new(items).update_quality()
expect(items[0].sell_in).to eq 9
expect(items[0].quality).to eq 50
end
it "quality keeps the same if sell in is below 0" do
items = [AgedBrieItem.new("Aged Brie", 0, 50)]
GildedRose.new(items).update_quality()
expect(items[0].sell_in).to eq -1
expect(items[0].quality).to eq 50
end
end
context "when quality below 50" do
it "quality increases in 1 if sell in is above 0" do
items = [AgedBrieItem.new("Aged Brie", 10, 30)]
GildedRose.new(items).update_quality()
expect(items[0].sell_in).to eq 9
expect(items[0].quality).to eq 31
end
it "quality increases in 2 if sell in is equal 0" do
items = [AgedBrieItem.new("Aged Brie", 0, 30)]
GildedRose.new(items).update_quality()
expect(items[0].sell_in).to eq -1
expect(items[0].quality).to eq 32
end
it "quality increases in 2 if sell in below 0" do
items = [AgedBrieItem.new("Aged Brie", -1, 32)]
GildedRose.new(items).update_quality()
expect(items[0].sell_in).to eq -2
expect(items[0].quality).to eq 34
end
end
end
context "Backstage passes to a TAFKAL80ETC concert" do
context "when quality is less then 50" do
it "quality increases 1 if sell in is above 10" do
items = [BackstageItem.new("Backstage passes to a TAFKAL80ETC concert", 11, 40)]
GildedRose.new(items).update_quality()
expect(items[0].sell_in).to eq 10
expect(items[0].quality).to eq 41
end
it "quality increases 2 if sell in is below 10 and above 5" do
items = [BackstageItem.new("Backstage passes to a TAFKAL80ETC concert", 10, 40)]
GildedRose.new(items).update_quality()
expect(items[0].sell_in).to eq 9
expect(items[0].quality).to eq 42
end
it "quality increases 3 if sell in is below 5 and above 0" do
items = [BackstageItem.new("Backstage passes to a TAFKAL80ETC concert", 5, 40)]
GildedRose.new(items).update_quality()
expect(items[0].sell_in).to eq 4
expect(items[0].quality).to eq 43
end
it "quality becomes 0 if sell in is equal 0" do
items = [BackstageItem.new("Backstage passes to a TAFKAL80ETC concert", 0, 40)]
GildedRose.new(items).update_quality()
expect(items[0].sell_in).to eq -1
expect(items[0].quality).to eq 0
end
end
context "when quality bigger then 50" do
it "quality keeps 50 when sell in is above 0" do
items = [BackstageItem.new("Backstage passes to a TAFKAL80ETC concert", 5, 50)]
GildedRose.new(items).update_quality()
expect(items[0].sell_in).to eq 4
expect(items[0].quality).to eq 50
end
it "quality becomes 0 if sell in is equal 0" do
items = [BackstageItem.new("Backstage passes to a TAFKAL80ETC concert", 0, 50)]
GildedRose.new(items).update_quality()
expect(items[0].sell_in).to eq -1
expect(items[0].quality).to eq 0
end
end
end
context "Sulfuras, Hand of Ragnaros" do
it "always stays the same" do
items = [SulfurasItem.new("Sulfuras, Hand of Ragnaros", 0, 80)]
GildedRose.new(items).update_quality()
expect(items[0].sell_in).to eq 0
expect(items[0].quality).to eq 80
GildedRose.new(items).update_quality()
expect(items[0].sell_in).to eq 0
expect(items[0].quality).to eq 80
end
end
end
end