Permalink
Browse files

Fixed tests to go thru the top level function

  • Loading branch information...
1 parent 5b41037 commit dd23f9e9e1b7362bd1de4c40ac673f296bfd49a5 @jimweirich committed Feb 16, 2011
Showing with 155 additions and 115 deletions.
  1. +3 −0 gilded_rose.rb
  2. +152 −115 gilded_rose_spec.rb
View
@@ -5,6 +5,7 @@ def update_quality
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'
@@ -50,6 +51,8 @@ def update_quality_of(item)
end
end
+# DO NOT CHANGE THINGS BELOW -----------------------------------------
+
Item = Struct.new(:name, :sell_in, :quality)
Items = [
View
@@ -1,162 +1,199 @@
require 'rspec/given'
require 'gilded_rose'
-describe "#update_quality_of" do
- Given(:sell_in) { 5 }
- Given(:quality) { 10 }
- Given(:item) { Item.new(name, sell_in, quality) }
+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
- When { update_quality_of(item) }
+ context "with a single" do
+ Given(:sell_in) { 5 }
+ Given(:quality) { 10 }
+ Given(:item) { Item.new(name, sell_in, quality) }
- context "with a normal item" do
- Given(:name) { "NORMAL ITEM" }
+ When { update_items([item]) }
- context "before sell date" do
- Then { item.quality.should == quality - 1 }
- Then { item.sell_in.should == sell_in - 1 }
- end
+ context "normal item" do
+ Given(:name) { "NORMAL ITEM" }
- context "on sell date" do
- Given(:sell_in) { 0 }
- Then { item.quality.should == quality - 2 }
- Then { item.sell_in.should == sell_in - 1 }
- end
+ context "before sell date" do
+ Then { item.quality.should == quality-1 }
+ Then { item.sell_in.should == sell_in-1 }
+ end
- context "after sell date" do
- Given(:sell_in) { -10 }
- Then { item.quality.should == quality - 2 }
- Then { item.sell_in.should == sell_in - 1 }
- end
+ context "on sell date" do
+ Given(:sell_in) { 0 }
+ Then { item.quality.should == quality-2 }
+ Then { item.sell_in.should == sell_in-1 }
+ end
- context "of zero quality" do
- Given(:quality) { 0 }
- Then { item.quality.should == 0 }
+ context "after sell date" do
+ Given(:sell_in) { -10 }
+ Then { item.quality.should == quality-2 }
+ Then { item.sell_in.should == sell_in-1 }
+ end
+
+ context "of zero quality" do
+ Given(:quality) { 0 }
+ Then { item.quality.should == 0 }
+ end
end
- end
- context "with Aged Brie" do
- Given(:name) { "Aged Brie" }
+ context "Aged Brie" do
+ Given(:name) { "Aged Brie" }
- context "before sell date" do
- Then { item.quality.should == quality+1 }
+ context "before sell date" do
+ Then { item.quality.should == quality+1 }
+ Then { item.sell_in.should == sell_in-1 }
- context "with max quality" do
- Given(:quality) { 50 }
- Then { item.quality.should == quality }
+ context "with max quality" do
+ Given(:quality) { 50 }
+ Then { item.quality.should == quality }
+ Then { item.sell_in.should == sell_in-1 }
+ end
end
- end
- context "on sell date" do
- Given(:sell_in) { 0 }
- Then { item.quality.should == quality+2 }
- end
+ context "on sell date" do
+ Given(:sell_in) { 0 }
+ Then { item.quality.should == quality+2 }
+ Then { item.sell_in.should == sell_in-1 }
+ end
- context "after sell date" do
- Given(:sell_in) { -10 }
- Then { item.quality.should == quality+2 }
+ context "after sell date" do
+ Given(:sell_in) { -10 }
+ Then { item.quality.should == quality+2 }
+ Then { item.sell_in.should == sell_in-1 }
- context "with max quality" do
- Given(:quality) { 50 }
- Then { item.quality.should == quality }
+ context "with max quality" do
+ Given(:quality) { 50 }
+ Then { item.quality.should == quality }
+ Then { item.sell_in.should == sell_in-1 }
+ end
end
end
- end
- context "with Sulfuras" do
- Given(:quality) { 80 }
- Given(:name) { "Sulfuras, Hand of Ragnaros" }
+ context "Sulfuras" do
+ Given(:quality) { 80 }
+ Given(:name) { "Sulfuras, Hand of Ragnaros" }
- context "before sell date" do
- Then { item.quality.should == quality }
- Then { item.sell_in.should == sell_in }
- end
+ context "before sell date" do
+ Then { item.quality.should == quality }
+ Then { item.sell_in.should == sell_in }
+ end
- context "on sell date" do
- Given(:sell_in) { 0 }
- Then { item.quality.should == quality }
- Then { item.sell_in.should == sell_in }
- end
+ context "on sell date" do
+ Given(:sell_in) { 0 }
+ Then { item.quality.should == quality }
+ Then { item.sell_in.should == sell_in }
+ end
- context "after sell date" do
- Given(:sell_in) { -10 }
- Then { item.quality.should == quality }
- Then { item.sell_in.should == sell_in }
+ context "after sell date" do
+ Given(:sell_in) { -10 }
+ Then { item.quality.should == quality }
+ Then { item.sell_in.should == sell_in }
+ end
end
- end
- context "with Backstage passes" do
- Given(:name) { "Backstage passes to a TAFKAL80ETC concert" }
+ context "Backstage pass" do
+ Given(:name) { "Backstage passes to a TAFKAL80ETC concert" }
- context "long before sell date" do
- Given(:sell_in) { 11 }
- Then { item.quality.should == quality+1 }
- Then { item.sell_in.should == sell_in-1 }
+ context "long before sell date" do
+ Given(:sell_in) { 11 }
+ Then { item.quality.should == quality+1 }
+ Then { item.sell_in.should == sell_in-1 }
- context "at max quality" do
- Given(:quality) { 50 }
- Then { item.quality.should == quality }
+ context "at max quality" do
+ Given(:quality) { 50 }
+ Then { item.quality.should == quality }
+ end
end
- end
- context "closer to sell date" do
- Given(:sell_in) { 10 }
- Then { item.quality.should == quality+2 }
- Then { item.sell_in.should == sell_in-1 }
+ context "closer to sell date" do
+ Given(:sell_in) { 10 }
+ Then { item.quality.should == quality+2 }
+ Then { item.sell_in.should == sell_in-1 }
- context "at max quality" do
- Given(:quality) { 50 }
- Then { item.quality.should == quality }
+ context "at max quality" do
+ Given(:quality) { 50 }
+ Then { item.quality.should == quality }
+ end
end
- end
- context "on sell date" do
- Given(:sell_in) { 0 }
- Then { item.quality.should == 0 }
- Then { item.sell_in.should == sell_in-1 }
- end
+ context "on sell date" do
+ Given(:sell_in) { 0 }
+ Then { item.quality.should == 0 }
+ Then { item.sell_in.should == sell_in-1 }
+ end
- context "after sell date" do
- Given(:sell_in) { -10 }
- Then { item.quality.should == 0 }
- Then { item.sell_in.should == sell_in-1 }
+ context "after sell date" do
+ Given(:sell_in) { -10 }
+ Then { item.quality.should == 0 }
+ Then { item.sell_in.should == sell_in-1 }
+ end
end
- end
- context "with conjured items" do
- before { pending }
- Given(:name) { "Conjured Mana Cake" }
+ context "conjured item" do
+ before { pending }
+ Given(:name) { "Conjured Mana Cake" }
- context "before the sell date" do
- Given(:sell_in) { 5 }
- Then { item.quality.should == quality-2 }
- Then { item.sell_in.should == sell_in-1 }
+ context "before the sell date" do
+ Given(:sell_in) { 5 }
+ Then { item.quality.should == quality-2 }
+ Then { item.sell_in.should == sell_in-1 }
- context "at zero quality" do
- Given(:quality) { 0 }
- Then { item.quality.should == quality }
+ context "at zero quality" do
+ Given(:quality) { 0 }
+ Then { item.quality.should == quality }
+ end
end
- end
- context "on sell date" do
- Given(:sell_in) { 0 }
- Then { item.quality.should == quality-2 }
- Then { item.sell_in.should == sell_in-1 }
+ context "on sell date" do
+ Given(:sell_in) { 0 }
+ Then { item.quality.should == quality-2 }
+ Then { item.sell_in.should == sell_in-1 }
- context "at zero quality" do
- Given(:quality) { 0 }
- Then { item.quality.should == quality }
+ context "at zero quality" do
+ Given(:quality) { 0 }
+ Then { item.quality.should == quality }
+ end
end
- end
- context "after sell date" do
- Given(:sell_in) { -10 }
- Then { item.quality.should == quality-2 }
- Then { item.sell_in.should == sell_in-1 }
+ context "after sell date" do
+ Given(:sell_in) { -10 }
+ Then { item.quality.should == quality-2 }
+ Then { item.sell_in.should == sell_in-1 }
- context "at zero quality" do
- Given(:quality) { 0 }
- Then { item.quality.should == quality }
+ context "at zero quality" do
+ Given(:quality) { 0 }
+ Then { item.quality.should == quality }
+ end
end
end
end
+
+ context "with several objects" do
+ Given(:items) {
+ [
+ Item.new("NORMAL ITEM", 5, 10),
+ Item.new("Aged Brie", 3, 10),
+ ]
+ }
+
+ When { update_items(items) }
+
+ Then { items[0].quality.should == 9 }
+ Then { items[0].sell_in.should == 4 }
+
+ Then { items[1].quality.should == 11 }
+ Then { items[1].sell_in.should == 2 }
+ end
end

0 comments on commit dd23f9e

Please sign in to comment.