Sha256: d5652d7333cf8722103b21f7af8bd90d71cf34bb2a90276beda3988b6712c77e

Contents?: true

Size: 957 Bytes

Versions: 2

Compression:

Stored size: 957 Bytes

Contents

require "helper"
require "fileutils"
require "spring/application_watcher"

class ApplicationWatcherTest < Test::Unit::TestCase
  def setup
    @dir = "/tmp/spring"
    FileUtils.mkdir(@dir)
  end

  def teardown
    FileUtils.rm_r(@dir)
  end

  def touch(file)
    sleep 0.01
    File.write(file, "omg")
  end

  def test_file_mtime
    file = "#{@dir}/omg"
    touch file

    watcher = Spring::ApplicationWatcher.new
    watcher.add_files [file]

    assert !watcher.stale?

    touch file
    assert watcher.stale?
  end

  def test_glob
    FileUtils.mkdir("#{@dir}/1")
    FileUtils.mkdir("#{@dir}/2")

    watcher = Spring::ApplicationWatcher.new
    watcher.add_globs ["#{@dir}/1/*.rb", "#{@dir}/2/*"]

    assert !watcher.stale?

    touch "#{@dir}/1/foo"
    assert !watcher.stale?

    touch "#{@dir}/1/foo.rb"
    assert watcher.stale?

    watcher.reset
    assert !watcher.stale?

    touch "#{@dir}/2/foo"
    assert watcher.stale?
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
spring-0.0.2 test/unit/application_watcher_test.rb
spring-0.0.1 test/unit/application_watcher_test.rb