mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-15 22:41:30 +00:00
basic test for ordinary item, made update_quality method into an instance method
This commit is contained in:
parent
06c28be5b1
commit
fb4d5aad4d
@ -1,11 +1,11 @@
|
|||||||
class GildedRose
|
class GildedRose
|
||||||
|
|
||||||
def initialize(items)
|
# def initialize(items)
|
||||||
@items = items
|
# @items = items
|
||||||
end
|
# end
|
||||||
|
|
||||||
def update_quality()
|
def self.update_quality(items)
|
||||||
@items.each do |item|
|
items.map do |item|
|
||||||
if item.name != "Aged Brie" and item.name != "Backstage passes to a TAFKAL80ETC concert"
|
if item.name != "Aged Brie" and item.name != "Backstage passes to a TAFKAL80ETC concert"
|
||||||
if item.quality > 0
|
if item.quality > 0
|
||||||
if item.name != "Sulfuras, Hand of Ragnaros"
|
if item.name != "Sulfuras, Hand of Ragnaros"
|
||||||
@ -50,6 +50,7 @@ class GildedRose
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
items
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -1,13 +1,33 @@
|
|||||||
require File.join(File.dirname(__FILE__), 'gilded_rose')
|
require 'gilded_rose'
|
||||||
|
|
||||||
describe GildedRose do
|
describe GildedRose do
|
||||||
|
let(:potato) { Item.new('potato', 15, 2)}
|
||||||
describe "#update_quality" do
|
describe "#update_quality" do
|
||||||
it "does not change the name" do
|
it "does not change the name" do
|
||||||
items = [Item.new("foo", 0, 0)]
|
items = [Item.new("foo", 0, 0)]
|
||||||
GildedRose.new(items).update_quality()
|
GildedRose.update_quality(items)
|
||||||
expect(items[0].name).to eq "foo"
|
expect(items[0].name).to eq "foo"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'should decrese the quality of normal item' do
|
||||||
|
items = [potato]
|
||||||
|
GildedRose.update_quality(items)
|
||||||
|
expect(items.first.quality).to eq (1)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should decrese the sellIn of normal item' do
|
||||||
|
items = [potato]
|
||||||
|
GildedRose.update_quality(items)
|
||||||
|
expect(items.first.sell_in).to eq (14)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should decrease value of normal items by 2 when sell_in date passes' do
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
# rubocop:disable all
|
||||||
require File.join(File.dirname(__FILE__), 'gilded_rose')
|
require File.join(File.dirname(__FILE__), 'gilded_rose')
|
||||||
require 'test/unit'
|
require 'test/unit'
|
||||||
|
|
||||||
@ -9,4 +10,5 @@ class TestUntitled < Test::Unit::TestCase
|
|||||||
assert_equal items[0].name, "fixme"
|
assert_equal items[0].name, "fixme"
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
# rubocop:enable all
|
||||||
@ -1,5 +1,5 @@
|
|||||||
#!/usr/bin/ruby -w
|
#!/usr/bin/ruby -w
|
||||||
|
# rubocop:disable all
|
||||||
require File.join(File.dirname(__FILE__), 'gilded_rose')
|
require File.join(File.dirname(__FILE__), 'gilded_rose')
|
||||||
|
|
||||||
puts "OMGHAI!"
|
puts "OMGHAI!"
|
||||||
@ -31,3 +31,4 @@ gilded_rose = GildedRose.new items
|
|||||||
puts ""
|
puts ""
|
||||||
gilded_rose.update_quality
|
gilded_rose.update_quality
|
||||||
end
|
end
|
||||||
|
# rubocop:enable all
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user