-
-
Save aler/718357 to your computer and use it in GitHub Desktop.
node jasmine spec runner and watchr config file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
// make it chmod +x and put it into ~/bin dir | |
require('jasmine'); | |
var target = ""; | |
if(process.argv[2]) { | |
target = process.argv[2] | |
} else { | |
target = process.cwd() + '/spec'; | |
} | |
jasmine.executeSpecsInFolder(target, function(runner, log){ | |
process.exit(runner.results().failedCount); | |
}, false, true, "_spec.js$"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#remove rb from file extension and put it into your root git dir | |
#install growlnotify cmd line tool | |
#I have this problem with ruby 1.9.2 https://github.com/mynyml/watchr/issues/#issue/16 | |
#works fine with ruby 1.8.7 p302 | |
require 'rubygems' | |
require 'growl' | |
RUNNER = "~/bin/spec" | |
# --------- | |
# Signals | |
# --------- | |
Signal.trap('QUIT') { run_all_specs('spec') } # Ctrl-\ | |
Signal.trap('INT' ) { abort("\nBye.\n") } # Ctrl-C | |
# --------- | |
# Rules | |
# --------- | |
watch( '^spec/(.*)_spec\.js' ) do |md| | |
run "Runnning: #{md[0]}" do | |
path = File.join(Dir.pwd, md[0]) | |
`#{RUNNER} #{path}` | |
end | |
end | |
# --------- | |
# Helpers | |
# --------- | |
def run_all_specs(target) | |
run "Running all in: #{target}" do | |
path = File.join(Dir.pwd, target) | |
`#{RUNNER} #{path}` | |
end | |
end | |
def run(description, &block) | |
puts "#{description}" | |
result = parse_result(block.call) | |
if result[:tests] =~ /\d/ | |
if $?.success? && result[:success] | |
title = "Jasmine Specs Passed!" | |
img = "~/.watchr/success.png" | |
else | |
title = "Jasmine Specs Failed!" | |
img = "~/.watchr/failed.png" | |
end | |
specs_count = pluralize(result[:assertions], "example", "examples") | |
failed_count = pluralize(result[:failures], "failure", "failures") | |
growl(title, "#{specs_count}, #{failed_count}", img) | |
else | |
growl("Running Specs Failed!", "Runner returned an error..") | |
end | |
end | |
def pluralize(count, singular, plural) | |
count == "1" ? "#{count} #{singular}" : "#{count} #{plural}" | |
end | |
def growl(title, message, image_path = nil) | |
image_path = File.expand_path(image_path) if image_path | |
roar = Growl.new | |
roar.message = message | |
roar.title = title | |
roar.image = image_path if image_path && File.exist?(image_path) | |
roar.run if Growl.installed? | |
end | |
def parse_result(result) | |
puts result | |
duration = result.scan(/Finished in (\d.\d+) seconds/).flatten.first | |
tests, assertions, failures = result.scan(/(\d+) tests?, (\d+) assertions?, (\d+) failures?/).flatten | |
{ | |
:tests => tests, | |
:assertions => assertions, | |
:failures => failures, | |
:success => failures == "0", | |
:duration => duration | |
} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment