Class: Spring::Test::WatcherTest

Inherits:
ActiveSupport::TestCase
  • Object
show all
Defined in:
lib/spring/test/watcher_test.rb

Constant Summary collapse

LATENCY =
0.001
TIMEOUT =
1

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#dirObject

Returns the value of attribute dir.



14
15
16
# File 'lib/spring/test/watcher_test.rb', line 14

def dir
  @dir
end

Instance Method Details

#assert_not_staleObject



45
46
47
48
# File 'lib/spring/test/watcher_test.rb', line 45

def assert_not_stale
  sleep LATENCY * 10
  assert !watcher.stale?
end

#assert_staleObject



39
40
41
42
43
# File 'lib/spring/test/watcher_test.rb', line 39

def assert_stale
  timeout = Time.now + TIMEOUT
  sleep LATENCY until watcher.stale? || Time.now > timeout
  assert watcher.stale?
end

#setupObject



24
25
26
# File 'lib/spring/test/watcher_test.rb', line 24

def setup
  @dir = File.realpath(Dir.mktmpdir)
end

#teardownObject



28
29
30
31
# File 'lib/spring/test/watcher_test.rb', line 28

def teardown
  FileUtils.remove_entry_secure @dir
  watcher.stop
end

#touch(file, mtime = nil) ⇒ Object



33
34
35
36
37
# File 'lib/spring/test/watcher_test.rb', line 33

def touch(file, mtime = nil)
  options = {}
  options[:mtime] = mtime if mtime
  FileUtils.touch(file, options)
end

#watcherObject



20
21
22
# File 'lib/spring/test/watcher_test.rb', line 20

def watcher
  @watcher ||= watcher_class.new(dir, LATENCY)
end

#watcher_classObject

Raises:

  • (NotImplementedError)


16
17
18
# File 'lib/spring/test/watcher_test.rb', line 16

def watcher_class
  raise NotImplementedError
end