better handling for when spec runner is kiled prematurely

This commit is contained in:
John Bintz 2011-06-01 17:14:23 -04:00
parent 0b5092348c
commit 732cc625a8
5 changed files with 101 additions and 9 deletions

View File

@ -7,3 +7,4 @@ gem 'rspec'
gem 'mocha' gem 'mocha'
gem 'rake', '0.8.7' gem 'rake', '0.8.7'
gem 'growl' gem 'growl'
gem 'fakefs', :require => nil

View File

@ -18,11 +18,14 @@ module Guard
end end
def run_all def run_all
JasmineHeadlessWebkitRunner.run if run_before JasmineHeadlessWebkitRunner.run if run_before and run_jammit
@ran_jammit = false
end end
def run_on_change(paths) def run_on_change(paths)
if run_before @ran_jammit = false
if run_before and run_jammit
@ran_jammit = true
run_all if JasmineHeadlessWebkitRunner.run(paths) == 0 run_all if JasmineHeadlessWebkitRunner.run(paths) == 0
end end
end end
@ -30,13 +33,26 @@ module Guard
private private
def run_before def run_before
if @options[:run_before] if @options[:run_before]
UI.info "Guard::JasmineHeadlessWebkit running #{@options[:run_before]} first..." run_program(@options[:run_before])
system @options[:run_before]
$?.exitstatus == 0
else else
true true
end end
end end
def run_jammit
if @options[:jammit] && !@ran_jammit
run_program("Jammit", %{jammit -f 2>/dev/null})
else
true
end
end
def run_program(name, command = nil)
command ||= name
UI.info "Guard::JasmineHeadlessWebkit running #{name}..."
system command
$?.exitstatus == 0
end
end end
class Dsl class Dsl

View File

@ -9,15 +9,25 @@ module Guard
system %{jasmine-headless-webkit --report #{file.path} -c #{paths.join(" ")}} system %{jasmine-headless-webkit --report #{file.path} -c #{paths.join(" ")}}
total, fails, any_console, secs = File.read(file.path).strip.split('/') notify(file.path)
end
Notifier.notify(message(total, fails, secs, any_console == "T"), :title => 'Jasmine results', :image => image(any_console == "T", fails)) def notify(file)
fails.to_i if (data = File.read(file).strip).empty?
Notifier.notify('Spec runner interrupted!', :title => 'Jasmine results', :image => :failed)
else
total, fails, any_console, secs = File.read(file).strip.split('/')
Notifier.notify(message(total, fails, secs, any_console == "T"), :title => 'Jasmine results', :image => image(any_console == "T", fails))
fails.to_i
end
end end
private private
def message(total, fails, secs, any_console) def message(total, fails, secs, any_console)
"#{total} tests, #{fails} failures, #{secs} secs#{any_console ? ', console.log used' : ''}." total_word = (total.to_i == 1) ? "test" : "tests"
"#{total} #{total_word}, #{fails} failures, #{secs} secs#{any_console ? ', console.log used' : ''}."
end end
def image(any_console, fails) def image(any_console, fails)

View File

@ -0,0 +1,35 @@
require 'spec_helper'
require 'guard/jasmine-headless-webkit/runner'
require 'fakefs/spec_helpers'
describe Guard::JasmineHeadlessWebkitRunner do
describe '.notify' do
include FakeFS::SpecHelpers
let(:file) { 'temp.txt' }
before do
File.open(file, 'w') { |fh| fh.print data }
end
context 'system run not interrupted' do
let(:data) { '1/0/F/5' }
it 'should notify with the right information' do
Guard::Notifier.expects(:notify).with("1 test, 0 failures, 5 secs.", { :title => 'Jasmine results', :image => :success })
Guard::JasmineHeadlessWebkitRunner.notify(file)
end
end
context 'system run interrupted' do
let(:data) { '' }
it 'should notify failure' do
Guard::Notifier.expects(:notify).with("Spec runner interrupted!", { :title => 'Jasmine results', :image => :failed })
Guard::JasmineHeadlessWebkitRunner.notify(file)
end
end
end
end

View File

@ -50,6 +50,7 @@ describe Guard::JasmineHeadlessWebkit do
context 'with failing command' do context 'with failing command' do
before do before do
Guard::JasmineHeadlessWebkitRunner.expects(:run).never Guard::JasmineHeadlessWebkitRunner.expects(:run).never
Guard::UI.expects(:info).with(regexp_matches(/false/))
end end
let(:options) { { :run_before => 'false' } } let(:options) { { :run_before => 'false' } }
@ -62,6 +63,7 @@ describe Guard::JasmineHeadlessWebkit do
context 'with succeeding command' do context 'with succeeding command' do
before do before do
Guard::JasmineHeadlessWebkitRunner.expects(:run).once Guard::JasmineHeadlessWebkitRunner.expects(:run).once
Guard::UI.expects(:info).with(regexp_matches(/true/))
end end
let(:options) { { :run_before => 'true' } } let(:options) { { :run_before => 'true' } }
@ -71,4 +73,32 @@ describe Guard::JasmineHeadlessWebkit do
end end
end end
end end
describe 'run jammit first' do
context 'run on run_all if called first' do
before do
guard.expects(:run_program).once.returns(true)
Guard::JasmineHeadlessWebkitRunner.expects(:run).once
end
let(:options) { { :jammit => true } }
it "should run jammit first" do
guard.run_all
end
end
context 'only run once if run_on_change is successful' do
before do
guard.expects(:run_program).once.returns(true)
Guard::JasmineHeadlessWebkitRunner.expects(:run).twice.returns(0)
end
let(:options) { { :jammit => true } }
it "should run jammit only once" do
guard.run_on_change([])
end
end
end
end end