diff --git a/animal.rb b/animal.rb index 8e60037..78d0f6f 100644 --- a/animal.rb +++ b/animal.rb @@ -9,7 +9,16 @@ def initialize(name, type, age) @age = age end - def old? - age > 3 + def feed + case type + when "cat" + "Here is some fresh salmon." + when "dog" + "Here is some prime rib." + when "bird" + "Here are some tasty seeds." + else + "We do not know how to feed you. Please alert the front desk." + end end end diff --git a/features/animal.feature b/features/animal.feature index aa25af6..15103c6 100644 --- a/features/animal.feature +++ b/features/animal.feature @@ -1 +1,9 @@ -#Create your feature here +Feature: Room Service + In order to properly nourish our animals + As a cat + I want to be fed fish + + Scenario: Cat + Given an animal + When I verify she is a "cat" + Then I should give her salmon diff --git a/features/step_definitions/animal_steps.rb b/features/step_definitions/animal_steps.rb index 324ff13..e7b002f 100644 --- a/features/step_definitions/animal_steps.rb +++ b/features/step_definitions/animal_steps.rb @@ -1 +1,11 @@ -#Delete this comment, here is where you should write your step defs +Given(/^an animal$/) do + @animal = Animal.new('Lucy', 'cat', 4) +end + +When(/^I verify she is a "(.*?)"$/) do |type| + expect(@animal.type).to eq type +end + +Then(/^I should give her (.*?)$/) do |title| + expect(@animal.feed).to include title +end \ No newline at end of file diff --git a/features/step_definitions/greeter_steps.rb b/features/step_definitions/greeter_steps.rb index 0009f62..688ae7c 100644 --- a/features/step_definitions/greeter_steps.rb +++ b/features/step_definitions/greeter_steps.rb @@ -3,15 +3,14 @@ end When(/^older than (\d+)$/) do |arg1| - expect(@animal.old?).to be true + expect(@animal.age).to be > 3 end When(/^I verify it is a "(.*?)"$/) do |type| - greeter = Greeter.new(@animal) - expect(greeter.animal.type).to eq type + @greeter = Greeter.new(@animal) + expect(@greeter.send(type + '?')).to be true end Then(/^I should see "(.*?)"$/) do |title| - greeter = Greeter.new(@animal) - expect(greeter.greet).to eq title + expect(@greeter.greet).to eq title end diff --git a/greeter.rb b/greeter.rb index 44dbffc..36a0832 100644 --- a/greeter.rb +++ b/greeter.rb @@ -14,7 +14,7 @@ def cat? end def greet - if cat? + if cat? && animal.age > 3 "Mr Cat" else "We don't know how to greet #{animal.name}"