better handling for when spec runner is kiled prematurely
This commit is contained in:
parent
0b5092348c
commit
732cc625a8
1
Gemfile
1
Gemfile
|
@ -7,3 +7,4 @@ gem 'rspec'
|
|||
gem 'mocha'
|
||||
gem 'rake', '0.8.7'
|
||||
gem 'growl'
|
||||
gem 'fakefs', :require => nil
|
||||
|
|
|
@ -18,11 +18,14 @@ module Guard
|
|||
end
|
||||
|
||||
def run_all
|
||||
JasmineHeadlessWebkitRunner.run if run_before
|
||||
JasmineHeadlessWebkitRunner.run if run_before and run_jammit
|
||||
@ran_jammit = false
|
||||
end
|
||||
|
||||
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
|
||||
end
|
||||
end
|
||||
|
@ -30,13 +33,26 @@ module Guard
|
|||
private
|
||||
def run_before
|
||||
if @options[:run_before]
|
||||
UI.info "Guard::JasmineHeadlessWebkit running #{@options[:run_before]} first..."
|
||||
system @options[:run_before]
|
||||
$?.exitstatus == 0
|
||||
run_program(@options[:run_before])
|
||||
else
|
||||
true
|
||||
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
|
||||
|
||||
class Dsl
|
||||
|
|
|
@ -9,15 +9,25 @@ module Guard
|
|||
|
||||
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
|
||||
|
||||
def notify(file)
|
||||
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
|
||||
|
||||
private
|
||||
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
|
||||
|
||||
def image(any_console, fails)
|
||||
|
|
|
@ -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
|
|
@ -50,6 +50,7 @@ describe Guard::JasmineHeadlessWebkit do
|
|||
context 'with failing command' do
|
||||
before do
|
||||
Guard::JasmineHeadlessWebkitRunner.expects(:run).never
|
||||
Guard::UI.expects(:info).with(regexp_matches(/false/))
|
||||
end
|
||||
|
||||
let(:options) { { :run_before => 'false' } }
|
||||
|
@ -62,6 +63,7 @@ describe Guard::JasmineHeadlessWebkit do
|
|||
context 'with succeeding command' do
|
||||
before do
|
||||
Guard::JasmineHeadlessWebkitRunner.expects(:run).once
|
||||
Guard::UI.expects(:info).with(regexp_matches(/true/))
|
||||
end
|
||||
|
||||
let(:options) { { :run_before => 'true' } }
|
||||
|
@ -71,4 +73,32 @@ describe Guard::JasmineHeadlessWebkit do
|
|||
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
|
||||
|
|
Loading…
Reference in New Issue