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

View File

@ -16,12 +16,14 @@ module Guard
def notify(file)
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))
report.failed
report.failed_files
else
raise StandardError.new("invalid report")
raise Jasmine::Headless::InvalidReport.new
end
rescue Exception => e
rescue Jasmine::Headless::InvalidReport => e
Notifier.notify('Spec runner interrupted!', :title => 'Jasmine results', :image => :failed)
rescue Exception => e
p e
end
private

View File

@ -18,17 +18,20 @@ describe Guard::JasmineHeadlessWebkitRunner 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::JasmineHeadlessWebkitRunner.notify(file)
Guard::JasmineHeadlessWebkitRunner.notify(file).should == []
end
end
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
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
@ -38,7 +41,7 @@ describe Guard::JasmineHeadlessWebkitRunner do
it 'should notify failure' do
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

View File

@ -27,30 +27,52 @@ describe Guard::JasmineHeadlessWebkit do
end
describe '#run_on_change' do
let(:one_file) { %w{test.js} }
context 'two files' do
it "should only run one" do
Guard::JasmineHeadlessWebkitRunner.expects(:run).with(%w{test.js}).returns(1)
guard.expects(:run_all).never
Guard::JasmineHeadlessWebkitRunner.expects(:run).with(one_file).returns(one_file)
guard.run_on_change(%w{test.js test.js})
guard.files_to_rerun.should == one_file
end
end
context 'jhw call fails' do
context 'one file no priors' do
it "should not run all" do
Guard::JasmineHeadlessWebkitRunner.expects(:run).returns(1)
guard.expects(:run_all).never
Guard::JasmineHeadlessWebkitRunner.expects(:run).returns(one_file)
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
context 'succeed, but still do not run all' do
it "should run all" do
Guard::JasmineHeadlessWebkitRunner.expects(:run).returns(0)
guard.expects(:run_all).never
Guard::JasmineHeadlessWebkitRunner.expects(:run).returns([])
guard.run_on_change(%w{test.js})
guard.run_on_change(one_file)
guard.files_to_rerun.should == []
end
end
@ -60,6 +82,7 @@ describe Guard::JasmineHeadlessWebkit do
guard.expects(:run_all).once
guard.run_on_change([])
guard.files_to_rerun.should == []
end
end
@ -69,6 +92,7 @@ describe Guard::JasmineHeadlessWebkit do
guard.expects(:run_all).once
guard.run_on_change(%w{test.jst})
guard.files_to_rerun.should == []
end
end
end
@ -102,4 +126,14 @@ describe Guard::JasmineHeadlessWebkit do
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