diff --git a/lib/rb-inotify/notifier.rb b/lib/rb-inotify/notifier.rb index e653d49..2a75d5c 100644 --- a/lib/rb-inotify/notifier.rb +++ b/lib/rb-inotify/notifier.rb @@ -195,7 +195,12 @@ def to_io # @raise [SystemCallError] if the file or directory can't be watched, # e.g. if the file isn't found, read access is denied, # or the flags don't contain any events + # @raise [ArgumentError] if the file is specified with :move_to. def watch(path, *flags, &callback) + if File.file?(path) and (flags.include?(:moved_to) or flags.include?(:moved_from)) + raise ArgumentError.new, ":moved_to must not be specified with file #{path}" + end + return Watcher.new(self, path, *flags, &callback) unless flags.include?(:recursive) dir = Dir.new(path) diff --git a/spec/notifier_spec.rb b/spec/notifier_spec.rb index 8370151..38ddc84 100644 --- a/spec/notifier_spec.rb +++ b/spec/notifier_spec.rb @@ -71,6 +71,16 @@ expect(bar_events.first.name).to eq("test_two.txt") expect(bar_events.first.absolute_name).to eq(another_dir.join("test_two.txt").to_s) end + + it "file should not specified with :moved_from or :moved_to" do + dir.join("one.txt").write("hello world") + expect { + recording(dir.join("one.txt"), :moved_to) + }.to raise_error(ArgumentError) + expect { + recording(dir.join("one.txt"), :moved_from) + }.to raise_error(ArgumentError) + end end describe :run do