From c9e7bb60cb1476f7fe4e2de2cbbd990c9fb743d7 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Tue, 27 Sep 2011 14:30:49 -0400 Subject: [PATCH] fix double inclusion and do glob expansion in runner, fix #7 --- lib/guard/jasmine-headless-webkit.rb | 2 +- lib/guard/jasmine-headless-webkit/runner.rb | 4 +- .../lib/guard/jasmine-headless-webkit_spec.rb | 51 +++++++++++++++++-- 3 files changed, 48 insertions(+), 9 deletions(-) diff --git a/lib/guard/jasmine-headless-webkit.rb b/lib/guard/jasmine-headless-webkit.rb index 6dcee90..a0ff50c 100644 --- a/lib/guard/jasmine-headless-webkit.rb +++ b/lib/guard/jasmine-headless-webkit.rb @@ -79,7 +79,7 @@ module Guard end def filter_paths(paths) - paths.find_all { |path| File.extname(path)[valid_extensions] }.uniq + paths.collect { |path| Dir[path] }.flatten.find_all { |path| File.extname(path)[valid_extensions] }.uniq end def valid_extensions diff --git a/lib/guard/jasmine-headless-webkit/runner.rb b/lib/guard/jasmine-headless-webkit/runner.rb index 6913564..70bc3c5 100644 --- a/lib/guard/jasmine-headless-webkit/runner.rb +++ b/lib/guard/jasmine-headless-webkit/runner.rb @@ -20,13 +20,11 @@ module Guard 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_files else - raise Jasmine::Headless::InvalidReport.new + raise Jasmine::Headless::InvalidReport end rescue Jasmine::Headless::InvalidReport => e Notifier.notify('Spec runner interrupted!', :title => 'Jasmine results', :image => :failed) false - rescue Exception => e - p e end private diff --git a/spec/lib/guard/jasmine-headless-webkit_spec.rb b/spec/lib/guard/jasmine-headless-webkit_spec.rb index 27bd199..95e15db 100644 --- a/spec/lib/guard/jasmine-headless-webkit_spec.rb +++ b/spec/lib/guard/jasmine-headless-webkit_spec.rb @@ -1,5 +1,6 @@ require 'spec_helper' require 'guard/jasmine-headless-webkit' +require 'fakefs/spec_helpers' describe Guard::JasmineHeadlessWebkit do let(:guard) { Guard::JasmineHeadlessWebkit.new([], options) } @@ -70,11 +71,26 @@ describe Guard::JasmineHeadlessWebkit do end describe '#run_on_change' do + include FakeFS::SpecHelpers + let(:one_file) { %w{test.js} } + def absolute(file) + case file + when Array + file.collect { |f| absolute(f) } + else + File.expand_path(file) + end + end + + before do + File.open(one_file.first, 'wb') + end + context 'two files' do it "should only run one" do - Guard::JasmineHeadlessWebkitRunner.expects(:run).with(one_file, {}).returns(one_file) + Guard::JasmineHeadlessWebkitRunner.expects(:run).with(absolute(one_file), {}).returns(one_file) guard.run_on_change(%w{test.js test.js}).should be_false guard.files_to_rerun.should == one_file @@ -93,7 +109,7 @@ describe Guard::JasmineHeadlessWebkit do 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::JasmineHeadlessWebkitRunner.expects(:run).with(absolute(one_file) + [ "two.js" ], {}).returns(one_file) guard.run_on_change(one_file).should be_false guard.files_to_rerun.should == one_file @@ -102,11 +118,11 @@ describe Guard::JasmineHeadlessWebkit do 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.instance_variable_set(:@files_to_rerun, absolute(one_file)) + Guard::JasmineHeadlessWebkitRunner.expects(:run).with(absolute(one_file), {}).returns(false) guard.run_on_change(one_file).should be_false - guard.files_to_rerun.should == one_file + guard.files_to_rerun.should == absolute(one_file) end end @@ -138,6 +154,31 @@ describe Guard::JasmineHeadlessWebkit do guard.files_to_rerun.should == [] end end + + context 'glob given' do + let(:files) { %w{file1.js file2.js other.js} } + + before do + files.each { |file| File.open(file, 'wb') } + end + + context 'not a duplicate' do + it 'should expand the glob' do + Guard::JasmineHeadlessWebkitRunner.expects(:run).with(absolute(%w{file1.js file2.js}), {}).returns(false) + + guard.run_on_change(%w{file*.js}) + end + end + + context 'a duplicate' do + it 'should expand the glob and uniq' do + guard.instance_variable_set(:@files_to_rerun, absolute(%w{file1.js})) + Guard::JasmineHeadlessWebkitRunner.expects(:run).with(absolute(%w{file1.js file2.js}), {}).returns(false) + + guard.run_on_change(%w{file*.js}) + end + end + end end context 'with run_before' do