• Stars
    star
    275
  • Rank 149,796 (Top 3 %)
  • Language
    CoffeeScript
  • Created about 13 years ago
  • Updated over 12 years ago

Reviews

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

Repository Details

Integration testing ftw

Ghostbuster

Automated browser testing via phantom.js, with all of the pain taken out! That means you get a real browser, with a real DOM, and can do real testing!

Installation

To install first gem install ghostbuster. Once you've done that, you can run setup-ghostbuster. Right now this only works on Mac, so, otherwise, ghostbuster will look for a copy of the phantomjs binary in ~/.ghostbuster.

Usage

Standalone

Once installed, you can simply use ghostbuster [path/to/Ghostfile] to run your tests.

Rake

As well, you can install Ghostbuster to run as a rake task. To do this, add this to your Rakefile:

require 'ghostbuster/install_rake'

Configuration via Ghostfile

Your Ghostfile handles your configuration. To set the pattern use:

ghost.pattern = "test_*.{js,coffee}" # this is the default

To enable (or disable) screenshots use:

ghost.take_screenshots! # or #do_not_take_screenshots! defaults to take_screenshots!

To set the directory your screenshots will save to use:

ghost.screenshot_dir = '.'

To set the dimensions for the screenshots use:

ghost.screenshot_dimensions 800, 2000 # width, height

To set the command for starting your server use:

ghost.start_command "./start.sh"

To set the timeout in seconds for the start_command to complete use:

ghost.start_wait = 2   # this is the default

To set the command for stopping your server use:

ghost.stop_command "./stop.sh"

To set the location of your phantomjs binary, use:

ghost.phantom_bin = File.join(ENV['HOME'], '.ghostbuster', 'phantomjs')

If no Ghostfile is found, it will simply use the defaults.

Output

You should get some output that looks something like this.

GhostBuster
For /Users/joshbuddy/Development/ghostbuster/ghost/test_ghost.coffee
  βœ“ Simple index
  βœ“ Form input
  βœ“ Link traversal
  βœ— Bad link traversal
    Assert location failed: Expected http://127.0.0.1:4567/not-correct, got http://127.0.0.1:4567/
  βœ— Form input not equal
    Assert first for selector #out did not meet expectations

For /Users/joshbuddy/Development/ghostbuster/ghost/test_ghostmore.coffee
  βœ“ Simple form
  ◐ Form should do more things

Your test directory should look something like this:

ghost_tests/start.sh       # Used to start your web application
ghost_tests/stop.sh        # Used to stop your web application
ghost_tests/test_*.coffee  # Your tests

Look inside ghost to see some examples of what actual tests would look like. Let's dive into a couple of simple examples.

Here is one in Coffeescript.

phantom.test.root = "http://127.0.0.1:4567" # you must specify your root.

phantom.test.add "Simple index", ->         # this adds a test
  @get '/', ->                              # this will get your a path relative to your root
    @body.assertFirst 'p', (p) ->           # this asserts the first paragraph's inner text
      p.innerHTML == 'This is my paragraph' # is 'This is my paragraph'
    @body.assertAll 'ul li', (li, idx) ->
      li.innerHTML == "List item #{idx + 1}"
    @succeed()                              # all tests must succeed

Here is the same test in Javascript.

phantom.test.root = "http://127.0.0.1:4567";  // you must specify your root.

phantom.test.add("Simple index", function() { // this adds a test
  this.get('/', function() {                  // this will get your a path relative to your root
    // this asserts the first paragraph's inner text
    this.body.assertFirst('p', function(p) { return p.innerHTML == 'This is my paragraph'});
    // this asserts all li's have the test, List item {num}
    this.body.assertAll('ul li', function(li, idx) { return li.innerHTML == "List item "+(idx + 1)});
    this.succeed();
  });                                         
});

Page Controls

The following methods are available within your test.

get

Arguments: location, [options], callback

This location will be relative to your root if it doesn't start with "http". Your callback will be called when the document is ready.

click

Arguments: selector, [index]

This will click the nth element matching the selector. If no index is specified it uses the first one found.

clickFollow

Arguments: selector, [index or options]

This will click the nth element matching the selector and assert the location changed. If no index is specified it uses the first one found. If no path option is given, it will merely assert that the location changed.

input

Arguments: selector, text

This will fill in the matching form elements with the text given.

select

Arguments: selector, newValue

This will set a select box to a given value

wait

Arguments: seconds, callback

This will wait seconds secs and then call your callback.

Assertions

Assertions are run in order, and only one assertion at a time can run. An assertion will have at most one second to complete. If you want to change the total amount of time an assertion will take, you can supply that time.

@body.assertFirst 'p', total: 3, (p) ->           # this asserts the first paragraph's inner text

The options for all assertions currently accepts total, which is the total amount of time this assertion will run for in seconds.

The available assertion function are available on body:

assertFirst

Arguments: selector, [options], callback

The callback will be called with the first matching DOM element for the selector. The callback must return true if this assertion is met.

assertAll

Arguments: selector, [options], callback

The callback will be called for each matching DOM element for the selector. The arguments supplied to the callback is the DOM element and the index (starting at 0). The callback must return true if this assertion is met.

assertLocation

Arguments: location, [options]

This assertion will attempt to match the current browser location. If your location does not start with http, it will be considered relative to the root of your test.

refuteLocation

Arguments: location, [options]

This assertion will attempt to refute the current browser location. If your location does not start with http, it will be considered relative to the root of your test.

assertCount

Arguments: selector, [options], callback

This callback will be called with the number of matching DOM elements for this selector. The callback must return true if this assertion is met.

assertCountAndAll

Arguments: selector, count, [options], callback

The callback will be called for each matching DOM element for the selector. It will only be called if the number of matching elements is equal to count. The arguments supplied to the callback is the DOM element and the index (starting at 0). The callback must return true if this assertion is met.

Before and After

You can add an arbitrary number of before and after blocks to be run within the context of your test. Simply call before and after on your test to add them. You have to call @succeed in the before block to continue processing your test.

phantom.test.before ->
  # do some setup
  @succeed()

phantom.test.after ->
  # do some teardown

More Repositories

1

spoiler-alert

SPOILER ALERT! A happy little bit of javascript to hide spoilers on your site.
JavaScript
474
star
2

jsonpath

Ruby implementation of http://goessner.net/articles/JsonPath/
Ruby
433
star
3

http_router

A kick-ass HTTP router for use in Rack
Ruby
199
star
4

usher

Pure ruby general purpose router with interfaces for rails, rack, email or choose your own adventure
Ruby
122
star
5

noexec

NO MORE BUNDLE EXEC
Ruby
109
star
6

optitron

Sensible, minimal simple options parsing and dispatching for Ruby. Build a CLI with no fuss.
Ruby
108
star
7

apiary

Convert your existing class into an EM-based API
Ruby
98
star
8

swearjar

Put another nickel in the swearjar. Simple profanity detection with content analysis.
Ruby
67
star
9

sherpa

Simple URI routing and generation in Javascript
JavaScript
60
star
10

tcplock

Throttle TCP connections to anything!
JavaScript
58
star
11

tokyo_cache_cow

Memcache server with substring deleting and aggregate functions
Ruby
47
star
12

exif-be-gone

Remove exif data using a node.js transform stream
JavaScript
40
star
13

ak47

Reload anything
Ruby
40
star
14

chirpstream

An EventMachine-based client for http://chirpstream.twitter.com.
Ruby
31
star
15

callsite

Caller/backtrace parser with some useful utilities for manipulating the load path, and doing other relative things.
Ruby
23
star
16

tumbler

Let's make gem development fun! Tumbler provides common gem management tasks using a common set of 'best practices' out of the box.
Ruby
22
star
17

rack-rewrite

Rack middleware for request rewriting
Ruby
19
star
18

rack-cache-while-revalidate

Works with Rack::Cache to serve up stale data while silently revalidating
Ruby
18
star
19

spanner

Natural language time span parsing
Ruby
18
star
20

em-ventually

Eventually, your tests should pass in EventMachine
Ruby
16
star
21

fuzzyhash

A fuzzy weird hash that can store string or ... regexs?
Ruby
16
star
22

load_path_find

Useful tools for looking for files on the $LOAD_PATH
Ruby
15
star
23

has_many_versions

Versioning for has_many relationships
Ruby
14
star
24

meddler

Hey, someone meddled with my middleware!
Ruby
14
star
25

pitcrew

AsyncIO-powered python DSL for running commands locally, on docker, or over ssh.
Python
13
star
26

spackle

Sensible DSL for ESI definition within Rails
Ruby
13
star
27

anybase

Arbitrary number bases
Ruby
13
star
28

hintable_levenshtein

levenshtein with the ability to inject hints into the ruleset for possibly cheaper rules
Ruby
12
star
29

rack-console

Rack Console that lets us take a look at a running rack app
Ruby
12
star
30

jsont

ruby implementation of http://goessner.net/articles/jsont/
Ruby
12
star
31

data_bindings

Schemas for schemaless data
Ruby
9
star
32

esi-for-rack

ESI implementation for Rack
Ruby
9
star
33

respond_to

Easy way to make respond_to? matchers for case statements.
Ruby
9
star
34

sms

Add an sms method to Kernel, because sms is the new puts. Or, sms from the command line, sms is also the new echo.
Ruby
9
star
35

em-http-monitor

Monitor, request recording and playback for em-http-request
Ruby
9
star
36

rack-tamperproof

Rack middleware that provides tamper-proof cookies
Ruby
8
star
37

dirge

Relative require, relative autoload and __DIR__
Ruby
8
star
38

messed

Framework around short message paradigms (read: twitter, irc, sms)
Ruby
8
star
39

kik

kik off a process if no listener exists on a port
Ruby
7
star
40

parameters_extra

Get back more detailed information about the arguments for a method
Ruby
7
star
41

gradients

Generate gradients because colors are fun.
Ruby
7
star
42

slick-chrome

Transfer files in chrome
JavaScript
7
star
43

http_router_sinatra

Kick ass router for Sinatra based on http_router
Ruby
7
star
44

emjay

Kickass Javascript templating for node.js and others.
JavaScript
7
star
45

padrino-presentation

Padrino Presentation for LSRC
7
star
46

decaying_bloomfilter

Time Decaying Bloom Filter - Much like a bloom-filter except keys inserted decay over-time.
Ruby
6
star
47

gameplan

Plan your game yo.
JavaScript
6
star
48

sabbath

REST for your work (queues)
Ruby
6
star
49

rack-capabilities

Discover just what rack can do (rather, what middleware you have installed)
Ruby
5
star
50

liposuction

Maybe us other protocols want middleware too. (And proxy servers)
Ruby
5
star
51

hashify

Simple to/from hash creation for your favorite classes
Ruby
5
star
52

esi_attribute_language

ESI Attribute Language
Ruby
5
star
53

shell_tools

Some common shell utilities
Ruby
5
star
54

dressmaker

Application templating in ruby. Define beautiful patterns and cut them out.
Ruby
5
star
55

q

Fast, fun, east HTML generation from Ruby
Ruby
4
star
56

tokyodystopia-ruby

TokyoDystopia Ruby bindings
C
4
star
57

queueing_proxy

Queueing HTTP proxy
Ruby
4
star
58

tumbler2

Ruby
4
star
59

arduino-examples

3
star
60

duck_duck_twilio

DuckDuckGo + Twilio SMS = WTF
Ruby
3
star
61

dreamerq

That queue I've been dreaming about
JavaScript
3
star
62

smatrix

(sparse/streaming)matrix
Ruby
3
star
63

passenger_reaper

Gemification of https://gist.github.com/596401/db750535df61e679aad69e8d9c9750f8640a234f
Ruby
3
star
64

plaza

An open modular web framework for the hacker in us all
Ruby
3
star
65

rack-regenerate

Rack middleware for periodic cache regeneration
Ruby
3
star
66

jacket

Beanstalkd monitoring, reporting and graphs!
JavaScript
3
star
67

code_stats

Brief code stats from your rakefile
Ruby
3
star
68

testable_examples

Test your examples!
Ruby
3
star
69

bundler_push_host

Set the bundler push host for the rake tasks
Ruby
3
star
70

yippee

Easily manage your requirements.txt files!
Python
2
star
71

sonjas-demo-app

Ruby
2
star
72

em-memcache-client

async Memcache client for Ruby EventMachine
Ruby
2
star
73

assetpack

Pack your assets before you leave home
JavaScript
2
star
74

tryleapjs

Tryleapjs.com
JavaScript
2
star
75

skiplist

C
2
star
76

jpake

J-pake implementation using ECC
Go
2
star
77

futures

Reading values that aren't quite set yet.
Ruby
2
star
78

squeezy

Asset compression service
Ruby
2
star
79

castle-attachmentstein

Ze attachments! Zee!
2
star
80

escaping_params

Crazy idea for autoescaping params
Ruby
2
star
81

led-display

Display emulator for that weird thing in the HackLab
Ruby
2
star
82

dsl_helper

Helpers for creating internal DSLs
Ruby
2
star
83

barbu

JavaScript
2
star
84

gravitypong

Gravity experiement
2
star
85

bridge-analysis

Some lin files with a simple parser
Ruby
2
star
86

envs

Sync your .env and .env.default files
Ruby
1
star
87

ReadEase

Unicode text normalizer browser extension
JavaScript
1
star
88

update_via_dnssec

Publish and update git repo over DNSSEC
Ruby
1
star
89

joshbuddy.github.com

Mah pages
1
star
90

changes

Make changes in multiple documents easy to see!
JavaScript
1
star