From b8b3ec02214008184602a96870a9054be9bf4b51 Mon Sep 17 00:00:00 2001 From: Volodia Date: Wed, 5 Jun 2024 07:16:52 +0300 Subject: [PATCH] add rsepc test --- ruby/gilded_rose.rb | 10 ++++----- ruby/gilded_rose_spec.rb | 48 ++++++++++++++++++++++++++++++++++++---- 2 files changed, 49 insertions(+), 9 deletions(-) diff --git a/ruby/gilded_rose.rb b/ruby/gilded_rose.rb index 436b0db7..c030cb94 100644 --- a/ruby/gilded_rose.rb +++ b/ruby/gilded_rose.rb @@ -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 diff --git a/ruby/gilded_rose_spec.rb b/ruby/gilded_rose_spec.rb index 015a759f..d24fd493 100644 --- a/ruby/gilded_rose_spec.rb +++ b/ruby/gilded_rose_spec.rb @@ -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