Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

DRY up specs

  • Loading branch information...
commit 84f8961f7f3d7cb30c2d4e6f350d95805e4f9aaf 1 parent eac37a1
@rares rares authored
Showing with 33 additions and 14 deletions.
  1. +33 −14 spec/stat_watcher_spec.rb
View
47 spec/stat_watcher_spec.rb
@@ -1,30 +1,49 @@
require File.expand_path('../spec_helper', __FILE__)
+TEMP_FILE_PATH = "./test.txt"
+
+class MyStatWatcher < Cool.io::StatWatcher
+ attr_accessor :accessed, :previous, :current
+
+ def initialize(path)
+ super path, 0.010
+ end
+
+ def on_change(previous, current)
+ self.accessed = true
+ self.previous = previous
+ self.current = current
+ end
+end
+
+def run_with_file_change(path)
+ sw = MyStatWatcher.new(path)
+ sw.attach(Cool.io::Loop.default)
+ File.open(path, "a+") { |f| f.write(rand.to_s) }
+ Cool.io::Loop.default.run_once
+ sw
+end
+
describe Cool.io::StatWatcher do
before :each do
- `touch ./test.txt`
+ `touch #{TEMP_FILE_PATH}`
end
after :each do
- `rm ./test.txt`
+ `rm #{TEMP_FILE_PATH}`
end
- it "fire on change when the file it is watching is modified" do
- class MyStatWatcher < Cool.io::StatWatcher
- attr_accessor :accessed
+ it "fire on_change when the file it is watching is modified" do
+ sw = run_with_file_change(TEMP_FILE_PATH)
- def on_change(previous, current)
- self.accessed = true
- end
- end
+ sw.accessed.should eql(true)
+ end
- sw = MyStatWatcher.new("./test.txt", 0.010)
- sw.attach(Cool.io::Loop.default)
- File.open("./test.txt", "a+") { |f| f.write("content") }
- Cool.io::Loop.default.run_once
+ it "should pass previos and current file stat info given a stat watcher" do
+ sw = run_with_file_change(TEMP_FILE_PATH)
- sw.accessed.should_not be_nil
+ sw.previous.ino.should eql(sw.current.ino)
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.