mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-15 14:31:28 +00:00
Extract normal item cases
All tests pass, both rspec as texttests. This gives me a good base to start implementing Conjured items. The idea is to implement Conjured items first before starting to clean up the code. My thought process when implementing new code is always: make it work -> make it safe -> clean it up
This commit is contained in:
parent
14363a173b
commit
cc494bf27e
@ -14,43 +14,7 @@ class GildedRose
|
||||
when 'Sulfuras, Hand of Ragnaros'
|
||||
update_sulfuras_quality(item)
|
||||
else
|
||||
if item.name != "Aged Brie" and item.name != "Backstage passes to a TAFKAL80ETC concert"
|
||||
if item.quality > 0
|
||||
item.quality = item.quality - 1
|
||||
end
|
||||
else
|
||||
if item.quality < 50
|
||||
item.quality = item.quality + 1
|
||||
if item.name == "Backstage passes to a TAFKAL80ETC concert"
|
||||
if item.sell_in < 11
|
||||
if item.quality < 50
|
||||
item.quality = item.quality + 1
|
||||
end
|
||||
end
|
||||
if item.sell_in < 6
|
||||
if item.quality < 50
|
||||
item.quality = item.quality + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
item.sell_in = item.sell_in - 1
|
||||
if item.sell_in < 0
|
||||
if item.name != "Aged Brie"
|
||||
if item.name != "Backstage passes to a TAFKAL80ETC concert"
|
||||
if item.quality > 0
|
||||
item.quality = item.quality - 1
|
||||
end
|
||||
else
|
||||
item.quality = item.quality - item.quality
|
||||
end
|
||||
else
|
||||
if item.quality < 50
|
||||
item.quality = item.quality + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
update_normal_quality(item)
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -73,6 +37,13 @@ class GildedRose
|
||||
item.quality = 50 if item.quality > 50
|
||||
end
|
||||
|
||||
def update_normal_quality(item)
|
||||
item.sell_in -= 1
|
||||
item.quality -= 1
|
||||
item.quality -= 1 if item.sell_in.negative?
|
||||
item.quality = 0 if item.quality.negative?
|
||||
end
|
||||
|
||||
def update_sulfuras_quality(item); end
|
||||
end
|
||||
|
||||
|
||||
@ -23,20 +23,6 @@ describe GildedRose do
|
||||
end
|
||||
end
|
||||
|
||||
context 'when sell by date has passed' do
|
||||
let(:sell_in) { 0 }
|
||||
|
||||
it 'lowers quality by 2' do
|
||||
subject.update_quality
|
||||
expect(items[0].quality).to eq 1
|
||||
end
|
||||
|
||||
it 'lowers sell_in by 1' do
|
||||
subject.update_quality
|
||||
expect(items[0].sell_in).to eq -1
|
||||
end
|
||||
end
|
||||
|
||||
context 'when 1 day left' do
|
||||
let(:sell_in) { 1 }
|
||||
|
||||
@ -51,9 +37,23 @@ describe GildedRose do
|
||||
end
|
||||
end
|
||||
|
||||
context 'when sell by date has passed' do
|
||||
let(:sell_in) { 0 }
|
||||
|
||||
it 'lowers quality by 2' do
|
||||
subject.update_quality
|
||||
expect(items[0].quality).to eq 1
|
||||
end
|
||||
|
||||
it 'lowers sell_in by 1' do
|
||||
subject.update_quality
|
||||
expect(items[0].sell_in).to eq -1
|
||||
end
|
||||
end
|
||||
|
||||
it 'does never lower the quality below 0' do
|
||||
items = [Item.new(item_name, sell_in, 0)]
|
||||
subject.update_quality
|
||||
GildedRose.new(items).update_quality
|
||||
expect(items[0].quality).to eq 0
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
Reference in New Issue
Block a user