Skip to content

Instantly share code, notes, and snippets.

@joahking
Forked from songkick/gist:15273
Created March 2, 2009 15:29
Show Gist options
  • Save joahking/72807 to your computer and use it in GitHub Desktop.
Save joahking/72807 to your computer and use it in GitHub Desktop.
#!/usr/bin/env jruby
# fast script for running javascript unit tests
# requires a bit of setup, as it uses jruby
# see http://celerity.rubyforge.org/
require "rubygems"
require "celerity"
module Javascript
class SpecRunner
def initialize(suites, browser = Celerity::Browser.new)
@browser = browser
@suites = suites
end
def run_all
@suites.each do |suite|
@browser.goto(suite)
puts "Running Javascript specs in #{suite}"
sleep(0.1) until @browser.text.include?("test(s)")
specs_run, specs_failed, duration = @browser.text.scan(/(\d+) test\(s\), (\d+) failure\(s\) (\d+\.\d+) seconds elapsed/)[0]
puts "Finished in #{duration} seconds"
puts
puts "#{specs_run} examples, #{specs_failed} failures"
end
end
end
end
# TODO: scan for files, and don't hardcode the path!
suites = ['file://localhost/Users/matt/projects/songkick/skweb/spec/javascripts/comments_spec.html']
runner = Javascript::SpecRunner.new(suites)
runner.run_all
puts "ENTER to run again."
while readline == "\n"
runner.run_all
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment