some cleanups of running specs, ensure correct return values for serial guard execution
This commit is contained in:
parent
570ea0814e
commit
3ed72300d3
@ -15,9 +15,11 @@ 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.
|
|
||||||
* `:valid_extensions => %w{js coffee}` to only trigger `run_on_change` events for files with these extensions. Forces Guard to re-run all tests when any other matched file changes.
|
* `:valid_extensions => %w{js coffee}` to only trigger `run_on_change` events for files with these extensions. Forces Guard to re-run all tests when any other matched file changes.
|
||||||
|
|
||||||
|
### Deprecated options
|
||||||
|
* `:run_before => "<command to run>"` to run a command before running specs. If the command fails, the test run stops.
|
||||||
|
|
||||||
## Using with Rails 3.1 and the Asset Pipeline and/or Jammit
|
## Using with Rails 3.1 and the Asset Pipeline and/or Jammit
|
||||||
|
|
||||||
Use [`guard-rails-assets`](https://github.com/dnagir/guard-rails-assets) chained in before `guard-jasmine-headless-webkit` to precompile your application
|
Use [`guard-rails-assets`](https://github.com/dnagir/guard-rails-assets) chained in before `guard-jasmine-headless-webkit` to precompile your application
|
||||||
|
@ -7,6 +7,9 @@ module Guard
|
|||||||
class JasmineHeadlessWebkit < Guard
|
class JasmineHeadlessWebkit < Guard
|
||||||
DEFAULT_EXTENSIONS = %w{js coffee}
|
DEFAULT_EXTENSIONS = %w{js coffee}
|
||||||
|
|
||||||
|
ALL_SPECS_MESSAGE = "Guard::JasmineHeadlessWebkit running all specs..."
|
||||||
|
SOME_SPECS_MESSAGE = "Guard::JasmineHeadlessWebkit running the following: %s"
|
||||||
|
|
||||||
attr_reader :files_to_rerun
|
attr_reader :files_to_rerun
|
||||||
|
|
||||||
def initialize(watchers = [], options = {})
|
def initialize(watchers = [], options = {})
|
||||||
@ -17,6 +20,8 @@ module Guard
|
|||||||
:valid_extensions => DEFAULT_EXTENSIONS
|
:valid_extensions => DEFAULT_EXTENSIONS
|
||||||
}.merge(options)
|
}.merge(options)
|
||||||
|
|
||||||
|
UI.deprecation ":run_before is deprecated. Use guard-shell to do something beforehand. This will be removed in a future release." if @options[:run_before]
|
||||||
|
|
||||||
@files_to_rerun = []
|
@files_to_rerun = []
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -32,9 +37,9 @@ module Guard
|
|||||||
|
|
||||||
def run_all
|
def run_all
|
||||||
run_something_and_rescue do
|
run_something_and_rescue do
|
||||||
UI.info "Guard::JasmineHeadlessWebkit running all specs..."
|
|
||||||
JasmineHeadlessWebkitRunner.run if run_all_things_before
|
|
||||||
@ran_before = false
|
@ran_before = false
|
||||||
|
|
||||||
|
run_for_failed_files if run_all_things_before
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -46,10 +51,8 @@ module Guard
|
|||||||
@ran_before = true
|
@ran_before = true
|
||||||
if !paths.empty?
|
if !paths.empty?
|
||||||
paths = (paths + @files_to_rerun).uniq
|
paths = (paths + @files_to_rerun).uniq
|
||||||
UI.info "Guard::JasmineHeadlessWebkit running the following: #{paths.join(' ')}"
|
|
||||||
if failed_files = JasmineHeadlessWebkitRunner.run(paths)
|
run_for_failed_files(paths)
|
||||||
@files_to_rerun = failed_files
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
run_all
|
run_all
|
||||||
end
|
end
|
||||||
@ -58,6 +61,20 @@ module Guard
|
|||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
def run_for_failed_files(paths = [])
|
||||||
|
if paths.empty?
|
||||||
|
UI.info(ALL_SPECS_MESSAGE)
|
||||||
|
else
|
||||||
|
UI.info(SOME_SPECS_MESSAGE % paths.join(' '))
|
||||||
|
end
|
||||||
|
|
||||||
|
if failed_files = JasmineHeadlessWebkitRunner.run(paths)
|
||||||
|
@files_to_rerun = failed_files
|
||||||
|
end
|
||||||
|
|
||||||
|
failed_files && failed_files.empty?
|
||||||
|
end
|
||||||
|
|
||||||
def filter_paths(paths)
|
def filter_paths(paths)
|
||||||
paths.find_all { |path| File.extname(path)[valid_extensions] }.uniq
|
paths.find_all { |path| File.extname(path)[valid_extensions] }.uniq
|
||||||
end
|
end
|
||||||
@ -93,9 +110,13 @@ module Guard
|
|||||||
yield
|
yield
|
||||||
rescue ::CoffeeScript::CompilationError
|
rescue ::CoffeeScript::CompilationError
|
||||||
rescue StandardError => e
|
rescue StandardError => e
|
||||||
puts e.message
|
if ENV['GUARD_ENV'] == 'test'
|
||||||
puts e.backtrace.join("\n")
|
raise e
|
||||||
puts
|
else
|
||||||
|
puts e.message
|
||||||
|
puts e.backtrace.join("\n")
|
||||||
|
puts
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -24,6 +24,39 @@ describe Guard::JasmineHeadlessWebkit do
|
|||||||
guard.start
|
guard.start
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'run_before' do
|
||||||
|
let(:options) { { :run_before => true, :all_on_start => false } }
|
||||||
|
|
||||||
|
it "should warn about deprecation" do
|
||||||
|
Guard::UI.expects(:deprecation).at_least_once
|
||||||
|
guard.start
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '#run_all' do
|
||||||
|
before do
|
||||||
|
guard.stubs(:run_all_things_before).returns(true)
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'fails' do
|
||||||
|
it 'should return false' do
|
||||||
|
Guard::JasmineHeadlessWebkitRunner.stubs(:run).returns(['file.js'])
|
||||||
|
|
||||||
|
guard.run_all.should be_false
|
||||||
|
guard.files_to_rerun.should == ['file.js']
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'succeeds' do
|
||||||
|
it 'should return true' do
|
||||||
|
Guard::JasmineHeadlessWebkitRunner.stubs(:run).returns([])
|
||||||
|
|
||||||
|
guard.run_all.should be_true
|
||||||
|
guard.files_to_rerun.should == []
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#run_on_change' do
|
describe '#run_on_change' do
|
||||||
@ -33,7 +66,7 @@ describe Guard::JasmineHeadlessWebkit do
|
|||||||
it "should only run one" do
|
it "should only run one" do
|
||||||
Guard::JasmineHeadlessWebkitRunner.expects(:run).with(one_file).returns(one_file)
|
Guard::JasmineHeadlessWebkitRunner.expects(:run).with(one_file).returns(one_file)
|
||||||
|
|
||||||
guard.run_on_change(%w{test.js test.js})
|
guard.run_on_change(%w{test.js test.js}).should be_false
|
||||||
guard.files_to_rerun.should == one_file
|
guard.files_to_rerun.should == one_file
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -42,7 +75,7 @@ describe Guard::JasmineHeadlessWebkit do
|
|||||||
it "should not run all" do
|
it "should not run all" do
|
||||||
Guard::JasmineHeadlessWebkitRunner.expects(:run).returns(one_file)
|
Guard::JasmineHeadlessWebkitRunner.expects(:run).returns(one_file)
|
||||||
|
|
||||||
guard.run_on_change(one_file)
|
guard.run_on_change(one_file).should be_false
|
||||||
guard.files_to_rerun.should == one_file
|
guard.files_to_rerun.should == one_file
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -52,7 +85,7 @@ describe Guard::JasmineHeadlessWebkit do
|
|||||||
guard.instance_variable_set(:@files_to_rerun, [ "two.js" ])
|
guard.instance_variable_set(:@files_to_rerun, [ "two.js" ])
|
||||||
Guard::JasmineHeadlessWebkitRunner.expects(:run).with(one_file + [ "two.js" ]).returns(one_file)
|
Guard::JasmineHeadlessWebkitRunner.expects(:run).with(one_file + [ "two.js" ]).returns(one_file)
|
||||||
|
|
||||||
guard.run_on_change(one_file)
|
guard.run_on_change(one_file).should be_false
|
||||||
guard.files_to_rerun.should == one_file
|
guard.files_to_rerun.should == one_file
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -62,7 +95,7 @@ describe Guard::JasmineHeadlessWebkit do
|
|||||||
guard.instance_variable_set(:@files_to_rerun, one_file)
|
guard.instance_variable_set(:@files_to_rerun, one_file)
|
||||||
Guard::JasmineHeadlessWebkitRunner.expects(:run).with(one_file).returns(nil)
|
Guard::JasmineHeadlessWebkitRunner.expects(:run).with(one_file).returns(nil)
|
||||||
|
|
||||||
guard.run_on_change(one_file)
|
guard.run_on_change(one_file).should be_false
|
||||||
guard.files_to_rerun.should == one_file
|
guard.files_to_rerun.should == one_file
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -71,7 +104,7 @@ describe Guard::JasmineHeadlessWebkit do
|
|||||||
it "should run all" do
|
it "should run all" do
|
||||||
Guard::JasmineHeadlessWebkitRunner.expects(:run).returns([])
|
Guard::JasmineHeadlessWebkitRunner.expects(:run).returns([])
|
||||||
|
|
||||||
guard.run_on_change(one_file)
|
guard.run_on_change(one_file).should be_true
|
||||||
guard.files_to_rerun.should == []
|
guard.files_to_rerun.should == []
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -79,9 +112,9 @@ describe Guard::JasmineHeadlessWebkit do
|
|||||||
context 'no files given, just run all' do
|
context 'no files given, just run all' do
|
||||||
it 'should run all but not run once' do
|
it 'should run all but not run once' do
|
||||||
Guard::JasmineHeadlessWebkitRunner.expects(:run).never
|
Guard::JasmineHeadlessWebkitRunner.expects(:run).never
|
||||||
guard.expects(:run_all).once
|
guard.expects(:run_all).once.returns(true)
|
||||||
|
|
||||||
guard.run_on_change([])
|
guard.run_on_change([]).should be_true
|
||||||
guard.files_to_rerun.should == []
|
guard.files_to_rerun.should == []
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -102,7 +135,6 @@ describe Guard::JasmineHeadlessWebkit do
|
|||||||
before do
|
before do
|
||||||
Guard::JasmineHeadlessWebkitRunner.expects(:run).never
|
Guard::JasmineHeadlessWebkitRunner.expects(:run).never
|
||||||
Guard::UI.expects(:info).with(regexp_matches(/false/))
|
Guard::UI.expects(:info).with(regexp_matches(/false/))
|
||||||
Guard::UI.expects(:info).with(regexp_matches(/running all/))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
let(:options) { { :run_before => 'false' } }
|
let(:options) { { :run_before => 'false' } }
|
||||||
|
@ -5,6 +5,8 @@ RSpec.configure do |config|
|
|||||||
config.mock_with :mocha
|
config.mock_with :mocha
|
||||||
end
|
end
|
||||||
|
|
||||||
|
ENV['GUARD_ENV'] = 'test'
|
||||||
|
|
||||||
module Guard
|
module Guard
|
||||||
module UI
|
module UI
|
||||||
class << self
|
class << self
|
||||||
|
Loading…
Reference in New Issue
Block a user