Permalink
Browse files

create verbose option

  • Loading branch information...
1 parent 846829c commit 9e61c2b0a2b531636f62f41e559116f1c70f253e @marcisme committed Jun 24, 2012
Showing with 61 additions and 6 deletions.
  1. +7 −6 README.md
  2. +2 −0 lib/guard/copy.rb
  3. +52 −0 spec/guard/copy_spec.rb
View
@@ -57,12 +57,13 @@ the directory specified by the `:from` option to that specified by the
### List of available options:
``` ruby
-:from => 'source' # directory to copy files from
-:to => 'target' # directory or glob to copy files to; can be an array
-:glob => :newest # how to handle globs; default: :all
- # :newest - copy to only the newest directory
- # :all - copy to all directories
-:delete => true # delete files from target directories
+:from => 'source' # directory to copy files from
+:to => 'target' # directory or glob to copy files to; can be an array
+:glob => :newest # how to handle globs; default: :all
+ # :newest - copy to only the newest directory
+ # :all - copy to all directories
+:delete => true # delete files from target directories
+:verbose => true # log all operations as info messages
```
## Watchers
View
@@ -55,6 +55,7 @@ def run_on_changes(paths)
validate_at_least_one_target('copy')
with_all_target_paths(paths) do |from_path, to_path|
validate_to_path(to_path)
+ UI.info("copying to #{to_path}") if options[:verbose]
FileUtils.cp(from_path, to_path)
end
end
@@ -67,6 +68,7 @@ def run_on_removals(paths)
validate_at_least_one_target('delete')
with_all_target_paths(paths) do |_, to_path|
validate_to_file(to_path)
+ UI.info("deleting #{to_path}") if options[:verbose]
FileUtils.rm(to_path)
end
end
View
@@ -198,6 +198,32 @@ module Guard
File.should be_file('t2/foo')
end
+ context 'when :verbose is false (or nil)' do
+ it 'does not log copy operation' do
+ file('source/foo')
+ dir('target')
+ guard = Copy.new([], :from => 'source', :to => 'target')
+ guard.start
+ UI.should_not_receive(:info)
+
+ guard.run_on_changes(['source/foo'])
+ end
+ end
+
+ context 'when :verbose is true' do
+ it 'logs copy operation' do
+ file('source/foo')
+ dir('t1')
+ dir('t2')
+ guard = Copy.new([], :from => 'source', :to => ['t1', 't2'], :verbose => true)
+ guard.start
+ UI.should_receive(:info).with('copying to t1/foo')
+ UI.should_receive(:info).with('copying to t2/foo')
+
+ guard.run_on_changes(['source/foo'])
+ end
+ end
+
end
describe '#run_on_removals' do
@@ -254,6 +280,32 @@ module Guard
end
end
+ context 'when :verbose is false (or nil)' do
+ it 'does not log delete operation' do
+ file('source/foo')
+ file('target/foo')
+ guard = Copy.new([], :from => 'source', :to => 'target', :delete => true)
+ guard.start
+ UI.should_not_receive(:info)
+
+ guard.run_on_removals(['source/foo'])
+ end
+ end
+
+ context 'when :verbose is true' do
+ it 'logs delete operation' do
+ file('source/foo')
+ file('t1/foo')
+ file('t2/foo')
+ guard = Copy.new([], :from => 'source', :to => ['t1', 't2'], :delete => true, :verbose => true)
+ guard.start
+ UI.should_receive(:info).with('deleting t1/foo')
+ UI.should_receive(:info).with('deleting t2/foo')
+
+ guard.run_on_removals(['source/foo'])
+ end
+ end
+
end
end

0 comments on commit 9e61c2b

Please sign in to comment.