Skip to content

Instantly share code, notes, and snippets.

@marcbowes
Created March 17, 2010 10:36
Show Gist options
  • Save marcbowes/335108 to your computer and use it in GitHub Desktop.
Save marcbowes/335108 to your computer and use it in GitHub Desktop.
# This is a cheap stab at demonstrating the behavior of
# Inotify::CREATE. That is, CREATE will trigger inotify events
# immediately upon file creation.
require 'inotify'
require 'fileutils'
# Method which fakes a slow write by sleeping for one second.
def slow_write(filename)
File.open(filename, "w") do |f|
sleep 1
f.puts "data"
end
end
describe Inotify do
before do
@inotify = Inotify.new
end
describe "CREATE" do
it 'should notify immediately' do
wd = @inotify.add_watch("/tmp", Inotify::CREATE)
filename = "/tmp/inotify-" + Time.now.to_i.to_s
writer = Thread.new do
slow_write(filename)
end
@inotify.each_event do |e|
if e.name == File.basename(filename)
File.read(filename).strip.should_not == "data"
break
end
end
writer.join
FileUtils.rm(filename)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment