Permalink
Browse files

No global Items (just made testing hard).

  • Loading branch information...
1 parent dd23f9e commit 4d993c35cc62f834f3d11f02f586b9ab587a47e1 @jimweirich committed Feb 17, 2011
Showing with 47 additions and 61 deletions.
  1. +45 −47 gilded_rose.rb
  2. +2 −14 gilded_rose_spec.rb
View
@@ -1,51 +1,46 @@
-def update_quality
- Items.each do |item|
- update_quality_of(item)
- end
-end
-
-def update_quality_of(item)
-
- if item.name != 'Aged Brie' && item.name != 'Backstage passes to a TAFKAL80ETC concert'
- if item.quality > 0
- if item.name != 'Sulfuras, Hand of Ragnaros'
- item.quality -= 1
+def update_quality(items)
+ items.each do |item|
+ if item.name != 'Aged Brie' && item.name != 'Backstage passes to a TAFKAL80ETC concert'
+ if item.quality > 0
+ if item.name != 'Sulfuras, Hand of Ragnaros'
+ item.quality -= 1
+ end
end
- end
- else
- if item.quality < 50
- item.quality += 1
- if item.name == 'Backstage passes to a TAFKAL80ETC concert'
- if item.sell_in < 11
- if item.quality < 50
- item.quality += 1
+ else
+ if item.quality < 50
+ item.quality += 1
+ if item.name == 'Backstage passes to a TAFKAL80ETC concert'
+ if item.sell_in < 11
+ if item.quality < 50
+ item.quality += 1
+ end
end
- end
- if item.sell_in < 6
- if item.quality < 50
- item.quality += 1
+ if item.sell_in < 6
+ if item.quality < 50
+ item.quality += 1
+ end
end
end
end
end
- end
- if item.name != 'Sulfuras, Hand of Ragnaros'
- item.sell_in -= 1
- end
- if item.sell_in < 0
- if item.name != "Aged Brie"
- if item.name != 'Backstage passes to a TAFKAL80ETC concert'
- if item.quality > 0
- if item.name != 'Sulfuras, Hand of Ragnaros'
- item.quality -= 1
+ if item.name != 'Sulfuras, Hand of Ragnaros'
+ item.sell_in -= 1
+ end
+ if item.sell_in < 0
+ if item.name != "Aged Brie"
+ if item.name != 'Backstage passes to a TAFKAL80ETC concert'
+ if item.quality > 0
+ if item.name != 'Sulfuras, Hand of Ragnaros'
+ item.quality -= 1
+ end
end
+ else
+ item.quality = item.quality - item.quality
end
else
- item.quality = item.quality - item.quality
- end
- else
- if item.quality < 50
- item.quality += 1
+ if item.quality < 50
+ item.quality += 1
+ end
end
end
end
@@ -55,11 +50,14 @@ def update_quality_of(item)
Item = Struct.new(:name, :sell_in, :quality)
-Items = [
- Item.new("+5 Dexterity Vest", 10, 20),
- Item.new("Aged Brie", 2, 0),
- Item.new("Elixir of the Mongoose", 5, 7),
- Item.new("Sulfuras, Hand of Ragnaros", 0, 80),
- Item.new("Backstage passes to a TAFKAL80ETC concert", 15, 20),
- Item.new("Conjured Mana Cake", 3, 6),
-]
+# We use the setup in the spec rather than the following for testing.
+#
+# Items = [
+# Item.new("+5 Dexterity Vest", 10, 20),
+# Item.new("Aged Brie", 2, 0),
+# Item.new("Elixir of the Mongoose", 5, 7),
+# Item.new("Sulfuras, Hand of Ragnaros", 0, 80),
+# Item.new("Backstage passes to a TAFKAL80ETC concert", 15, 20),
+# Item.new("Conjured Mana Cake", 3, 6),
+# ]
+
View
@@ -3,24 +3,12 @@
describe "#update_quality" do
- # Horrible hack because +update_quality+ has a bad interface for
- # testing.
- def update_items(items)
- old_items = Items.dup
- Items.clear
- items.each do |i| Items << i end
- update_quality
- ensure
- Items.clear
- old_items.each do |i| Items << i end
- end
-
context "with a single" do
Given(:sell_in) { 5 }
Given(:quality) { 10 }
Given(:item) { Item.new(name, sell_in, quality) }
- When { update_items([item]) }
+ When { update_quality([item]) }
context "normal item" do
Given(:name) { "NORMAL ITEM" }
@@ -188,7 +176,7 @@ def update_items(items)
]
}
- When { update_items(items) }
+ When { update_quality(items) }
Then { items[0].quality.should == 9 }
Then { items[0].sell_in.should == 4 }

0 comments on commit 4d993c3

Please sign in to comment.