run a command before running specs, useful for compiling javascript templates

This commit is contained in:
John Bintz 2011-05-29 08:53:33 -04:00
parent 97ec0a7c47
commit 4b79c1c11d
4 changed files with 49 additions and 5 deletions

View File

@ -6,3 +6,4 @@ gem 'guard'
gem 'rspec' gem 'rspec'
gem 'mocha' gem 'mocha'
gem 'rake', '0.8.7' gem 'rake', '0.8.7'
gem 'growl'

View File

@ -14,7 +14,10 @@ home folder's `.jasmine-headless-webkit` file.
## `guard` options ## `guard` options
* `:all_on_start => false` to not run everything when starting, just like `guard-rspec` * `:all_on_start => false` to not run everything when starting, just like `guard-rspec`.
* `:run_before => "<command to run>` to run a command before running specs. If the command fails, the test run stops. Useful for running Jammit before running your specs to compile templates:
`guard 'jasmine-headliness-webkit', :run_before => 'jammit -f 2>/dev/null' do`
## What's the deal with `newest_js_file`? ## What's the deal with `newest_js_file`?

View File

@ -7,21 +7,35 @@ module Guard
def initialize(watchers = [], options = {}) def initialize(watchers = [], options = {})
super super
@options = { @options = {
:all_on_start => true :all_on_start => true,
:run_before => false
}.merge(options) }.merge(options)
end end
def start def start
UI.info "Guard::JasmineHeadlessWebkit is running." UI.info "Guard::JasmineHeadlessWebkit is running."
run_all if @options[:all_on_start] run_all if @options[:all_on_start]
end end
def run_all def run_all
JasmineHeadlessWebkitRunner.run JasmineHeadlessWebkitRunner.run if run_before
end end
def run_on_change(paths) def run_on_change(paths)
run_all if JasmineHeadlessWebkitRunner.run(paths) == 0 if run_before
run_all if JasmineHeadlessWebkitRunner.run(paths) == 0
end
end
private
def run_before
if @options[:run_before]
UI.info "Guard::JasmineHeadlessWebkit running #{@options[:run_before]} first..."
system @options[:run_before]
$?.exitstatus == 0
else
true
end
end end
end end

View File

@ -45,4 +45,30 @@ describe Guard::JasmineHeadlessWebkit do
end end
end end
end end
context 'with run_before' do
context 'with failing command' do
before do
Guard::JasmineHeadlessWebkitRunner.expects(:run).never
end
let(:options) { { :run_before => 'false' } }
it "should run the command first" do
guard.run_all
end
end
context 'with succeeding command' do
before do
Guard::JasmineHeadlessWebkitRunner.expects(:run).once
end
let(:options) { { :run_before => 'true' } }
it "should run the command first" do
guard.run_all
end
end
end
end end