restrict capacity to run_at_start to reload and run_all actions

This commit is contained in:
Yann Lugrin 2010-11-04 14:10:58 +01:00
parent c52139b396
commit 56d4914ce1
2 changed files with 20 additions and 15 deletions

View File

@ -41,8 +41,8 @@ module Guard
UI.info "Guard is now watching at '#{Dir.pwd}'"
guards.each do |guard|
if supervised_task(guard, :start)
(guard.class.instance_methods(false) | ::Guard::Guard.instance_methods(false)).each do |m|
guard.send(:"#{$1}") if m.to_s =~ /^(.+)_at_start\?$/ && guard.send(:"#{$1}_at_start?")
%w[reload run_all].each do |m|
guard.send(m) if guard.respond_to?(:"#{m}_at_start?") && guard.send(:"#{m}_at_start?")
end
end
end

View File

@ -61,6 +61,7 @@ describe Guard do
@guard = mock(::Guard::Guard)
@guard.stub!(:reload_at_start?).and_return(false)
@guard.stub!(:run_all_at_start?).and_return(false)
@guard.stub!(:respond_to?)
@listener = mock(::Guard::Polling)
@listener.stub!(:on_change)
@ -93,27 +94,31 @@ describe Guard do
subject.start
end
it 'should call method definined to run at start' do
@guard.class.stub(:instance_methods).with(false).and_return([:test, :test_at_start?])
@guard.should_receive(:run_all_at_start?).and_return(true)
@guard.should_receive(:run_all).and_return(true)
@guard.should_receive(:test_at_start?).and_return(true)
@guard.should_receive(:test).and_return(true)
it 'should call reload at start if needed' do
@guard.should_receive(:respond_to?).with(:reload_at_start?).and_return(true)
@guard.should_receive(:reload_at_start?).and_return(true)
@guard.should_receive(:reload).and_return(true)
subject.start
end
it 'should not call method definined to not run at start' do
@guard.class.stub(:instance_methods).with(false).and_return([:test, :test_at_start?])
it 'should call run_all at start if needed' do
@guard.should_receive(:respond_to?).with(:run_all_at_start?).and_return(true)
@guard.should_receive(:run_all_at_start?).and_return(true)
@guard.should_receive(:run_all).and_return(true)
subject.start
end
it 'should not call reload and run_all at start if not needed' do
@guard.should_receive(:respond_to?).with(:reload_at_start?).and_return(true)
@guard.should_receive(:reload_at_start?).and_return(false)
@guard.should_not_receive(:reload)
@guard.should_receive(:respond_to?).with(:run_all_at_start?).and_return(true)
@guard.should_receive(:run_all_at_start?).and_return(false)
@guard.should_not_receive(:run_all)
@guard.should_receive(:test_at_start?).and_return(false)
@guard.should_not_receive(:test)
subject.start
end