Skip to content

Instantly share code, notes, and snippets.

@zspencer
Created January 10, 2011 23:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zspencer/773735 to your computer and use it in GitHub Desktop.
Save zspencer/773735 to your computer and use it in GitHub Desktop.
A very simple series of step definitions with duplication I want to remove...
# encoding: utf-8
begin require 'rspec/expectations'; rescue LoadError; require 'spec/expectations'; end
require 'cucumber/formatter/unicode'
Given /^a rocket exists$/ do
@rocket = Rocket.new
end
When /^the rocket is launched$/ do
@rocket.launch
end
Then /^the rocket is on the moon!$/ do
@rocket.location.should == "moon"
end
Given /^a person exists$/ do
@person = Person.new
end
When /^the person enters the rocket$/ do
@person.enter(@rocket)
end
Then /^the passenger is on the moon!$/ do
@person.location.should == "moon"
end
class EarthBasedObject
def initialize
@location = "earth"
end
def location
@location
end
end
class Rocket < EarthBasedObject
def launch
@location = "moon"
end
end
class Person < EarthBasedObject
def enter(object)
@object = object
end
def location
if(@object)
@object.location
else
super.location
end
end
end
Feature: Visit The Moon
In order to experience space travel
As a nerd
I want to visit the moon
Scenario: Launching The Rocket
Given a rocket exists
When the rocket is launched
Then the rocket is on the moon!
Scenario: Rocket has a passenger
Given a rocket exists
And a person exists
When the person enters the rocket
And the rocket is launched
Then the passenger is on the moon!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment