Skip to content

Commit

Permalink
Preserve Whole Object.
Browse files Browse the repository at this point in the history
  • Loading branch information
josemotanet committed Jun 4, 2013
1 parent 1f5d277 commit f07639d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
29 changes: 29 additions & 0 deletions preserve-whole-object/lib/after.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
class Item
attr_reader :name, :price, :date

def initialize name, price, date
@name = name
@price = price
@date = date
end
end

class Store
def initialize
@items = []
end

def contain? item
! find(item).nil?
end

def <<(item)
@items << item
end

def find item
@items.find { |i| i.name == item.name &&
i.price == item.price &&
i.date == item.date }
end
end
12 changes: 9 additions & 3 deletions preserve-whole-object/test/test.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require 'minitest/spec'
require 'minitest/autorun'
require 'minitest/spec'

require 'before' if ENV["BEFORE"]
require 'after' unless ENV["BEFORE"]
Expand All @@ -9,7 +9,13 @@

subject { Store.new.tap { |store| store << item } }

it "finds an item in the store" do
subject.contain?(item_name,price,date).must_equal true
if ENV["BEFORE"]
it "finds an item in the store" do
subject.contain?(item.name,item.price,item.date).must_equal true
end
else
it "finds an item in the store" do
subject.contain?(item).must_equal true
end
end
end

0 comments on commit f07639d

Please sign in to comment.