Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Added more examples; added Cucumber steps.
- Loading branch information
Avdi Grimm
committed
Jul 19, 2010
1 parent
d0eaa97
commit 23bf9dd
Showing
12 changed files
with
765 additions
and
56 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,3 +16,4 @@ announcement.txt | |
coverage | ||
doc | ||
pkg | ||
/examples/cucumber/greenletters.log |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
== 1.0.0 / 2010-07-03 | ||
== 0.0.1 / 2010-07-19 | ||
|
||
* 1 major enhancement | ||
* Birthday! |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
#+Title: Greenletters README | ||
#+AUTHOR: Avdi Grimm | ||
#+EMAIL: avdi@avdi.org | ||
|
||
# Configuration: | ||
#+STARTUP: odd | ||
#+STARTUP: hi | ||
#+STARTUP: hidestars | ||
|
||
|
||
* Synopsis | ||
|
||
#+begin_src ruby | ||
require 'greenletters' | ||
adv = Greenletters::Process.new("adventure", :transcript => $stdout) | ||
adv.on(:output, /welcome to adventure/i) do |process, match_data| | ||
adv << "no\n" | ||
end | ||
|
||
puts "Starting adventure..." | ||
adv.start! | ||
adv.wait_for(:output, /you are standing at the end of a road/i) | ||
adv << "east\n" | ||
adv.wait_for(:output, /inside a building/i) | ||
adv << "quit\n" | ||
adv.wait_for(:output, /really want to quit/i) | ||
adv << "yes\n" | ||
adv.wait_for(:exit) | ||
puts "Adventure has exited." | ||
#+end_src | ||
|
||
* What | ||
|
||
Greenletters is a console interaction automation library similar to [[http://directory.fsf.org/project/expect/][GNU | ||
Expect]]. You can use it to script interactions with command-line programs. | ||
|
||
* Why | ||
Because Ruby's built-in expect.rb is pretty underpowered and I wanted to drive | ||
command-line applications from Ruby, not TCL. | ||
|
||
* Who | ||
Greenletters is by [[mailto:avdi@avdi.org][Avdi Grimm]]. | ||
|
||
* Where | ||
http://github.com/avdi/greenletters | ||
|
||
* How | ||
Greenletters uses the pty.rb library under the covers to create a UNIX | ||
pseudoterminal under Ruby's control. Of course, this means that it is | ||
*NIX-only; Windows users need not apply. | ||
|
||
The advantage of using a PTY is that *any* output - inclding output written to | ||
the console instead of STDOUT/STDERR - will be captured by Greenletters. | ||
|
||
* LICENSE | ||
|
||
(The MIT License) | ||
|
||
Copyright (c) 2010 Avdi Grimm | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
'Software'), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | ||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | ||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file was deleted.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# This demo interacts with the classic Collossal Cave Adventure game. To install | ||
# the game on Debian-based systems (Ubuntu, etc), execute: | ||
# | ||
# sudo apt-get install bsdgames | ||
# | ||
$:.unshift(File.expand_path('../lib', File.dirname(__FILE__))) | ||
require 'greenletters' | ||
require 'logger' | ||
|
||
logger = ::Logger.new($stdout) | ||
logger.level = ::Logger::INFO | ||
# logger.level = ::Logger::DEBUG | ||
adv = Greenletters::Process.new("adventure", | ||
:logger => logger, | ||
:transcript => $stdout) | ||
adv.on(:output, /welcome to adventure/i) do |process, match_data| | ||
adv << "no\n" | ||
end | ||
|
||
puts "Starting aadventure..." | ||
adv.start! | ||
adv.wait_for(:output, /you are standing at the end of a road/i) | ||
adv << "east\n" | ||
adv.wait_for(:output, /inside a building/i) | ||
adv << "quit\n" | ||
adv.wait_for(:output, /really want to quit/i) | ||
adv << "yes\n" | ||
adv.wait_for(:exit) | ||
puts "Adventure has exited." | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
Feature: play adventure | ||
As a nerd | ||
I want to play a text adventure game | ||
Because I'm old-skool | ||
|
||
Scenario: play first few rooms (named process) | ||
Given process activity is logged to "greenletters.log" | ||
Given a process "adventure" from command "adventure" | ||
Given I reply "no" to output "Would you like instructions?" from process "adventure" | ||
Given I reply "yes" to output "Do you really want to quit" from process "adventure" | ||
When I execute the process "adventure" | ||
Then I should see the following output from process "adventure": | ||
""" | ||
You are standing at the end of a road before a small brick building. | ||
Around you is a forest. A small stream flows out of the building and | ||
down a gully. | ||
""" | ||
When I enter "east" into process "adventure" | ||
Then I should see the following output from process "adventure": | ||
""" | ||
You are inside a building, a well house for a large spring. | ||
""" | ||
When I enter "west" into process "adventure" | ||
Then I should see the following output from process "adventure": | ||
""" | ||
You're at end of road again. | ||
""" | ||
When I enter "south" into process "adventure" | ||
Then I should see the following output from process "adventure": | ||
""" | ||
You are in a valley in the forest beside a stream tumbling along a | ||
rocky bed. | ||
""" | ||
When I enter "quit" into process "adventure" | ||
Then the process "adventure" should exit succesfully | ||
|
||
Scenario: play first few rooms (default process) | ||
Given process activity is logged to "greenletters.log" | ||
Given a process from command "adventure" | ||
Given I reply "no" to output "Would you like instructions?" | ||
Given I reply "yes" to output "Do you really want to quit" | ||
When I execute the process | ||
Then I should see the following output: | ||
""" | ||
You are standing at the end of a road before a small brick building. | ||
Around you is a forest. A small stream flows out of the building and | ||
down a gully. | ||
""" | ||
When I enter "east" | ||
Then I should see the following output: | ||
""" | ||
You are inside a building, a well house for a large spring. | ||
""" | ||
When I enter "west" | ||
Then I should see the following output: | ||
""" | ||
You're at end of road again. | ||
""" | ||
When I enter "south" | ||
Then I should see the following output: | ||
""" | ||
You are in a valley in the forest beside a stream tumbling along a | ||
rocky bed. | ||
""" | ||
When I enter "quit" | ||
Then the process should exit succesfully | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
$:.unshift(File.expand_path('../../../lib', File.dirname(__FILE__))) | ||
require 'greenletters' | ||
require 'greenletters/cucumber_steps' | ||
|
Oops, something went wrong.