• Stars
    star
    116
  • Rank 303,894 (Top 6 %)
  • Language
    Ruby
  • Created over 14 years ago
  • Updated about 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Ruby console automation a la Expect

Greenletters README

Synopsis

See introductory blog post HERE.

require 'greenletters'

adv = Greenletters::Process.new("adventure", :transcript => $stdout)

# Install a handler which may be triggered at any time
adv.on(:output, /welcome to adventure/i) do |process, match_data|
  adv << "no\n"
end

puts "Starting adventure..."
adv.start!

# Wait for the specified pattern before proceeding
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."

Or, in Cucumber format:

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.
"""

What

Greenletters is a console interaction automation library similar to 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 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 MacOSX/Linux/*NIX-only; Windows users need not apply.

The advantage of using a PTY is that any output - including output written to the console instead of STDOUT/STDERR - will be captured by Greenletters.

Cucumber

To use the Cucumber steps in your own feature files, put the following in your env.rb:

require 'greenletters'
require 'greenletters/cucumber_steps'

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.

More Repositories

1

naught

A toolkit for building Null Object classes in Ruby
Ruby
1,049
star
2

quarto

Ruby
469
star
3

sbpprb

Smalltalk Best Practice Patterns in Ruby
Ruby
456
star
4

dotenv_elixir

A port of dotenv to Elixir
Elixir
226
star
5

ppwm

A site to promote diverse pair-programming
CSS
223
star
6

hammertime

Exception debugging console for Ruby
Ruby
208
star
7

alter-ego

Avdi's personal fork of AlterEgo
Ruby
58
star
8

.emacs24.d

A from-scratch rebuild of my Emacs configuration
Emacs Lisp
46
star
9

cowsay

Enter the cow, baby!
Ruby
41
star
10

firetower

A command-line interface to Campfire chats
Ruby
39
star
11

keyword_params

Declarative Keyword Paramaters for Ruby
Ruby
34
star
12

orgpress

A collection of Makefiles and scripts for generating formatted eBooks.
Ruby
34
star
13

nulldb

NOTE: This is no longer the official Github home of NullDB.
Ruby
32
star
14

leadlight

Rose colored stained glass windows for HTTP
Ruby
30
star
15

rpcfn-interactive-fiction

Ruby Programming Challenge for Newbies: Interactive Fiction
Ruby
28
star
16

brainguy

Ruby
27
star
17

Xcast

Ruby
26
star
18

hookr

A publish/subscribe callback hook facility for Ruby.
Ruby
19
star
19

cow

Ruby
19
star
20

org-rtm

Emacs org-mode/Remember the Milk Integration
Emacs Lisp
19
star
21

lockstep

Ruby
18
star
22

refactoring-in-ruby

My notebook as I work through the exercises in Refactoring in Ruby
15
star
23

gem-love

Show your love for your favorite gems
Ruby
13
star
24

fp_oo_elx

Elixir
13
star
25

walrus

Shell
12
star
26

fail-fast

Avdi's personal fork of FailFast
JavaScript
11
star
27

dm-google-sheet-adapter

DataMappr adapter for Google Sheet
Ruby
9
star
28

tapas-queue

A thread-safe, optionally bounded, timeout-capable queue based on RubyTapas episodes 137-143 (and a few others).
Ruby
8
star
29

gem-isntall

Ruby
7
star
30

tapas-dotfiles

Emacs Lisp
6
star
31

spartan

Butt-naked Ruby tests.
Ruby
6
star
32

handcar

Debugging utility for Rails
Ruby
5
star
33

clafamatt

CLAss FAMily ATTributes gives your classes class-inheritable attributes without all that tedious mucking about with @inheritable_attributes
Ruby
5
star
34

curator

A system for managing all of your digital artifacts
Ruby
5
star
35

mythbashers

JavaScript
4
star
36

feedupdater

Bob "sporkmonger" Aman's Feed Updater Utility
Ruby
4
star
37

gilded_rose_kata

Ruby
4
star
38

preen

Ruby
3
star
39

aws-sam

Playing around with AWS SAM
Python
3
star
40

bewarethemoose

Beware of the Moose
Shell
3
star
41

rack-stereoscope

TODO: one-line summary of your gem
Ruby
3
star
42

zero-zero

An ejection seat for Ruby apps
Ruby
3
star
43

polyglop

POLYglot Grand Language Omniscience Project
Ruby
3
star
44

hookah

Ruby
3
star
45

http_client

A replacement for net/http
Ruby
3
star
46

raffle

Ruby
3
star
47

rack_base_uri

A Rack middleware for automatically setting [X]HTML document base URIs.
Ruby
2
star
48

rudyard

Ruby Refactoring Framework
2
star
49

gem-lovefest

The server side of gem-love
Ruby
2
star
50

lmcr

The example code for Let's Make a Chatbot in Ruby
Ruby
2
star
51

favo5

Ruby
2
star
52

tick

Ruby
2
star
53

dacs

Devver Application Configuration System
Ruby
2
star
54

webscripts

1
star
55

odin

A project for learning TypeScript
TypeScript
1
star
56

rake-server

An experiment at turning Rake into a task server
Ruby
1
star
57

methodical

Automation framework for sequential operations
Ruby
1
star
58

daemon-herder

Ruby
1
star
59

flock-block

Block helper for file locking
Ruby
1
star
60

prototypes-in-ruby

Ruby
1
star
61

pulse-ffi

Ruby
1
star
62

tapas_shot_renumber

A tool for renumbering shots in RubyTapas-style scripts
Dockerfile
1
star
63

rails-synctest

Temporary
Ruby
1
star
64

articles

1
star
65

funwithgit

1
star
66

rut

Ruby
1
star