fix double inclusion and do glob expansion in runner, fix #7

This commit is contained in:
John Bintz 2011-09-27 14:30:49 -04:00
parent cd27ecb5be
commit c9e7bb60cb
3 changed files with 48 additions and 9 deletions

View File

@ -79,7 +79,7 @@ module Guard
end end
def filter_paths(paths) 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 end
def valid_extensions def valid_extensions

View File

@ -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)) 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 report.failed_files
else else
raise Jasmine::Headless::InvalidReport.new raise Jasmine::Headless::InvalidReport
end end
rescue Jasmine::Headless::InvalidReport => 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)
false false
rescue Exception => e
p e
end end
private private

View File

@ -1,5 +1,6 @@
require 'spec_helper' require 'spec_helper'
require 'guard/jasmine-headless-webkit' require 'guard/jasmine-headless-webkit'
require 'fakefs/spec_helpers'
describe Guard::JasmineHeadlessWebkit do describe Guard::JasmineHeadlessWebkit do
let(:guard) { Guard::JasmineHeadlessWebkit.new([], options) } let(:guard) { Guard::JasmineHeadlessWebkit.new([], options) }
@ -70,11 +71,26 @@ describe Guard::JasmineHeadlessWebkit do
end end
describe '#run_on_change' do describe '#run_on_change' do
include FakeFS::SpecHelpers
let(:one_file) { %w{test.js} } 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 context 'two files' do
it "should only run one" 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.run_on_change(%w{test.js test.js}).should be_false
guard.files_to_rerun.should == one_file guard.files_to_rerun.should == one_file
@ -93,7 +109,7 @@ describe Guard::JasmineHeadlessWebkit do
context 'one file one prior' do context 'one file one prior' do
it "should not run all" do it "should not run all" do
guard.instance_variable_set(:@files_to_rerun, [ "two.js" ]) 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.run_on_change(one_file).should be_false
guard.files_to_rerun.should == one_file guard.files_to_rerun.should == one_file
@ -102,11 +118,11 @@ describe Guard::JasmineHeadlessWebkit do
context 'failed hard' do context 'failed hard' do
it "should not run all" do it "should not run all" do
guard.instance_variable_set(:@files_to_rerun, one_file) guard.instance_variable_set(:@files_to_rerun, absolute(one_file))
Guard::JasmineHeadlessWebkitRunner.expects(:run).with(one_file, {}).returns(nil) Guard::JasmineHeadlessWebkitRunner.expects(:run).with(absolute(one_file), {}).returns(false)
guard.run_on_change(one_file).should be_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
end end
@ -138,6 +154,31 @@ describe Guard::JasmineHeadlessWebkit do
guard.files_to_rerun.should == [] guard.files_to_rerun.should == []
end end
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 end
context 'with run_before' do context 'with run_before' do