Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

check for targets that resolve to files

  • Loading branch information...
commit 805dbfe51c6bbd25c4051e8e7ebdedf50133086f 1 parent f8bbda5
@marcisme authored
Showing with 41 additions and 25 deletions.
  1. +36 −18 lib/guard/copy.rb
  2. +5 −7 spec/guard/copy_spec.rb
View
54 lib/guard/copy.rb
@@ -29,24 +29,9 @@ def start
validate_from_is_directory
validate_presence_of(:to)
validate_to_does_not_include_from
- @targets.each do |target|
- unless target.resolve
- UI.warning("Guard::Copy - '#{target.pattern}' does not match a valid directory")
- end
- end
- if target_paths.any?
- UI.info("Guard::Copy will copy files from:")
- UI.info(" #{options[:from]}")
- UI.info("to:")
- target_paths.each { |target_path| UI.info(" #{target_path}") }
-
- if options[:delete]
- UI.info("Guard::Copy will delete files removed from:")
- UI.info(" #{options[:from]}")
- UI.info("from:")
- target_paths.each { |target_path| UI.info(" #{target_path}") }
- end
- end
+ resolve_targets
+ validate_no_targets_are_files
+ display_target_paths
end
# Called when just `enter` is pressed
@@ -157,5 +142,38 @@ def validate_to_file(to_file)
end
end
+ def resolve_targets
+ @targets.each do |target|
+ unless target.resolve
+ UI.warning("Guard::Copy - '#{target.pattern}' does not match a valid directory")
+ end
+ end
+ end
+
+ def validate_no_targets_are_files
+ target_paths.each do |path|
+ if File.file?(path)
+ UI.error('Guard::Copy - :to option contains a file and must be all directories')
+ throw :task_has_failed
+ end
+ end
+ end
+
+ def display_target_paths
+ if target_paths.any?
+ UI.info("Guard::Copy will copy files from:")
+ UI.info(" #{options[:from]}")
+ UI.info("to:")
+ target_paths.each { |target_path| UI.info(" #{target_path}") }
+
+ if options[:delete]
+ UI.info("Guard::Copy will delete files removed from:")
+ UI.info(" #{options[:from]}")
+ UI.info("from:")
+ target_paths.each { |target_path| UI.info(" #{target_path}") }
+ end
+ end
+ end
+
end
end
View
12 spec/guard/copy_spec.rb
@@ -128,13 +128,11 @@ module Guard
end
it 'throws :task_has_failed when :to contains a file' do
- pending do
- dir('source')
- file('target')
- guard = Copy.new([], :from => 'source', :to => 'target')
- UI.should_receive(:error).with('Guard::Copy - :to option contains a file and must be all directories')
- expect { guard.start }.to throw_symbol(:task_has_failed)
- end
+ dir('source')
+ file('target')
+ guard = Copy.new([], :from => 'source', :to => 'target')
+ UI.should_receive(:error).with('Guard::Copy - :to option contains a file and must be all directories')
+ expect { guard.start }.to throw_symbol(:task_has_failed)
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.