mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-06 18:21:41 +00:00
add rsepc test
This commit is contained in:
parent
260659349e
commit
b8b3ec0221
@ -8,9 +8,9 @@ class GildedRose
|
||||
next if item.name == "Sulfuras, Hand of Ragnaros"
|
||||
|
||||
if item.name == "Aged Brie"
|
||||
item.quality += 1 if item.quality < 50
|
||||
increases_proportionally_to_times(item)
|
||||
elsif item.name == "Backstage passes to a TAFKAL80ETC concert"
|
||||
increases_proportionally_to_age(item)
|
||||
increases_proportionally_to_times(item)
|
||||
else
|
||||
decrease_quality(item)
|
||||
end
|
||||
@ -36,12 +36,12 @@ class GildedRose
|
||||
item.quality -= decrement if item.quality > 0
|
||||
end
|
||||
|
||||
def increases_proportionally_to_age(item)
|
||||
def increases_proportionally_to_times(item)
|
||||
if item.sell_in <= 10
|
||||
item.quality += 1 if item.quality < 50
|
||||
item.quality += 2 if item.quality < 50
|
||||
end
|
||||
if item.sell_in <= 5
|
||||
item.quality += 1 if item.quality < 50
|
||||
item.quality += 3 if item.quality < 50
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -3,9 +3,49 @@ require 'rspec'
|
||||
require File.join(File.dirname(__FILE__), 'gilded_rose')
|
||||
|
||||
describe GildedRose do
|
||||
it "does not change the name" do
|
||||
items = [Item.new("foo", 0, 0)]
|
||||
GildedRose.new(items).update_quality()
|
||||
expect(items[0].name).to eq "fixme"
|
||||
let(:items) { [Item.new("foo", 10, 20)] }
|
||||
let(:gilded_rose) { GildedRose.new(items) }
|
||||
|
||||
it 'decreases quality and sell in' do
|
||||
gilded_rose.update_quality
|
||||
expect(items[0].sell_in).to eq(9)
|
||||
expect(items[0].quality).to eq(19)
|
||||
end
|
||||
|
||||
it "not decrease quality below 0" do
|
||||
items[0].quality = 0
|
||||
gilded_rose.update_quality
|
||||
expect(items[0].quality).to eq(0)
|
||||
end
|
||||
|
||||
context "with Aged Brie" do
|
||||
let(:items) { [Item.new("Aged Brie", 10, 20)] }
|
||||
|
||||
it 'quality never be more than 50' do
|
||||
items[0].quality = 50
|
||||
gilded_rose.update_quality
|
||||
expect(items[0].quality).to eq(50)
|
||||
end
|
||||
|
||||
it 'increases proportionally to time until 10' do
|
||||
items[0].sell_in = 7
|
||||
gilded_rose.update_quality
|
||||
expect(items[0].quality).to eq(22)
|
||||
end
|
||||
|
||||
it 'increases proportionally to time until 5' do
|
||||
items[0].sell_in = 5
|
||||
gilded_rose.update_quality
|
||||
expect(items[0].quality).to eq(25)
|
||||
end
|
||||
end
|
||||
|
||||
context 'with Conjured' do
|
||||
let(:items) { [Item.new("Conjured", 10, 20)] }
|
||||
|
||||
it 'decreases by 2' do
|
||||
gilded_rose.update_quality
|
||||
expect(items[0].quality).to eq(18)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
Reference in New Issue
Block a user