Permalink
Browse files

initial commit

  • Loading branch information...
joshbuddy committed Aug 26, 2011
0 parents commit 2cc6c2182d63f4472c3367673c3a7cd567244bef
@@ -0,0 +1,5 @@
+*.gem
+.bundle
+Gemfile.lock
+pkg/*
+ghost/log/thin.log
@@ -0,0 +1,4 @@
+source "http://rubygems.org"
+
+# Specify your gem's dependencies in ghostbuster.gemspec
+gemspec
@@ -0,0 +1,53 @@
+# Ghostbuster
+
+Automated browser testing via phantom.js, with all of the pain taken out!
+
+## 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
+
+Once installed, you can simply use `ghostbuster path/to/tests` to run your tests. You should get some output that looks something liek this.
+
+~~~~
+
+ GhostBuster
+ For /Users/joshbuddy/Development/ghostbuster/ghost/test_ghost.coffee
+ ✓ Simple index
+ ✓ Form input
+ ✓ Link traversal
+ ✗ Bad link traversal
+ Assert location failed: Excepted 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.
+
+~~~~
+
+ 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
+
+~~~~
+
+To use this within rake, just put `require 'ghostbuster/install_rake'` in your Rakefile.
@@ -0,0 +1,3 @@
+require 'bundler/gem_tasks'
+$: << 'lib'
+require 'ghostbuster/install_rake'
@@ -0,0 +1,4 @@
+#!/usr/bin/env ruby
+
+require 'ghostbuster'
+Ghostbuster::Runner.new(ARGV).run
@@ -0,0 +1,32 @@
+#!/usr/bin/env ruby
+
+case RUBY_PLATFORM
+when /darwin/
+ require 'fileutils'
+ puts "Creating ghostbuster directory in your home"
+ root = File.expand_path(File.join(ENV['HOME'], '.ghostbuster'))
+ cache = File.expand_path(File.join(root, 'cache'))
+ unless File.exist?(File.join(root, 'version')) && File.read(File.join(root, 'version')) == '1'
+ FileUtils.rm_rf(root)
+ FileUtils.mkdir_p(root)
+ FileUtils.mkdir_p(cache)
+ phantom_url = "http://phantomjs.googlecode.com/files/phantomjs-1.2.0-macosx-universal.dmg"
+ unless File.exist?(File.join(cache, File.basename(phantom_url)))
+ Dir.chdir(cache) do
+ puts "Downloading and install phantom.js"
+ system("curl #{phantom_url} -O") or raise("Unable to download from #{phantom_url}")
+ system("open #{File.basename(phantom_url)}") or raise("Unable to open disk image")
+ end
+ system("cp -r /Volumes/phantomjs/phantomjs.app #{root}")
+ File.exist?("#{root}/phantomjs.app") or raise("Unable to copy phantomjs from your disk image")
+ system("ln -s #{root}/phantomjs.app/Contents/MacOS/phantomjs #{root}/phantomjs") or raise("Unable to copy phantomjs from your disk image")
+ `hdiutil eject /Volumes/phantomjs`
+ File.open("#{root}/version", 'w') {|f| f << '1' }
+ else
+ puts "Already installed and at the right version"
+ end
+ end
+else
+ puts "I don't know how to install for RUBY_PLATFORM #{RUBY_PLATFORM}"
+ exit(1)
+end
@@ -0,0 +1,14 @@
+require 'rubygems'
+require 'sinatra'
+
+class App < Sinatra::Base
+ get "/" do
+ erb :index
+ end
+
+ get "/form" do
+ erb :form
+ end
+end
+
+run App
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+bundle exec thin --port 4567 -P thin.pid -d -R config.ru start
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+bundle exec thin --port 4567 -P thin.pid -d -R config.ru stop
@@ -0,0 +1,37 @@
+phantom.test.root = "http://127.0.0.1:4567"
+
+phantom.test.add "Simple index", ->
+ @get '/', ->
+ @body.assertFirst 'p', (p) ->
+ p.innerHTML == 'This is my paragraph'
+ @body.assertAll 'ul li', (li, idx) ->
+ li.innerHTML == "List item #{idx + 1}"
+ @succeed()
+
+phantom.test.add "Form input", ->
+ @get '/form', ->
+ @body.input "#in", "this is my input"
+ @body.click "#btn"
+ @body.assertFirst '#out', (out) ->
+ out.innerHTML == 'this is my input'
+ @succeed()
+
+phantom.test.add "Link traversal", ->
+ @get '/', ->
+ @body.click 'a'
+ @body.assertLocation('/form')
+ @succeed()
+
+phantom.test.add "Bad link traversal", ->
+ @get '/', ->
+ @body.click 'a'
+ @body.assertLocation('/not-correct')
+ @succeed()
+
+phantom.test.add "Form input not equal", ->
+ @get '/form', ->
+ @body.input "#in", "this is my input"
+ @body.click "#btn"
+ @body.assertFirst '#out', (out) ->
+ out.innerHTML == 'this is NOT my input'
+ @succeed()
@@ -0,0 +1,8 @@
+phantom.test.root = "http://127.0.0.1:4567"
+
+phantom.test.add "Simple form", ->
+ @get '/form', ->
+ @succeed()
+
+phantom.test.addPending "Form should do more things", ->
+ console.log "some thing here.."
@@ -0,0 +1,12 @@
+<html>
+<head>
+ <title>This is my index</title>
+</head>
+<body>
+ <form>
+ <input type="text" id="in">
+ <input type="button" id="btn" onclick="document.getElementById('out').innerHTML = document.getElementById('in').value;">
+ </form>
+ <p id="out"></p>
+</body>
+</html>
@@ -0,0 +1,15 @@
+<html>
+<head>
+ <title>This is my index</title>
+</head>
+<body>
+ <h1>First header</h1>
+ <p>This is my paragraph</p>
+ <ul>
+ <li>List item 1</li>
+ <li>List item 2</li>
+ <li>List item 3</li>
+ </ul>
+ <a href="/form">form</a>
+</body>
+</html>
@@ -0,0 +1,25 @@
+# -*- encoding: utf-8 -*-
+$:.push File.expand_path("../lib", __FILE__)
+require "ghostbuster/version"
+
+Gem::Specification.new do |s|
+ s.name = "ghostbuster"
+ s.version = Ghostbuster::VERSION
+ s.authors = ["Josh Hull"]
+ s.email = ["joshbuddy@gmail.com"]
+ s.homepage = "https://github.com/joshbuddy/ghostbuster"
+ s.summary = %q{Integration testing ftw}
+ s.description = %q{Integration testing ftw.}
+
+ s.rubyforge_project = "ghostbuster"
+
+ s.files = `git ls-files`.split("\n")
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
+ s.require_paths = ["lib"]
+
+ s.add_development_dependency 'thin', '~> 1.2.11'
+ s.add_development_dependency 'rake', '~> 0.8.7'
+ s.add_development_dependency 'bundler', '~> 1.0.14'
+ s.add_development_dependency 'sinatra'
+end
Oops, something went wrong.

0 comments on commit 2cc6c21

Please sign in to comment.