smarter filtering of files by extension
This commit is contained in:
parent
8497977cac
commit
761de5a80a
@ -4,11 +4,14 @@ require 'guard/jasmine-headless-webkit/runner'
|
||||
|
||||
module Guard
|
||||
class JasmineHeadlessWebkit < Guard
|
||||
DEFAULT_EXTENSIONS = %w{js coffee}
|
||||
|
||||
def initialize(watchers = [], options = {})
|
||||
super
|
||||
@options = {
|
||||
:all_on_start => true,
|
||||
:run_before => false
|
||||
:run_before => false,
|
||||
:valid_extensions => DEFAULT_EXTENSIONS
|
||||
}.merge(options)
|
||||
end
|
||||
|
||||
@ -23,6 +26,7 @@ module Guard
|
||||
end
|
||||
|
||||
def run_on_change(paths)
|
||||
paths = filter_paths(paths)
|
||||
@ran_jammit = false
|
||||
if run_before and run_jammit
|
||||
@ran_jammit = true
|
||||
@ -35,6 +39,14 @@ module Guard
|
||||
end
|
||||
|
||||
private
|
||||
def filter_paths(paths)
|
||||
paths.find_all { |path| File.extname(path)[valid_extensions] }
|
||||
end
|
||||
|
||||
def valid_extensions
|
||||
%r{\.(#{@options[:valid_extensions].join('|')})$}
|
||||
end
|
||||
|
||||
def run_before
|
||||
if @options[:run_before]
|
||||
run_program(@options[:run_before])
|
||||
@ -61,6 +73,7 @@ module Guard
|
||||
|
||||
class Dsl
|
||||
def newest_js_file(path)
|
||||
p binding
|
||||
Dir[path + '*.{js,coffee}'].sort { |left, right| File.mtime(right) <=> File.mtime(left) }.first
|
||||
end
|
||||
end
|
||||
|
@ -32,7 +32,7 @@ describe Guard::JasmineHeadlessWebkit do
|
||||
Guard::JasmineHeadlessWebkitRunner.expects(:run).returns(1)
|
||||
guard.expects(:run_all).never
|
||||
|
||||
guard.run_on_change(%w{test})
|
||||
guard.run_on_change(%w{test.js})
|
||||
end
|
||||
end
|
||||
|
||||
@ -41,7 +41,7 @@ describe Guard::JasmineHeadlessWebkit do
|
||||
Guard::JasmineHeadlessWebkitRunner.expects(:run).returns(0)
|
||||
guard.expects(:run_all).once
|
||||
|
||||
guard.run_on_change(%w{test})
|
||||
guard.run_on_change(%w{test.js})
|
||||
end
|
||||
end
|
||||
|
||||
@ -53,6 +53,15 @@ describe Guard::JasmineHeadlessWebkit do
|
||||
guard.run_on_change([])
|
||||
end
|
||||
end
|
||||
|
||||
context "Files I don't care about given, ignore" do
|
||||
it 'should run all but not run once' do
|
||||
Guard::JasmineHeadlessWebkitRunner.expects(:run).never
|
||||
guard.expects(:run_all).once
|
||||
|
||||
guard.run_on_change(%w{test.jst})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'with run_before' do
|
||||
@ -106,7 +115,7 @@ describe Guard::JasmineHeadlessWebkit do
|
||||
let(:options) { { :jammit => true } }
|
||||
|
||||
it "should run jammit only once" do
|
||||
guard.run_on_change(%w{path.txt})
|
||||
guard.run_on_change(%w{path.js})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user