support for jhw's duck-punch-sprockets branch, run rails asset compilation before running jhw

This commit is contained in:
John Bintz 2011-06-12 13:44:10 -04:00
parent f093cdb813
commit 12d5d19b72
2 changed files with 46 additions and 14 deletions

View File

@ -22,15 +22,15 @@ module Guard
def run_all def run_all
UI.info "Guard::JasmineHeadlessWebkit running all specs..." UI.info "Guard::JasmineHeadlessWebkit running all specs..."
JasmineHeadlessWebkitRunner.run if run_before and run_jammit JasmineHeadlessWebkitRunner.run if run_before and run_rails_assets and run_jammit
@ran_jammit = false @ran_before = false
end end
def run_on_change(paths) def run_on_change(paths)
paths = filter_paths(paths) paths = filter_paths(paths)
@ran_jammit = false @ran_before = false
if run_before and run_jammit if run_before and run_rails_assets and run_jammit
@ran_jammit = true @ran_before = true
if !paths.empty? if !paths.empty?
UI.info "Guard::JasmineHeadlessWebkit running the following: #{paths.join(' ')}" UI.info "Guard::JasmineHeadlessWebkit running the following: #{paths.join(' ')}"
JasmineHeadlessWebkitRunner.run(paths) JasmineHeadlessWebkitRunner.run(paths)
@ -50,16 +50,20 @@ module Guard
end end
def run_before def run_before
if @options[:run_before] run_a_thing_before(:run_before, @options[:run_before])
run_program(@options[:run_before])
else
true
end
end end
def run_jammit def run_jammit
if @options[:jammit] && !@ran_jammit run_a_thing_before(:jammit, "Jammit", %{jammit -f 2>/dev/null})
run_program("Jammit", %{jammit -f 2>/dev/null}) end
def run_rails_assets
run_a_thing_before(:rails_assets, "Rails Assets", %{rake assets:precompile:for_testing})
end
def run_a_thing_before(option, *args)
if @options[option] && !@ran_before
run_program(*args)
else else
true true
end end

View File

@ -97,7 +97,7 @@ describe Guard::JasmineHeadlessWebkit do
describe 'run jammit first' do describe 'run jammit first' do
context 'run on run_all if called first' do context 'run on run_all if called first' do
before do before do
guard.expects(:run_program).once.returns(true) guard.expects(:run_program).once.with('Jammit', regexp_matches(/jammit/)).returns(true)
Guard::JasmineHeadlessWebkitRunner.expects(:run).once Guard::JasmineHeadlessWebkitRunner.expects(:run).once
end end
@ -110,7 +110,7 @@ describe Guard::JasmineHeadlessWebkit do
context 'only run once if run_on_change is successful' do context 'only run once if run_on_change is successful' do
before do before do
guard.expects(:run_program).once.returns(true) guard.expects(:run_program).once.with('Jammit', regexp_matches(/jammit/)).returns(true)
Guard::JasmineHeadlessWebkitRunner.expects(:run).once.returns(0) Guard::JasmineHeadlessWebkitRunner.expects(:run).once.returns(0)
end end
@ -121,4 +121,32 @@ describe Guard::JasmineHeadlessWebkit do
end end
end end
end end
describe 'run rails_assets first' do
context 'run on run_all if called first' do
before do
guard.expects(:run_program).with('Rails Assets', regexp_matches(/assets:precompile:for_testing/)).once.returns(true)
Guard::JasmineHeadlessWebkitRunner.expects(:run).once
end
let(:options) { { :rails_assets => true } }
it "should run rails assets first" do
guard.run_all
end
end
context 'only run once if run_on_change is successful' do
before do
guard.expects(:run_program).with('Rails Assets', regexp_matches(/assets:precompile:for_testing/)).once.returns(true)
Guard::JasmineHeadlessWebkitRunner.expects(:run).once.returns(0)
end
let(:options) { { :rails_assets => true } }
it "should run rails assets only once" do
guard.run_on_change(%w{path.js})
end
end
end
end end