Permalink
Browse files

relax :to validation

Check that targets contained in the `:to` parameter do not start with
the `:from` parameter. The validation used to fail on mere inclusion,
which was overly restrictive.

This change addresses issue #13.
  • Loading branch information...
1 parent 0fa3a8e commit 68df054f4ad9adfa29b22486edf592d5070538ba @marcisme committed Apr 7, 2013
Showing with 6 additions and 6 deletions.
  1. +4 −4 lib/guard/copy.rb
  2. +2 −2 spec/guard/copy_spec.rb
View
@@ -29,7 +29,7 @@ def start
validate_from_is_directory
validate_presence_of(:to)
validate_to_patterns_are_not_absolute
- validate_to_does_not_include_from
+ validate_to_does_not_start_with_from
resolve_targets!
validate_no_targets_are_files
display_target_paths
@@ -120,9 +120,9 @@ def validate_from_is_directory
end
end
- def validate_to_does_not_include_from
- if options[:to].include?(options[:from])
- UI.error('Guard::Copy - :to must not include :from')
+ def validate_to_does_not_start_with_from
+ if Array(options[:to]).any? { |to| to.start_with?(options[:from]) }
+ UI.error('Guard::Copy - :to must not start with :from')
throw :task_has_failed
end
end
View
@@ -112,10 +112,10 @@ module Guard
expect { guard.start }.to throw_symbol(:task_has_failed)
end
- it 'throws :task_has_failed when :to includes :from' do
+ it 'throws :task_has_failed when :to starts with :from' do
dir('source')
guard = Copy.new([], :from => 'source', :to => 'source')
- UI.should_receive(:error).with('Guard::Copy - :to must not include :from')
+ UI.should_receive(:error).with('Guard::Copy - :to must not start with :from')
expect { guard.start }.to throw_symbol(:task_has_failed)
end

0 comments on commit 68df054

Please sign in to comment.