From fb4d5aad4de51c730bfc48dec54897f7bd7bbb7a Mon Sep 17 00:00:00 2001 From: ollie beney Date: Wed, 4 Nov 2020 14:32:23 +0000 Subject: [PATCH] basic test for ordinary item, made update_quality method into an instance method --- ruby/{spec => lib}/gilded_rose.rb | 11 ++++++----- ruby/spec/gilded_rose_spec.rb | 26 +++++++++++++++++++++++--- ruby/spec/gilded_rose_tests.rb | 4 +++- ruby/spec/texttest_fixture.rb | 3 ++- 4 files changed, 34 insertions(+), 10 deletions(-) rename ruby/{spec => lib}/gilded_rose.rb (92%) diff --git a/ruby/spec/gilded_rose.rb b/ruby/lib/gilded_rose.rb similarity index 92% rename from ruby/spec/gilded_rose.rb rename to ruby/lib/gilded_rose.rb index e177a497..7da84fd8 100644 --- a/ruby/spec/gilded_rose.rb +++ b/ruby/lib/gilded_rose.rb @@ -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 diff --git a/ruby/spec/gilded_rose_spec.rb b/ruby/spec/gilded_rose_spec.rb index 9033fc74..03fcab3e 100644 --- a/ruby/spec/gilded_rose_spec.rb +++ b/ruby/spec/gilded_rose_spec.rb @@ -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 diff --git a/ruby/spec/gilded_rose_tests.rb b/ruby/spec/gilded_rose_tests.rb index 2e1b70d1..0096dc1b 100644 --- a/ruby/spec/gilded_rose_tests.rb +++ b/ruby/spec/gilded_rose_tests.rb @@ -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 \ No newline at end of file +end +# rubocop:enable all \ No newline at end of file diff --git a/ruby/spec/texttest_fixture.rb b/ruby/spec/texttest_fixture.rb index ad76aacf..cb698965 100644 --- a/ruby/spec/texttest_fixture.rb +++ b/ruby/spec/texttest_fixture.rb @@ -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