Permalink
Browse files

Move watch dir logic to the listener and ensure it's present (Fixes #195

)
  • Loading branch information...
1 parent 6f17487 commit 9cb0fddbbf96cd35a1275d5532f818d1b2555c94 @netzpirat netzpirat committed Dec 19, 2011
Showing with 30 additions and 7 deletions.
  1. +1 −1 lib/guard.rb
  2. +7 −2 lib/guard/listener.rb
  3. +22 −4 spec/guard/listener_spec.rb
View
2 lib/guard.rb
@@ -63,7 +63,7 @@ def setup(options = {})
@guards = []
self.reset_groups
@interactor = Interactor.new unless options[:no_interactions]
- @listener = Listener.select_and_init(options[:watchdir] && File.expand_path(options[:watchdir]), options)
+ @listener = Listener.select_and_init(options)
UI.clear if @options[:clear]
debug_command_execution if @options[:verbose]
View
9 lib/guard/listener.rb
@@ -28,11 +28,16 @@ def paused?
# Select the appropriate listener implementation for the
# current OS and initializes it.
#
- # @param [Array] args the arguments for the listener
+ # @param [Hash] options the options for the listener
+ # @option options [String] watchdir the directory to watch
# @return [Guard::Listener] the chosen listener
#
- def self.select_and_init(watchdir = Dir.pwd, options = nil)
+ def self.select_and_init(options = nil)
+ watchdir = options && options.key?(:watchdir) && File.expand_path(options[:watchdir])
+ watchdir = Dir.pwd unless watchdir
+
no_vendor = options && options.key?(:no_vendor) ? options[:no_vendor] : false
+
if mac? && Darwin.usable?(no_vendor)
Darwin.new(watchdir, options)
elsif linux? && Linux.usable?(no_vendor)
View
26 spec/guard/listener_spec.rb
@@ -27,13 +27,31 @@
described_class.select_and_init
end
- it 'forwards its arguments to the constructor' do
+ it 'forwards its options to the constructor' do
described_class.stub!(:mac?).and_return(true)
Guard::Darwin.stub!(:usable?).and_return(true)
- path, opts = 'path', { :foo => 23 }
- Guard::Darwin.should_receive(:new).with(path, opts).and_return(true)
- described_class.select_and_init(path, opts)
+ opts = { :foo => 23 }
+ Guard::Darwin.should_receive(:new).with(anything(), opts).and_return(true)
+ described_class.select_and_init(opts)
+ end
+
+ context 'with an explicit watch directory' do
+ it 'uses the given working directory' do
+ RbConfig::CONFIG['target_os'] = 'darwin10.4.0'
+ Guard::Darwin.stub(:usable?).and_return(true)
+ Guard::Darwin.should_receive(:new).with('/Users/mrx/projects/secret', { :watchdir => '/Users/mrx/projects/secret' })
+ described_class.select_and_init({ :watchdir => '/Users/mrx/projects/secret' })
+ end
+ end
+
+ context 'without an explicit watch directory' do
+ it 'uses the current working directory' do
+ RbConfig::CONFIG['target_os'] = 'darwin10.4.0'
+ Guard::Darwin.stub(:usable?).and_return(true)
+ Guard::Darwin.should_receive(:new).with(Dir.pwd, nil)
+ described_class.select_and_init
+ end
end
end

0 comments on commit 9cb0fdd

Please sign in to comment.