run a command before running specs, useful for compiling javascript templates
This commit is contained in:
parent
97ec0a7c47
commit
4b79c1c11d
1
Gemfile
1
Gemfile
@ -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'
|
||||||
|
@ -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`?
|
||||||
|
|
||||||
|
@ -7,7 +7,8 @@ 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
|
||||||
|
|
||||||
@ -17,11 +18,24 @@ module Guard
|
|||||||
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
|
||||||
|
|
||||||
|
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user