From c845f7f72fae1e69ba2431fc6e315f5f70165abb Mon Sep 17 00:00:00 2001 From: David Matas Date: Sun, 29 Apr 2012 19:07:36 +0200 Subject: [PATCH 1/6] Exercise 1 completed --- zoo.rb | 8 ++++++++ zoo_spec.rb | 19 +++++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/zoo.rb b/zoo.rb index 8f5eea5..d1045ba 100644 --- a/zoo.rb +++ b/zoo.rb @@ -52,6 +52,14 @@ def full? end end +class Human + include Animal + + def acceptable_food + [:bacon, :tacos] + end +end + class Zookeeper def feed(args={}) food = args.fetch(:food) diff --git a/zoo_spec.rb b/zoo_spec.rb index 4943c90..d67aa53 100644 --- a/zoo_spec.rb +++ b/zoo_spec.rb @@ -23,14 +23,14 @@ it "should be full after eating 30 bamboo" do panda = Panda.new 31.times do - panda.eat(:bamboo) + panda.eat(:bamboo) end panda.should be_full end it "should not be full after 1" do panda = Panda.new - panda.eat(:bamboo) + panda.eat(:bamboo) panda.should_not be_full end end @@ -75,3 +75,18 @@ Zookeeper.new.feed(food: :zeebras, to: lion) end end + +describe Human do + it "should like bacon" do + Human.new.likes?(:bacon).should be_true + end + + it "should like tacos" do + Human.new.likes?(:tacos).should be_true + end + + it "should like bamboo" do + Human.new.likes?(:bamboo).should_not be_true + end +end + From 526f1eb6facd5d10f5997a5150a81e65d9be5f72 Mon Sep 17 00:00:00 2001 From: David Matas Date: Sun, 29 Apr 2012 19:10:07 +0200 Subject: [PATCH 2/6] Created Food class --- zoo.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/zoo.rb b/zoo.rb index d1045ba..77773f3 100644 --- a/zoo.rb +++ b/zoo.rb @@ -31,7 +31,7 @@ class Panda include Animal def acceptable_food - [:bamboo] + [Food.new(:bamboo).name] end def full? @@ -69,3 +69,10 @@ def feed(args={}) end +class Food + attr_reader :name + + def initialize(name) + @name = name + end +end \ No newline at end of file From b3df5f1c84d773b35aa8a551b47742301a903832 Mon Sep 17 00:00:00 2001 From: David Matas Date: Sun, 29 Apr 2012 19:10:36 +0200 Subject: [PATCH 3/6] Changed variables name in feed method --- zoo.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/zoo.rb b/zoo.rb index 77773f3..25e12da 100644 --- a/zoo.rb +++ b/zoo.rb @@ -63,8 +63,8 @@ def acceptable_food class Zookeeper def feed(args={}) food = args.fetch(:food) - panda = args.fetch(:to) - panda.eat(food) + animal = args.fetch(:to) + animal.eat(food) end end From 7ac79b3a98f177724869e1ed3c1083d5203edeb3 Mon Sep 17 00:00:00 2001 From: David Matas Date: Sun, 29 Apr 2012 20:28:40 +0200 Subject: [PATCH 4/6] Updated Food class --- zoo.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/zoo.rb b/zoo.rb index 25e12da..3f02052 100644 --- a/zoo.rb +++ b/zoo.rb @@ -44,7 +44,7 @@ class Lion include Animal def acceptable_food - [:wildebeests, :zeebras] + [Food.new(:wildebeests).name, Food.new(:zeebras).name] end def full? @@ -56,7 +56,7 @@ class Human include Animal def acceptable_food - [:bacon, :tacos] + [Food.new(:bacon).name, Food.new(:tacos).name] end end From c9aec8cad3c719e57ebe7eb6d4403e7b63754fe8 Mon Sep 17 00:00:00 2001 From: David Matas Date: Fri, 15 Jun 2012 10:39:40 +0200 Subject: [PATCH 5/6] Updated from Rubyoffrails --- zoo_spec.rb | 92 ----------------------------------------------------- 1 file changed, 92 deletions(-) delete mode 100644 zoo_spec.rb diff --git a/zoo_spec.rb b/zoo_spec.rb deleted file mode 100644 index d67aa53..0000000 --- a/zoo_spec.rb +++ /dev/null @@ -1,92 +0,0 @@ -# Zoo spec file -require "./zoo" -require "rspec" - -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) - end - - it "should not like grasshoppers" do - Panda.new.likes?(:grasshoppers).should eq(false) - end - - it "should be able to eat the food" do - Panda.new.eat(:bamboo).should be_true - end - - it "should be full after eating 30 bamboo" do - panda = Panda.new - 31.times do - panda.eat(:bamboo) - end - panda.should be_full - end - - it "should not be full after 1" do - panda = Panda.new - panda.eat(:bamboo) - panda.should_not be_full - end -end - -describe Lion do - it "should like wildebeests" do - Lion.new.likes?(:wildebeests).should eq(true) - end - - it "should like zeebras" do - Lion.new.likes?(:zeebras).should eq(true) - end - - it "should not like salad" do - Lion.new.likes?(:salad).should eq(false) - end - - it "should take 11 meals to be full" do - lion = Lion.new - lion.eat(: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) - end - lion.should be_full - end -end - -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) - 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) - end -end - -describe Human do - it "should like bacon" do - Human.new.likes?(:bacon).should be_true - end - - it "should like tacos" do - Human.new.likes?(:tacos).should be_true - end - - it "should like bamboo" do - Human.new.likes?(:bamboo).should_not be_true - end -end - From e5385252fc10711947b5f8547225e153398f2766 Mon Sep 17 00:00:00 2001 From: David Matas Date: Fri, 15 Jun 2012 10:40:40 +0200 Subject: [PATCH 6/6] Updated from RubyoffRails - missing part in previous commit --- spec/zoo_spec.rb | 92 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 spec/zoo_spec.rb diff --git a/spec/zoo_spec.rb b/spec/zoo_spec.rb new file mode 100644 index 0000000..51397f9 --- /dev/null +++ b/spec/zoo_spec.rb @@ -0,0 +1,92 @@ +# Zoo spec file +require_relative "../zoo" +require "rspec" + +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) + end + + it "should not like grasshoppers" do + Panda.new.likes?(:grasshoppers).should eq(false) + end + + it "should be able to eat the food" do + Panda.new.eat(:bamboo).should be_true + end + + it "should be full after eating 30 bamboo" do + panda = Panda.new + 31.times do + panda.eat(:bamboo) + end + panda.should be_full + end + + it "should not be full after 1" do + panda = Panda.new + panda.eat(:bamboo) + panda.should_not be_full + end +end + +describe Lion do + it "should like wildebeests" do + Lion.new.likes?(:wildebeests).should eq(true) + end + + it "should like zeebras" do + Lion.new.likes?(:zeebras).should eq(true) + end + + it "should not like salad" do + Lion.new.likes?(:salad).should eq(false) + end + + it "should take 11 meals to be full" do + lion = Lion.new + lion.eat(: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) + end + lion.should be_full + end +end + +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) + 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) + end +end + +describe Human do + it "should like bacon" do + Human.new.likes?(:bacon).should be_true + end + + it "should like tacos" do + Human.new.likes?(:tacos).should be_true + end + + it "should like bamboo" do + Human.new.likes?(:bamboo).should_not be_true + end +end +