From af02a32e761ed656316e1c3901886f13d2f58d6e Mon Sep 17 00:00:00 2001 From: Rupert Saxton Date: Mon, 22 Jan 2018 09:40:30 -0500 Subject: [PATCH] Add cucumber steps and feature for animal --- animal.rb | 2 +- features/animal.feature | 13 ++++++++++++- features/greeter.feature | 4 ++-- features/step_definitions/animal_steps.rb | 20 +++++++++++++++++++- features/step_definitions/greeter_steps.rb | 2 +- 5 files changed, 35 insertions(+), 6 deletions(-) diff --git a/animal.rb b/animal.rb index 8e60037..adaa9cf 100644 --- a/animal.rb +++ b/animal.rb @@ -10,6 +10,6 @@ def initialize(name, type, age) end def old? - age > 3 + @age > 3 end end diff --git a/features/animal.feature b/features/animal.feature index aa25af6..19606e6 100644 --- a/features/animal.feature +++ b/features/animal.feature @@ -1 +1,12 @@ -#Create your feature here +Feature: Animal + In order to properly track animals + An animal must have a name, type and age + And can determine if it's old + + Scenario: Bear + Given a 3 year old Bear named Charles + Then it should have the name Charles + And have the species be Bear + And be 3 years old + And is not old + diff --git a/features/greeter.feature b/features/greeter.feature index b3f6143..8e384d2 100644 --- a/features/greeter.feature +++ b/features/greeter.feature @@ -1,10 +1,10 @@ Feature: Greeter In order to properly address senior animals - As a old cat + As an old cat I want to be greeted as 'Mr Cat' Scenario: Cat - Given a animal + Given an animal When older than 3 And I verify it is a "cat" Then I should see "Mr Cat" diff --git a/features/step_definitions/animal_steps.rb b/features/step_definitions/animal_steps.rb index 324ff13..98978b9 100644 --- a/features/step_definitions/animal_steps.rb +++ b/features/step_definitions/animal_steps.rb @@ -1 +1,19 @@ -#Delete this comment, here is where you should write your step defs +Given(/^a (\d+) year old (.*?) named (.*?)$/) do |age, species, name| + @bear = Animal.new(name, species, age.to_i) +end + +Then(/^it should have the name (.*?)$/) do |name| + expect(@bear.name).to eq name +end + +And(/^have the species be (.*?)$/) do |species| + expect(@bear.type).to eq species +end + +And(/^be (\d+) years old$/) do |arg1| + expect(@bear.age).to eq arg1.to_i +end + +And(/^is not old$/) do + expect(@bear.old?).to be false +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..671d564 100644 --- a/features/step_definitions/greeter_steps.rb +++ b/features/step_definitions/greeter_steps.rb @@ -1,4 +1,4 @@ -Given(/^a animal$/) do +Given(/^an animal$/) do @animal = Animal.new('Lucy', 'cat', 4) end