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 'mocha'
|
||||
gem 'rake', '0.8.7'
|
||||
gem 'growl'
|
||||
|
|
|
@ -14,7 +14,10 @@ home folder's `.jasmine-headless-webkit` file.
|
|||
|
||||
## `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`?
|
||||
|
||||
|
|
|
@ -7,7 +7,8 @@ module Guard
|
|||
def initialize(watchers = [], options = {})
|
||||
super
|
||||
@options = {
|
||||
:all_on_start => true
|
||||
:all_on_start => true,
|
||||
:run_before => false
|
||||
}.merge(options)
|
||||
end
|
||||
|
||||
|
@ -17,14 +18,27 @@ module Guard
|
|||
end
|
||||
|
||||
def run_all
|
||||
JasmineHeadlessWebkitRunner.run
|
||||
JasmineHeadlessWebkitRunner.run if run_before
|
||||
end
|
||||
|
||||
def run_on_change(paths)
|
||||
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
|
||||
|
||||
class Dsl
|
||||
def newest_js_file(path)
|
||||
Dir[path + '*.{js,coffee}'].sort { |left, right| File.mtime(right) <=> File.mtime(left) }.first
|
||||
|
|
|
@ -45,4 +45,30 @@ describe Guard::JasmineHeadlessWebkit do
|
|||
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
|
||||
|
|
Loading…
Reference in New Issue