some cleanups of running specs, ensure correct return values for serial guard execution

This commit is contained in:
John Bintz 2011-09-07 09:53:33 -04:00
parent 570ea0814e
commit 3ed72300d3
4 changed files with 75 additions and 18 deletions

View File

@ -15,9 +15,11 @@ home folder's `.jasmine-headless-webkit` file.
## `guard` options
* `: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.
### 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
Use [`guard-rails-assets`](https://github.com/dnagir/guard-rails-assets) chained in before `guard-jasmine-headless-webkit` to precompile your application

View File

@ -7,6 +7,9 @@ module Guard
class JasmineHeadlessWebkit < Guard
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
def initialize(watchers = [], options = {})
@ -17,6 +20,8 @@ module Guard
:valid_extensions => DEFAULT_EXTENSIONS
}.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 = []
end
@ -32,9 +37,9 @@ module Guard
def run_all
run_something_and_rescue do
UI.info "Guard::JasmineHeadlessWebkit running all specs..."
JasmineHeadlessWebkitRunner.run if run_all_things_before
@ran_before = false
run_for_failed_files if run_all_things_before
end
end
@ -46,10 +51,8 @@ module Guard
@ran_before = true
if !paths.empty?
paths = (paths + @files_to_rerun).uniq
UI.info "Guard::JasmineHeadlessWebkit running the following: #{paths.join(' ')}"
if failed_files = JasmineHeadlessWebkitRunner.run(paths)
@files_to_rerun = failed_files
end
run_for_failed_files(paths)
else
run_all
end
@ -58,6 +61,20 @@ module Guard
end
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)
paths.find_all { |path| File.extname(path)[valid_extensions] }.uniq
end
@ -93,11 +110,15 @@ module Guard
yield
rescue ::CoffeeScript::CompilationError
rescue StandardError => e
if ENV['GUARD_ENV'] == 'test'
raise e
else
puts e.message
puts e.backtrace.join("\n")
puts
end
end
end
class Dsl
def newest_js_file(path)

View File

@ -24,6 +24,39 @@ describe Guard::JasmineHeadlessWebkit do
guard.start
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
describe '#run_on_change' do
@ -33,7 +66,7 @@ describe Guard::JasmineHeadlessWebkit do
it "should only run one" do
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
end
end
@ -42,7 +75,7 @@ describe Guard::JasmineHeadlessWebkit do
it "should not run all" do
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
end
end
@ -52,7 +85,7 @@ describe Guard::JasmineHeadlessWebkit do
guard.instance_variable_set(:@files_to_rerun, [ "two.js" ])
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
end
end
@ -62,7 +95,7 @@ describe Guard::JasmineHeadlessWebkit do
guard.instance_variable_set(:@files_to_rerun, one_file)
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
end
end
@ -71,7 +104,7 @@ describe Guard::JasmineHeadlessWebkit do
it "should run all" do
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 == []
end
end
@ -79,9 +112,9 @@ describe Guard::JasmineHeadlessWebkit do
context 'no files given, just run all' do
it 'should run all but not run once' do
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 == []
end
end
@ -102,7 +135,6 @@ describe Guard::JasmineHeadlessWebkit do
before do
Guard::JasmineHeadlessWebkitRunner.expects(:run).never
Guard::UI.expects(:info).with(regexp_matches(/false/))
Guard::UI.expects(:info).with(regexp_matches(/running all/))
end
let(:options) { { :run_before => 'false' } }

View File

@ -5,6 +5,8 @@ RSpec.configure do |config|
config.mock_with :mocha
end
ENV['GUARD_ENV'] = 'test'
module Guard
module UI
class << self