test/unit/application_watcher_test.rb in spring-0.0.2 vs test/unit/application_watcher_test.rb in spring-0.0.3
- old
+ new
@@ -1,7 +1,8 @@
require "helper"
require "fileutils"
+require "active_support/core_ext/numeric/time"
require "spring/application_watcher"
class ApplicationWatcherTest < Test::Unit::TestCase
def setup
@dir = "/tmp/spring"
@@ -10,25 +11,25 @@
def teardown
FileUtils.rm_r(@dir)
end
- def touch(file)
- sleep 0.01
- File.write(file, "omg")
+ def touch(file, mtime = nil)
+ options = {}
+ options[:mtime] = mtime if mtime
+ FileUtils.touch(file, options)
end
def test_file_mtime
file = "#{@dir}/omg"
- touch file
+ touch file, Time.now - 2.seconds
watcher = Spring::ApplicationWatcher.new
watcher.add_files [file]
assert !watcher.stale?
-
- touch file
+ touch file, Time.now
assert watcher.stale?
end
def test_glob
FileUtils.mkdir("#{@dir}/1")
@@ -37,18 +38,18 @@
watcher = Spring::ApplicationWatcher.new
watcher.add_globs ["#{@dir}/1/*.rb", "#{@dir}/2/*"]
assert !watcher.stale?
- touch "#{@dir}/1/foo"
+ touch "#{@dir}/1/foo", Time.now - 1.minute
assert !watcher.stale?
- touch "#{@dir}/1/foo.rb"
+ touch "#{@dir}/1/foo.rb", 2.seconds
assert watcher.stale?
watcher.reset
assert !watcher.stale?
- touch "#{@dir}/2/foo"
+ touch "#{@dir}/2/foo", Time.now
assert watcher.stale?
end
end