Skip to content

Commit

Permalink
Fixed tests to go thru the top level function
Browse files Browse the repository at this point in the history
  • Loading branch information
jimweirich committed Feb 16, 2011
1 parent 5b41037 commit dd23f9e
Show file tree
Hide file tree
Showing 2 changed files with 155 additions and 115 deletions.
3 changes: 3 additions & 0 deletions gilded_rose.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -50,6 +51,8 @@ def update_quality_of(item)
end
end

# DO NOT CHANGE THINGS BELOW -----------------------------------------

Item = Struct.new(:name, :sell_in, :quality)

Items = [
Expand Down
267 changes: 152 additions & 115 deletions gilded_rose_spec.rb
Original file line number Diff line number Diff line change
@@ -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.