mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-17 23:41:27 +00:00
extracted #special_item? method and implemented in update quality section
This commit is contained in:
parent
7a8792f64f
commit
58be55719a
@ -38,13 +38,11 @@ class GildedRose
|
|||||||
|
|
||||||
|
|
||||||
if item.sell_in < 0
|
if item.sell_in < 0
|
||||||
|
|
||||||
if item.name != "Aged Brie"
|
if item.name != "Aged Brie"
|
||||||
|
|
||||||
if !item.name.downcase.match /backstage/
|
if !item.name.downcase.match /backstage/
|
||||||
if item.quality > 0
|
update_normal_quality(item) unless sulfuras?(item)
|
||||||
if !sulfuras?(item)
|
|
||||||
update_normal_quality(item)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
item.quality = 0
|
item.quality = 0
|
||||||
end
|
end
|
||||||
@ -53,6 +51,9 @@ class GildedRose
|
|||||||
item.quality = item.quality + 1
|
item.quality = item.quality + 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -64,6 +65,10 @@ class GildedRose
|
|||||||
def self.sulfuras?(item)
|
def self.sulfuras?(item)
|
||||||
!item.name.downcase.match( /sulfuras/).nil?
|
!item.name.downcase.match( /sulfuras/).nil?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.special_item?(item)
|
||||||
|
!item.name.downcase.match( /Aged Brie/ || /backstage/) || !sulfuras?(item)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class Item
|
class Item
|
||||||
|
|||||||
@ -112,6 +112,23 @@ let(:sulfarus) { Item.new('Sulfuras, Hand of Ragnaros', 50, 80) }
|
|||||||
expect(GildedRose.sulfuras?(item_double)).to eq false
|
expect(GildedRose.sulfuras?(item_double)).to eq false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '#special_item?' do
|
||||||
|
it 'returns true for aged brie' do
|
||||||
|
item_double = double :item, name: "Aged Brie"
|
||||||
|
expect(GildedRose.special_item?(item_double)).to eq true
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns true for backstage passes' do
|
||||||
|
item_double = double :item, name: "backstage pass for gong party"
|
||||||
|
expect(GildedRose.special_item?(item_double)).to eq true
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns true for sulfuras' do
|
||||||
|
sulfuras_double = double :selfarus, name: 'Sulfuras'
|
||||||
|
expect(GildedRose.special_item?(sulfuras_double)).to eq true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user