From 570ea0814ea819870874281fead57f7482a491cb Mon Sep 17 00:00:00 2001 From: John Bintz Date: Tue, 6 Sep 2011 16:00:27 -0400 Subject: [PATCH] always re-run failed specs, clear those out with ctrl-z --- lib/guard/jasmine-headless-webkit.rb | 14 ++++- lib/guard/jasmine-headless-webkit/runner.rb | 8 +-- .../jasmine-headless-webkit/runner_spec.rb | 11 ++-- .../lib/guard/jasmine-headless-webkit_spec.rb | 52 +++++++++++++++---- 4 files changed, 68 insertions(+), 17 deletions(-) diff --git a/lib/guard/jasmine-headless-webkit.rb b/lib/guard/jasmine-headless-webkit.rb index 2c5d891..41eda1e 100644 --- a/lib/guard/jasmine-headless-webkit.rb +++ b/lib/guard/jasmine-headless-webkit.rb @@ -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 diff --git a/lib/guard/jasmine-headless-webkit/runner.rb b/lib/guard/jasmine-headless-webkit/runner.rb index 4f7ff2b..d8de8fb 100644 --- a/lib/guard/jasmine-headless-webkit/runner.rb +++ b/lib/guard/jasmine-headless-webkit/runner.rb @@ -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 diff --git a/spec/lib/guard/jasmine-headless-webkit/runner_spec.rb b/spec/lib/guard/jasmine-headless-webkit/runner_spec.rb index 03a3bcf..3623e7e 100644 --- a/spec/lib/guard/jasmine-headless-webkit/runner_spec.rb +++ b/spec/lib/guard/jasmine-headless-webkit/runner_spec.rb @@ -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 diff --git a/spec/lib/guard/jasmine-headless-webkit_spec.rb b/spec/lib/guard/jasmine-headless-webkit_spec.rb index e7d5380..c57fd38 100644 --- a/spec/lib/guard/jasmine-headless-webkit_spec.rb +++ b/spec/lib/guard/jasmine-headless-webkit_spec.rb @@ -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