Created
January 10, 2011 23:53
-
-
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...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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