always re-run failed specs, clear those out with ctrl-z

This commit is contained in:
John Bintz 2011-09-06 16:00:27 -04:00
parent 5baaf8f6e3
commit 570ea0814e
4 changed files with 68 additions and 17 deletions

View File

@ -7,6 +7,8 @@ module Guard
class JasmineHeadlessWebkit < Guard class JasmineHeadlessWebkit < Guard
DEFAULT_EXTENSIONS = %w{js coffee} DEFAULT_EXTENSIONS = %w{js coffee}
attr_reader :files_to_rerun
def initialize(watchers = [], options = {}) def initialize(watchers = [], options = {})
super super
@options = { @options = {
@ -14,6 +16,8 @@ module Guard
:run_before => false, :run_before => false,
:valid_extensions => DEFAULT_EXTENSIONS :valid_extensions => DEFAULT_EXTENSIONS
}.merge(options) }.merge(options)
@files_to_rerun = []
end end
def start def start
@ -21,6 +25,11 @@ module Guard
run_all if @options[:all_on_start] run_all if @options[:all_on_start]
end end
def reload
@files_to_rerun = []
UI.info "Resetting Guard::JasmineHeadlessWebkit failed files..."
end
def run_all def run_all
run_something_and_rescue do run_something_and_rescue do
UI.info "Guard::JasmineHeadlessWebkit running all specs..." UI.info "Guard::JasmineHeadlessWebkit running all specs..."
@ -36,8 +45,11 @@ module Guard
if run_all_things_before if run_all_things_before
@ran_before = true @ran_before = true
if !paths.empty? if !paths.empty?
paths = (paths + @files_to_rerun).uniq
UI.info "Guard::JasmineHeadlessWebkit running the following: #{paths.join(' ')}" UI.info "Guard::JasmineHeadlessWebkit running the following: #{paths.join(' ')}"
JasmineHeadlessWebkitRunner.run(paths) if failed_files = JasmineHeadlessWebkitRunner.run(paths)
@files_to_rerun = failed_files
end
else else
run_all run_all
end end

View File

@ -16,12 +16,14 @@ module Guard
def notify(file) def notify(file)
if (report = Jasmine::Headless::Report.load(file)).valid? if (report = Jasmine::Headless::Report.load(file)).valid?
Notifier.notify(message(report.total, report.failed, report.time, report.has_used_console?), :title => 'Jasmine results', :image => image(report.has_used_console?, report.failed)) Notifier.notify(message(report.total, report.failed, report.time, report.has_used_console?), :title => 'Jasmine results', :image => image(report.has_used_console?, report.failed))
report.failed report.failed_files
else else
raise StandardError.new("invalid report") raise Jasmine::Headless::InvalidReport.new
end end
rescue Exception => e rescue Jasmine::Headless::InvalidReport => e
Notifier.notify('Spec runner interrupted!', :title => 'Jasmine results', :image => :failed) Notifier.notify('Spec runner interrupted!', :title => 'Jasmine results', :image => :failed)
rescue Exception => e
p e
end end
private private

View File

@ -18,17 +18,20 @@ describe Guard::JasmineHeadlessWebkitRunner do
it 'should notify with the right information' do it 'should notify with the right information' do
Guard::Notifier.expects(:notify).with("1 test, 0 failures, 5.0 secs.", { :title => 'Jasmine results', :image => :success }) Guard::Notifier.expects(:notify).with("1 test, 0 failures, 5.0 secs.", { :title => 'Jasmine results', :image => :success })
Guard::JasmineHeadlessWebkitRunner.notify(file) Guard::JasmineHeadlessWebkitRunner.notify(file).should == []
end end
end end
context 'with failures' do context 'with failures' do
let(:data) { "TOTAL||1||1||5||F" } let(:data) { <<-REPORT }
FAIL||Test||Two||file.js:50
TOTAL||1||1||5||F
REPORT
it 'should notify with the right information' do it 'should notify with the right information' do
Guard::Notifier.expects(:notify).with("1 test, 1 failures, 5.0 secs.", { :title => 'Jasmine results', :image => :failed }) Guard::Notifier.expects(:notify).with("1 test, 1 failures, 5.0 secs.", { :title => 'Jasmine results', :image => :failed })
Guard::JasmineHeadlessWebkitRunner.notify(file) Guard::JasmineHeadlessWebkitRunner.notify(file).should == [ 'file.js' ]
end end
end end
@ -38,7 +41,7 @@ describe Guard::JasmineHeadlessWebkitRunner do
it 'should notify failure' do it 'should notify failure' do
Guard::Notifier.expects(:notify).with("Spec runner interrupted!", { :title => 'Jasmine results', :image => :failed }) Guard::Notifier.expects(:notify).with("Spec runner interrupted!", { :title => 'Jasmine results', :image => :failed })
Guard::JasmineHeadlessWebkitRunner.notify(file) Guard::JasmineHeadlessWebkitRunner.notify(file).should be_nil
end end
end end
end end

View File

@ -27,30 +27,52 @@ describe Guard::JasmineHeadlessWebkit do
end end
describe '#run_on_change' do describe '#run_on_change' do
let(:one_file) { %w{test.js} }
context 'two files' do context 'two files' do
it "should only run one" do it "should only run one" do
Guard::JasmineHeadlessWebkitRunner.expects(:run).with(%w{test.js}).returns(1) Guard::JasmineHeadlessWebkitRunner.expects(:run).with(one_file).returns(one_file)
guard.expects(:run_all).never
guard.run_on_change(%w{test.js test.js}) guard.run_on_change(%w{test.js test.js})
guard.files_to_rerun.should == one_file
end end
end end
context 'jhw call fails' do context 'one file no priors' do
it "should not run all" do it "should not run all" do
Guard::JasmineHeadlessWebkitRunner.expects(:run).returns(1) Guard::JasmineHeadlessWebkitRunner.expects(:run).returns(one_file)
guard.expects(:run_all).never
guard.run_on_change(%w{test.js}) guard.run_on_change(one_file)
guard.files_to_rerun.should == one_file
end
end
context 'one file one prior' do
it "should not run all" do
guard.instance_variable_set(:@files_to_rerun, [ "two.js" ])
Guard::JasmineHeadlessWebkitRunner.expects(:run).with(one_file + [ "two.js" ]).returns(one_file)
guard.run_on_change(one_file)
guard.files_to_rerun.should == one_file
end
end
context 'failed hard' do
it "should not run all" do
guard.instance_variable_set(:@files_to_rerun, one_file)
Guard::JasmineHeadlessWebkitRunner.expects(:run).with(one_file).returns(nil)
guard.run_on_change(one_file)
guard.files_to_rerun.should == one_file
end end
end end
context 'succeed, but still do not run all' do context 'succeed, but still do not run all' do
it "should run all" do it "should run all" do
Guard::JasmineHeadlessWebkitRunner.expects(:run).returns(0) Guard::JasmineHeadlessWebkitRunner.expects(:run).returns([])
guard.expects(:run_all).never
guard.run_on_change(%w{test.js}) guard.run_on_change(one_file)
guard.files_to_rerun.should == []
end end
end end
@ -60,6 +82,7 @@ describe Guard::JasmineHeadlessWebkit do
guard.expects(:run_all).once guard.expects(:run_all).once
guard.run_on_change([]) guard.run_on_change([])
guard.files_to_rerun.should == []
end end
end end
@ -69,6 +92,7 @@ describe Guard::JasmineHeadlessWebkit do
guard.expects(:run_all).once guard.expects(:run_all).once
guard.run_on_change(%w{test.jst}) guard.run_on_change(%w{test.jst})
guard.files_to_rerun.should == []
end end
end end
end end
@ -102,4 +126,14 @@ describe Guard::JasmineHeadlessWebkit do
end end
end end
end end
describe '#reload' do
it 'should reset the state of the files_to_rerun' do
Guard::UI.expects(:info).with(regexp_matches(/Resetting/))
guard.instance_variable_set(:@files_to_rerun, "test")
guard.reload
guard.files_to_rerun.should == []
end
end
end end