Skip to content
Browse files

fixing stat_watcher spec to not fail randomly

  • Loading branch information...
1 parent 04110f9 commit 8ee4303ccbb5e007e328bf0bb47e5ebdc01ef38c @rares rares committed Feb 7, 2011
Showing with 21 additions and 7 deletions.
  1. +21 −7 spec/stat_watcher_spec.rb
View
28 spec/stat_watcher_spec.rb
@@ -2,11 +2,13 @@
TEMP_FILE_PATH = "./test.txt"
+INTERVAL = 0.010
+
class MyStatWatcher < Cool.io::StatWatcher
attr_accessor :accessed, :previous, :current
def initialize(path)
- super path, 0.010
+ super path, INTERVAL
end
def on_change(previous, current)
@@ -18,15 +20,31 @@ def on_change(previous, current)
def run_with_file_change(path)
reactor = Cool.io::Loop.default
+
sw = MyStatWatcher.new(path)
sw.attach(reactor)
- File.open(path, "a+") { |f| f.write(rand.to_s) }
- reactor.run_once
+
+ tw = Cool.io::TimerWatcher.new(INTERVAL, true)
+ tw.on_timer do
+ reactor.stop if sw.accessed
+ File.open(path, "w+") { |f| f.write(rand.to_s) }
+ end
+ tw.attach(reactor)
+
+ reactor.run
+
+ tw.detach
+ sw.detach
+
sw
end
describe Cool.io::StatWatcher do
+ let :sw do
+ run_with_file_change(TEMP_FILE_PATH)
+ end
+
before :each do
`touch #{TEMP_FILE_PATH}`
end
@@ -36,14 +54,10 @@ def run_with_file_change(path)
end
it "fire on_change when the file it is watching is modified" do
- sw = run_with_file_change(TEMP_FILE_PATH)
-
sw.accessed.should eql(true)
end
it "should pass previous and current file stat info given a stat watcher" do
- sw = run_with_file_change(TEMP_FILE_PATH)
-
sw.previous.ino.should eql(sw.current.ino)
end

0 comments on commit 8ee4303

Please sign in to comment.
Something went wrong with that request. Please try again.