Ghostbuster: Easier headless testing with PhantomJS (and CoffeeScript)

Ghostbuster from Joshua Hull from the Padrino team aims to make it even easier to get started with PhantomJS. Just by installing the gem, Ghostbuster will download and configure Phantom JS so you can write beautiful tests in CoffeeScript.

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

I love the simple test output. UTF-8 entities FTW:

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

See the GitHub repo for usage.

News Films

Our little film studio focuses on telling developer-centric stories that need to be seen.

GopherCon 2016 Conference Recap

0:00 / 0:00