Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

restrict capacity to run_at_start to reload and run_all actions

  • Loading branch information...
commit 56d4914ce1ff9756ea44485c3754d56439a74fcf 1 parent c52139b
@yannlugrin yannlugrin authored
Showing with 17 additions and 12 deletions.
  1. +2 −2 lib/guard.rb
  2. +15 −10 spec/guard_spec.rb
View
4 lib/guard.rb
@@ -41,8 +41,8 @@ def start(options = {})
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
25 spec/guard_spec.rb
@@ -61,6 +61,7 @@ def debug(message)
@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 @@ def debug(message)
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?])
+ 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 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)
- @guard.should_receive(:test_at_start?).and_return(true)
- @guard.should_receive(:test).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 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
Please sign in to comment.
Something went wrong with that request. Please try again.