Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Integration testing ftw
CoffeeScript Ruby Other

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.


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!


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.


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


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

    ghost.pattern = "test_*.coffee" # this is the default

To enable (or disable) screenshots use:

    ghost.take_screenshots! # or #do_not_takescreenshots! 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 # x, y

To set the command for starting your server use:

    ghost.start_command "./"

To set the command for stopping your server use:

    ghost.stop_command "./"

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

You should get some output that looks something like this.

    For /Users/joshbuddy/Development/ghostbuster/ghost/
      ✓ Simple index
      ✓ Form input
      ✓ Link traversal
      ✗ Bad link traversal
        Assert location failed: Excepted, got
      ✗ Form input not equal
        Assert first for selector #out did not meet expectations

    For /Users/joshbuddy/Development/ghostbuster/ghost/
      ✓ Simple form
      • Form should do more things

Your test directory should look something like this:

ghost_tests/       # Used to start your web application
ghost_tests/        # 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.

    phantom.test.root = "" # 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

To use this within rake, just put require 'ghostbuster/install_rake' in your Rakefile.


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 available assertions are:

  • assertFirst : This asserts for the first matching DOM element
  • assertAll : This asserts for the each matching DOM element
  • assertLocation : This asserts the current browser location

The closures passed for matching have access to the real DOM node, however, they do not have any access to the outside context. They must return true if the assertion is passed, anything else will be interpreted as failure.

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

    phantom.test.after ->
      # do some teardown
Something went wrong with that request. Please try again.