Skip to content

Commit

Permalink
Fix specs on ignoring unmonitored file events
Browse files Browse the repository at this point in the history
  • Loading branch information
mynyml committed Sep 4, 2009
1 parent 6c1e48c commit 0a4c868
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
1 change: 1 addition & 0 deletions lib/watchr/event_handlers/linux.rb
Expand Up @@ -9,6 +9,7 @@ class Linux
# @dir_map is {wd => path}, where wd == watch descriptor, following
# (ruby-)inotify vocabulary
def initialize
super
@inotify = Inotify.new
@dir_map = {}
end
Expand Down
14 changes: 7 additions & 7 deletions test/test_event_handler.rb
Expand Up @@ -66,15 +66,14 @@ class TestEventHandler < Test::Unit::TestCase

Timeout.timeout(1.5) do
observer.reset
#FileUtils.touch(p[:aaa]) # change of file attributes
p[:aaa].open('w+') {|f| f << 'ohaie' } # file modified
p[:aaa].open('w+') {|f| f << 'ohaie' }
listening.run until observer.notified?
assert observer.notified_with?(p[:aaa]), "expected observer to be notified with #{p[:aaa]}, got #{observer.notified.inspect}"
end

Timeout.timeout(1.5) do
observer.reset
p[:bbb].open('w') {|f| f << 'ohaie' } # file modified
p[:bbb].open('w') {|f| f << 'ohaie' }
listening.run until observer.notified?
assert observer.notified_with?(p[:bbb]), "expected observer to be notified with #{p[:bbb]}, got #{observer.notified.inspect}"
end
Expand All @@ -87,23 +86,24 @@ class TestEventHandler < Test::Unit::TestCase
end

test "ignores events on unmonitored files" do
with_fixtures %w( aaa bbb ) do |dir|
with_fixtures %w( aaa bbb ccc ) do |dir|
handler = Watchr.handler.new
p = {
:aaa => (dir + 'aaa').expand_path,
:bbb => (dir + 'bbb').expand_path
:bbb => (dir + 'bbb').expand_path,
:ccc => (dir + 'ccc').expand_path
}

observer = MockObserver.new
handler.add_observer(observer)

listening = Thread.new {
handler.monitored_paths = p.values
handler.monitored_paths = [ p[:aaa], p[:bbb] ]
handler.listen
}
listening.priority = 10

FileUtils.touch(dir + 'ccc')
p[:ccc].open('w') {|f| f << 'ohaie' }
100.times { listening.run }
sleep( handler.delay || 0.1 )
assert !observer.notified?
Expand Down

0 comments on commit 0a4c868

Please sign in to comment.