basic test for ordinary item, made update_quality method into an instance method

This commit is contained in:
ollie beney 2020-11-04 14:32:23 +00:00
parent 06c28be5b1
commit fb4d5aad4d
4 changed files with 34 additions and 10 deletions

View File

@ -1,11 +1,11 @@
class GildedRose
def initialize(items)
@items = items
end
# def initialize(items)
# @items = items
# end
def update_quality()
@items.each do |item|
def self.update_quality(items)
items.map do |item|
if item.name != "Aged Brie" and item.name != "Backstage passes to a TAFKAL80ETC concert"
if item.quality > 0
if item.name != "Sulfuras, Hand of Ragnaros"
@ -50,6 +50,7 @@ class GildedRose
end
end
end
items
end
end

View File

@ -1,13 +1,33 @@
require File.join(File.dirname(__FILE__), 'gilded_rose')
require 'gilded_rose'
describe GildedRose do
let(:potato) { Item.new('potato', 15, 2)}
describe "#update_quality" do
it "does not change the name" do
items = [Item.new("foo", 0, 0)]
GildedRose.new(items).update_quality()
GildedRose.update_quality(items)
expect(items[0].name).to eq "foo"
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

View File

@ -1,3 +1,4 @@
# rubocop:disable all
require File.join(File.dirname(__FILE__), 'gilded_rose')
require 'test/unit'
@ -9,4 +10,5 @@ class TestUntitled < Test::Unit::TestCase
assert_equal items[0].name, "fixme"
end
end
end
# rubocop:enable all

View File

@ -1,5 +1,5 @@
#!/usr/bin/ruby -w
# rubocop:disable all
require File.join(File.dirname(__FILE__), 'gilded_rose')
puts "OMGHAI!"
@ -31,3 +31,4 @@ gilded_rose = GildedRose.new items
puts ""
gilded_rose.update_quality
end
# rubocop:enable all