diff --git a/zoo.rb b/zoo.rb index 8f5eea5..381009f 100644 --- a/zoo.rb +++ b/zoo.rb @@ -13,7 +13,7 @@ def eat(food) end def likes?(food) - acceptable_food.include?(food.to_sym) + acceptable_food.include?(food.name) end def acceptable_food @@ -24,14 +24,36 @@ def full? false end + def feed(foods) + foods.each do |food| + eat(food) + end + end end +class Food + + attr_accessor :name + + def initialize(name) + @name = name + end +end + +class FoodBarge + + @foodbarge = FoodBarge.new + + def food_for(animal) + animal.acceptable_food + end +end class Panda include Animal def acceptable_food - [:bamboo] + [Food.new("bamboo").name] end def full? @@ -44,7 +66,7 @@ class Lion include Animal def acceptable_food - [:wildebeests, :zeebras] + [Food.new("wildebeests").name, Food.new("zebras").name] end def full? @@ -58,6 +80,13 @@ def feed(args={}) panda = args.fetch(:to) panda.eat(food) end +end +class Human + include Animal + + def acceptable_food + [Food.new("bacon").name, Food.new("tacos").name] + end end diff --git a/zoo_spec.rb b/zoo_spec.rb index 4943c90..9fff70e 100644 --- a/zoo_spec.rb +++ b/zoo_spec.rb @@ -5,58 +5,60 @@ describe Panda do it "should like bamboo" do - Panda.new.likes?(:bamboo).should eq(true) - end - - it "should like bamboo as a string" do - Panda.new.likes?("bamboo").should eq(true) + Panda.new.likes?(Food.new("bamboo")).should eq(true) end it "should not like grasshoppers" do - Panda.new.likes?(:grasshoppers).should eq(false) + Panda.new.likes?(Food.new("grasshoppers")).should eq(false) end it "should be able to eat the food" do - Panda.new.eat(:bamboo).should be_true + Panda.new.eat(Food.new("bamboo")).should be_true end it "should be full after eating 30 bamboo" do panda = Panda.new 31.times do - panda.eat(:bamboo) + panda.eat(Food.new("bamboo")) end panda.should be_full end it "should not be full after 1" do panda = Panda.new - panda.eat(:bamboo) + panda.eat(Food.new("bamboo")) panda.should_not be_full end + + it "should be able to get fed" do + panda = Panda.new + panda.should respond_to(:feed) + panda.feed([Food.new("bamboo")]) + end end describe Lion do it "should like wildebeests" do - Lion.new.likes?(:wildebeests).should eq(true) + Lion.new.likes?(Food.new("wildebeests")).should eq(true) end it "should like zeebras" do - Lion.new.likes?(:zeebras).should eq(true) + Lion.new.likes?(Food.new("zebras")).should eq(true) end it "should not like salad" do - Lion.new.likes?(:salad).should eq(false) + Lion.new.likes?(Food.new("salad")).should eq(false) end it "should take 11 meals to be full" do lion = Lion.new - lion.eat(:zeebras) + lion.eat(Food.new("zeebras")) lion.should_not be_full end it "should take 11 meals to be full" do lion = Lion.new 11.times do - lion.eat(:zeebras) + lion.eat(Food.new("zebras")) end lion.should be_full end @@ -65,13 +67,48 @@ describe Zookeeper do it "should be able to feed bamboo to the pandas" do panda = Panda.new - panda.should_receive(:eat).with(:bamboo) - Zookeeper.new.feed(food: :bamboo, to: panda) + panda.should_receive(:eat).with("bamboo") + Zookeeper.new.feed(food: "bamboo", to: panda) end it "should be able to feed zeebras to the lions" do lion = Lion.new - lion.should_receive(:eat).with(:zeebras) - Zookeeper.new.feed(food: :zeebras, to: lion) + lion.should_receive(:eat).with("zeebras") + Zookeeper.new.feed(food: "zeebras", to: lion) end end + +describe Human do + + it "should like bacon" do + Human.new.likes?(Food.new("bacon")).should be_true + end + + it "should like tacos" do + Human.new.likes?(Food.new("tacos")).should be_true + end + + it "should not like bamboo" do + Human.new.likes?(Food.new("bamboo")).should_not be_true + end + + it "should be able to eat" do + Human.new.eat(Food.new("bacon")).should be_true + end +end + +describe FoodBarge do + + it "should be able to check what foods are acceptable to the animal" do + foodbarge = FoodBarge.new + panda = Panda.new + foodbarge.should_receive(:food_for).with(panda) + foodbarge.food_for(panda) + end + + it "should have bacon and tacos ready for the human to eat" do + animal = Human.new + barge = FoodBarge.new + barge.food_for(animal).should eq([Food.new("bacon").name, Food.new("tacos").name]) + end +end