Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

panda and tiger level #18

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions spec_helper.rb
Original file line number Diff line number Diff line change
@@ -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
26 changes: 24 additions & 2 deletions zoo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,38 @@ def ==(other)
end

class Tacos < Food; end
class Bacon < Food; end
class Wildebeests < Food; end
class Zeebras < Food; end
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

61 changes: 61 additions & 0 deletions zoo_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Zoo spec file
require "./zoo"
require "rspec"
require '../../spec_helper'

class Grasshoppers < Food; end
class Salad < Food; end
Expand Down Expand Up @@ -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