2011-05-24 01:28:01 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
require 'guard/jasmine-headless-webkit'
|
|
|
|
|
|
|
|
describe Guard::JasmineHeadlessWebkit do
|
|
|
|
let(:guard) { Guard::JasmineHeadlessWebkit.new([], options) }
|
|
|
|
|
|
|
|
let(:options) { {} }
|
|
|
|
|
|
|
|
describe "#start" do
|
|
|
|
context 'no all on start' do
|
|
|
|
let(:options) { { :all_on_start => false } }
|
|
|
|
|
|
|
|
it "should not run all" do
|
|
|
|
guard.expects(:run_all).never
|
|
|
|
guard.start
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'all on start' do
|
|
|
|
let(:options) { { :all_on_start => true } }
|
|
|
|
|
|
|
|
it "should not run all" do
|
|
|
|
guard.expects(:run_all).once
|
|
|
|
guard.start
|
|
|
|
end
|
|
|
|
end
|
2011-09-07 13:53:33 +00:00
|
|
|
|
|
|
|
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
|
2011-09-14 14:06:55 +00:00
|
|
|
|
|
|
|
context 'pass along jhw options' do
|
|
|
|
let(:options) { { :all_on_start => false, :full_run => false } }
|
|
|
|
|
|
|
|
it 'should only pass along jhw options' do
|
|
|
|
Guard::JasmineHeadlessWebkitRunner.expects(:run).with([], :full_run => false)
|
|
|
|
|
|
|
|
guard.run_all
|
|
|
|
end
|
|
|
|
end
|
2011-05-24 01:28:01 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '#run_on_change' do
|
2011-09-06 20:00:27 +00:00
|
|
|
let(:one_file) { %w{test.js} }
|
|
|
|
|
2011-08-05 17:35:06 +00:00
|
|
|
context 'two files' do
|
|
|
|
it "should only run one" do
|
2011-09-14 14:06:55 +00:00
|
|
|
Guard::JasmineHeadlessWebkitRunner.expects(:run).with(one_file, {}).returns(one_file)
|
2011-08-05 17:35:06 +00:00
|
|
|
|
2011-09-07 13:53:33 +00:00
|
|
|
guard.run_on_change(%w{test.js test.js}).should be_false
|
2011-09-06 20:00:27 +00:00
|
|
|
guard.files_to_rerun.should == one_file
|
2011-08-05 17:35:06 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-09-06 20:00:27 +00:00
|
|
|
context 'one file no priors' do
|
2011-05-24 01:28:01 +00:00
|
|
|
it "should not run all" do
|
2011-09-06 20:00:27 +00:00
|
|
|
Guard::JasmineHeadlessWebkitRunner.expects(:run).returns(one_file)
|
|
|
|
|
2011-09-07 13:53:33 +00:00
|
|
|
guard.run_on_change(one_file).should be_false
|
2011-09-06 20:00:27 +00:00
|
|
|
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" ])
|
2011-09-14 14:06:55 +00:00
|
|
|
Guard::JasmineHeadlessWebkitRunner.expects(:run).with(one_file + [ "two.js" ], {}).returns(one_file)
|
2011-09-06 20:00:27 +00:00
|
|
|
|
2011-09-07 13:53:33 +00:00
|
|
|
guard.run_on_change(one_file).should be_false
|
2011-09-06 20:00:27 +00:00
|
|
|
guard.files_to_rerun.should == one_file
|
|
|
|
end
|
|
|
|
end
|
2011-05-24 01:28:01 +00:00
|
|
|
|
2011-09-06 20:00:27 +00:00
|
|
|
context 'failed hard' do
|
|
|
|
it "should not run all" do
|
|
|
|
guard.instance_variable_set(:@files_to_rerun, one_file)
|
2011-09-14 14:06:55 +00:00
|
|
|
Guard::JasmineHeadlessWebkitRunner.expects(:run).with(one_file, {}).returns(nil)
|
2011-09-06 20:00:27 +00:00
|
|
|
|
2011-09-07 13:53:33 +00:00
|
|
|
guard.run_on_change(one_file).should be_false
|
2011-09-06 20:00:27 +00:00
|
|
|
guard.files_to_rerun.should == one_file
|
2011-05-24 01:28:01 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-06-10 15:33:27 +00:00
|
|
|
context 'succeed, but still do not run all' do
|
2011-05-24 01:28:01 +00:00
|
|
|
it "should run all" do
|
2011-09-06 20:00:27 +00:00
|
|
|
Guard::JasmineHeadlessWebkitRunner.expects(:run).returns([])
|
2011-05-24 01:28:01 +00:00
|
|
|
|
2011-09-07 13:53:33 +00:00
|
|
|
guard.run_on_change(one_file).should be_true
|
2011-09-06 20:00:27 +00:00
|
|
|
guard.files_to_rerun.should == []
|
2011-05-24 01:28:01 +00:00
|
|
|
end
|
|
|
|
end
|
2011-06-03 20:25:00 +00:00
|
|
|
|
|
|
|
context 'no files given, just run all' do
|
|
|
|
it 'should run all but not run once' do
|
|
|
|
Guard::JasmineHeadlessWebkitRunner.expects(:run).never
|
2011-09-07 13:53:33 +00:00
|
|
|
guard.expects(:run_all).once.returns(true)
|
2011-06-03 20:25:00 +00:00
|
|
|
|
2011-09-07 13:53:33 +00:00
|
|
|
guard.run_on_change([]).should be_true
|
2011-09-06 20:00:27 +00:00
|
|
|
guard.files_to_rerun.should == []
|
2011-06-03 20:25:00 +00:00
|
|
|
end
|
|
|
|
end
|
2011-06-03 20:45:19 +00:00
|
|
|
|
|
|
|
context "Files I don't care about given, ignore" do
|
|
|
|
it 'should run all but not run once' do
|
|
|
|
Guard::JasmineHeadlessWebkitRunner.expects(:run).never
|
|
|
|
guard.expects(:run_all).once
|
|
|
|
|
|
|
|
guard.run_on_change(%w{test.jst})
|
2011-09-06 20:00:27 +00:00
|
|
|
guard.files_to_rerun.should == []
|
2011-06-03 20:45:19 +00:00
|
|
|
end
|
|
|
|
end
|
2011-05-24 01:28:01 +00:00
|
|
|
end
|
2011-05-29 12:53:33 +00:00
|
|
|
|
|
|
|
context 'with run_before' do
|
|
|
|
context 'with failing command' do
|
|
|
|
before do
|
|
|
|
Guard::JasmineHeadlessWebkitRunner.expects(:run).never
|
2011-06-01 21:14:23 +00:00
|
|
|
Guard::UI.expects(:info).with(regexp_matches(/false/))
|
2011-05-29 12:53:33 +00:00
|
|
|
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
|
2011-06-01 21:14:23 +00:00
|
|
|
Guard::UI.expects(:info).with(regexp_matches(/true/))
|
2011-06-10 15:50:25 +00:00
|
|
|
Guard::UI.expects(:info).with(regexp_matches(/running all/))
|
2011-05-29 12:53:33 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
let(:options) { { :run_before => 'true' } }
|
|
|
|
|
|
|
|
it "should run the command first" do
|
|
|
|
guard.run_all
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2011-09-06 20:00:27 +00:00
|
|
|
|
|
|
|
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
|
2011-05-24 01:28:01 +00:00
|
|
|
end
|