Skip to content

Instantly share code, notes, and snippets.

@jccarbonfive
Last active December 11, 2015 01:58
Show Gist options
  • Save jccarbonfive/4526691 to your computer and use it in GitHub Desktop.
Save jccarbonfive/4526691 to your computer and use it in GitHub Desktop.
Feature: Pig Latin
In order to amuse others or conceal the meaning of some text
As a user
I want to be able to translate from English to Pig Latin
Scenario: Translating English to Pig Latin
Given a file of English text
When I ask to translate it to Pig Latin
Then I should see it in Pig Latin
$ cucumber features/pig_latin.feature
Using the default profile...
UUU
1 scenario (1 undefined)
3 steps (3 undefined)
0m0.002s
You can implement step definitions for undefined steps with these snippets:
Given /^a file of English text$/ do
pending # express the regexp above with the code you wish you had
end
When /^I ask to translate it to Pig Latin$/ do
pending # express the regexp above with the code you wish you had
end
Then /^I should see it in Pig Latin$/ do
pending # express the regexp above with the code you wish you had
end
$ cucumber features/pig_latin.feature
Using the default profile...
.F-
(::) failed steps (::)
Exit status was 1 but expected it to be 0. Output:
/Users/jared/Projects/translator/lib/translator.rb:12:in `initialize': wrong number of arguments (0 for 1) (ArgumentError)
Given /^a file of English text$/ do
write_file 'english.txt', <<-EOS
The quick brown fox
jumps over the lazy dog.
EOS
end
When /^I ask to translate it to Pig Latin$/ do
run_simple 'translator english.txt'
end
Then /^I should see it in Pig Latin$/ do
assert_exact_output <<-EOS, all_stdout
Ethay ickquay ownbray oxfay
umpsjay overay ethay azylay ogday.
EOS
end
$ cucumber features/pig_latin.feature
Using the default profile...
.F-
(::) failed steps (::)
No such file or directory - translator (Aruba::LaunchError)
./features/step_definitions/pig_latin_steps.rb:9:in `/^I ask to translate it to Pig Latin$/'
features/pig_latin.feature:8:in `When I ask to translate it to Pig Latin'
Failing Scenarios:
cucumber features/pig_latin.feature:6 # Scenario: Translating English to Pig Latin
$ touch bin/translator
$ chmod +x bin/translator
$ cucumber features/pig_latin.feature
Using the default profile...
..F
(::) failed steps (::)
expected: "Ethay ickquay ownbray oxfay umpsjay overay ethay azylay ogday.\n"
got: "" (using ==)
#!/usr/bin/env ruby
$: << File.join(File.dirname(__FILE__), '..', 'lib')
require 'translator'
Translator.pig_latin ARGF, STDOUT
$ cucumber features/pig_latin.feature
Using the default profile...
.F-
(::) failed steps (::)
Exit status was 1 but expected it to be 0. Output:
/Users/jared/Projects/translator/bin/translator:6:in `<main>': undefined method `pig_latin' for Translator:Module (NoMethodError)
require 'translator/version'
module Translator
def self.pig_latin(request, response)
end
end
$ cucumber features/pig_latin.feature
Using the default profile...
..F
(::) failed steps (::)
expected: "Ethay ickquay ownbray oxfay umpsjay overay ethay azylay ogday.\n"
got: "" (using ==)
require 'translator/version'
module Translator
def self.pig_latin(request, response)
view = PigLatinView.new
view.render_on response
end
class PigLatinView
attr_reader :pig_latin
def initialize(pig_latin)
@pig_latin = pig_latin
end
def render_on(io)
pig_latin.each_line do |line|
io.puts line
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment