Skip to content

Commit

Permalink
always re-run failed specs, clear those out with ctrl-z
Browse files Browse the repository at this point in the history
  • Loading branch information
johnbintz committed Sep 6, 2011
1 parent 5baaf8f commit 570ea08
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 17 deletions.
14 changes: 13 additions & 1 deletion lib/guard/jasmine-headless-webkit.rb
Expand Up @@ -7,20 +7,29 @@ module Guard
class JasmineHeadlessWebkit < Guard
DEFAULT_EXTENSIONS = %w{js coffee}

attr_reader :files_to_rerun

def initialize(watchers = [], options = {})
super
@options = {
:all_on_start => true,
:run_before => false,
:valid_extensions => DEFAULT_EXTENSIONS
}.merge(options)

@files_to_rerun = []
end

def start
UI.info "Guard::JasmineHeadlessWebkit is running."
run_all if @options[:all_on_start]
end

def reload
@files_to_rerun = []
UI.info "Resetting Guard::JasmineHeadlessWebkit failed files..."
end

def run_all
run_something_and_rescue do
UI.info "Guard::JasmineHeadlessWebkit running all specs..."
Expand All @@ -36,8 +45,11 @@ def run_on_change(paths)
if run_all_things_before
@ran_before = true
if !paths.empty?
paths = (paths + @files_to_rerun).uniq
UI.info "Guard::JasmineHeadlessWebkit running the following: #{paths.join(' ')}"
JasmineHeadlessWebkitRunner.run(paths)
if failed_files = JasmineHeadlessWebkitRunner.run(paths)
@files_to_rerun = failed_files
end
else
run_all
end
Expand Down
8 changes: 5 additions & 3 deletions lib/guard/jasmine-headless-webkit/runner.rb
Expand Up @@ -16,12 +16,14 @@ def run(paths = [])
def notify(file)
if (report = Jasmine::Headless::Report.load(file)).valid?
Notifier.notify(message(report.total, report.failed, report.time, report.has_used_console?), :title => 'Jasmine results', :image => image(report.has_used_console?, report.failed))
report.failed
report.failed_files
else
raise StandardError.new("invalid report")
raise Jasmine::Headless::InvalidReport.new
end
rescue Exception => e
rescue Jasmine::Headless::InvalidReport => e
Notifier.notify('Spec runner interrupted!', :title => 'Jasmine results', :image => :failed)
rescue Exception => e
p e
end

private
Expand Down
11 changes: 7 additions & 4 deletions spec/lib/guard/jasmine-headless-webkit/runner_spec.rb
Expand Up @@ -18,17 +18,20 @@
it 'should notify with the right information' do
Guard::Notifier.expects(:notify).with("1 test, 0 failures, 5.0 secs.", { :title => 'Jasmine results', :image => :success })

Guard::JasmineHeadlessWebkitRunner.notify(file)
Guard::JasmineHeadlessWebkitRunner.notify(file).should == []
end
end

context 'with failures' do
let(:data) { "TOTAL||1||1||5||F" }
let(:data) { <<-REPORT }
FAIL||Test||Two||file.js:50
TOTAL||1||1||5||F
REPORT

it 'should notify with the right information' do
Guard::Notifier.expects(:notify).with("1 test, 1 failures, 5.0 secs.", { :title => 'Jasmine results', :image => :failed })

Guard::JasmineHeadlessWebkitRunner.notify(file)
Guard::JasmineHeadlessWebkitRunner.notify(file).should == [ 'file.js' ]
end
end

Expand All @@ -38,7 +41,7 @@
it 'should notify failure' do
Guard::Notifier.expects(:notify).with("Spec runner interrupted!", { :title => 'Jasmine results', :image => :failed })

Guard::JasmineHeadlessWebkitRunner.notify(file)
Guard::JasmineHeadlessWebkitRunner.notify(file).should be_nil
end
end
end
Expand Down
52 changes: 43 additions & 9 deletions spec/lib/guard/jasmine-headless-webkit_spec.rb
Expand Up @@ -27,30 +27,52 @@
end

describe '#run_on_change' do
let(:one_file) { %w{test.js} }

context 'two files' do
it "should only run one" do
Guard::JasmineHeadlessWebkitRunner.expects(:run).with(%w{test.js}).returns(1)
guard.expects(:run_all).never
Guard::JasmineHeadlessWebkitRunner.expects(:run).with(one_file).returns(one_file)

guard.run_on_change(%w{test.js test.js})
guard.files_to_rerun.should == one_file
end
end

context 'jhw call fails' do
context 'one file no priors' do
it "should not run all" do
Guard::JasmineHeadlessWebkitRunner.expects(:run).returns(1)
guard.expects(:run_all).never
Guard::JasmineHeadlessWebkitRunner.expects(:run).returns(one_file)

guard.run_on_change(one_file)
guard.files_to_rerun.should == one_file
end
end

context 'one file one prior' do
it "should not run all" 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.files_to_rerun.should == one_file
end
end

guard.run_on_change(%w{test.js})
context 'failed hard' do
it "should not run all" 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.files_to_rerun.should == one_file
end
end

context 'succeed, but still do not run all' do
it "should run all" do
Guard::JasmineHeadlessWebkitRunner.expects(:run).returns(0)
guard.expects(:run_all).never
Guard::JasmineHeadlessWebkitRunner.expects(:run).returns([])

guard.run_on_change(%w{test.js})
guard.run_on_change(one_file)
guard.files_to_rerun.should == []
end
end

Expand All @@ -60,6 +82,7 @@
guard.expects(:run_all).once

guard.run_on_change([])
guard.files_to_rerun.should == []
end
end

Expand All @@ -69,6 +92,7 @@
guard.expects(:run_all).once

guard.run_on_change(%w{test.jst})
guard.files_to_rerun.should == []
end
end
end
Expand Down Expand Up @@ -102,4 +126,14 @@
end
end
end

describe '#reload' do
it 'should reset the state of the files_to_rerun' do
Guard::UI.expects(:info).with(regexp_matches(/Resetting/))

guard.instance_variable_set(:@files_to_rerun, "test")
guard.reload
guard.files_to_rerun.should == []
end
end
end

0 comments on commit 570ea08

Please sign in to comment.