Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/rb-inotify/notifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions spec/notifier_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down