diff --git a/spec_helper.rb b/spec_helper.rb new file mode 100644 index 0000000..cdd59d3 --- /dev/null +++ b/spec_helper.rb @@ -0,0 +1,10 @@ +RSpec.configure do |config| + # Use color in STDOUT + config.color_enabled = true + + # Use color not only in STDOUT but also in pagers and files + config.tty = true + + # Use the specified formatter + # config.formatter = :documentation # :progress, :html, :textmate +end \ No newline at end of file diff --git a/zoo.rb b/zoo.rb index d4d906c..e0fafba 100644 --- a/zoo.rb +++ b/zoo.rb @@ -62,6 +62,7 @@ def ==(other) end class Tacos < Food; end +class Bacon < Food; end class Wildebeests < Food; end class Zeebras < Food; end class Bamboo < Food; end @@ -69,9 +70,30 @@ class Bamboo < Food; end class Zookeeper def feed(args={}) food = args.fetch(:food) - panda = args.fetch(:to) - panda.eat(food) + animal = args.fetch(:to) + animal.eat(food) end + def receive(foodBarge) + feed(foodBarge) + end + +end + +class Human + include Animal + + def acceptable_food + [Bacon.new, Tacos.new] + end +end + +class FoodBarge + def food_for(args={}) + food = args.fetch(:food) + zookeeper = args.fetch(:to) + animal = args.fetch(:animal) + zookeeper.receive(food: food, to: animal) + end end diff --git a/zoo_spec.rb b/zoo_spec.rb index 64203cc..d988821 100644 --- a/zoo_spec.rb +++ b/zoo_spec.rb @@ -1,6 +1,7 @@ # Zoo spec file require "./zoo" require "rspec" +require '../../spec_helper' class Grasshoppers < Food; end class Salad < Food; end @@ -79,4 +80,64 @@ class Salad < Food; end lion.should_receive(:eat).with(:zeebras) Zookeeper.new.feed(food: :zeebras, to: lion) end + + it "should feed the panda the bamboo when foodbarge is received" do + foodbarge = FoodBarge.new + zookeeper = Zookeeper.new + panda = Panda.new + bamboo = Bamboo.new + foodbarge.food_for(food: bamboo, to: zookeeper, animal: panda) + expect(panda.eat(bamboo)).to eq(true) + end + + it "should feed the lion the zeebras when foodbarge is received" do + foodbarge = FoodBarge.new + zookeeper = Zookeeper.new + lion = Lion.new + zeebras = Zeebras.new + foodbarge.food_for(food: zeebras, to: zookeeper, animal: lion) + expect(lion.eat(zeebras)).to eq(true) + end + + it "should not feed the lion the bamboo when foodbarge is received" do + foodbarge = FoodBarge.new + zookeeper = Zookeeper.new + lion = Lion.new + bamboo = Bamboo.new + foodbarge.food_for(food: bamboo, to: zookeeper, animal: lion) + expect(lion.eat(bamboo)).to eq(false) + end +end + +describe Human do + it "should like bacon" do + expect(Human.new.likes?(Bacon.new)).to eq(true) + end + + it "should like tacos" do + expect(Human.new.likes?(Tacos.new)).to eq(true) + end + + it "should not like bamboo" do + expect(Human.new.likes?(Bamboo.new)).to eq(false) + end +end + +describe FoodBarge do + it "should be sent to zookeeper with bamboo for a panda" do + zookeeper = Zookeeper.new + bamboo = Bamboo.new + panda = Panda.new + expect(zookeeper).to receive(:receive).with(food: bamboo, to: panda) + expect(FoodBarge.new.food_for(food: bamboo, to: zookeeper, animal: panda)) + end + + it "should be sent to zookeeper with zeebras for a lion" do + zookeeper = Zookeeper.new + zeebras = Zeebras.new + lion = Lion.new + expect(zookeeper).to receive(:receive).with(food: zeebras, to: lion) + expect(FoodBarge.new.food_for(food: zeebras, to: zookeeper, animal: lion)) + end end +