Sha256: 1bfdac7fbf9fa9ce9fca9fe959516e6e16973155ed594a7d4ee09bfd9b09b626

Contents?: true

Size: 881 Bytes

Versions: 66

Compression:

Stored size: 881 Bytes

Contents

$:.unshift "../lib"
require 'eventmachine'
require 'test/unit'

class TestFileWatch < Test::Unit::TestCase
  module FileWatcher
    def file_modified
      $modified = true
    end
    def file_deleted
      $deleted = true
    end
    def unbind
      $unbind = true
      EM.stop
    end
  end

  def setup
    EM.kqueue = true if EM.kqueue?
  end

  def teardown
    EM.kqueue = false if EM.kqueue?
  end

  def test_events
    EM.run{
      require 'tempfile'
      file = Tempfile.new('em-watch')
      $tmp_path = file.path

      # watch it
      watch = EM.watch_file(file.path, FileWatcher)
      $path = watch.path

      # modify it
      File.open(file.path, 'w'){ |f| f.puts 'hi' }

      # delete it
      EM.add_timer(0.25){ file.close; file.delete }
    }

    assert_equal($path, $tmp_path)
    assert($modified)
    assert($deleted)
    assert($unbind)
  end
end

Version data entries

66 entries across 66 versions & 8 rubygems

Version Path
classiccms-0.7.5 vendor/bundle/gems/eventmachine-0.12.10/tests/test_file_watch.rb
classiccms-0.7.4 vendor/bundle/gems/eventmachine-0.12.10/tests/test_file_watch.rb
classiccms-0.7.3 vendor/bundle/gems/eventmachine-0.12.10/tests/test_file_watch.rb
MattHulse-eventmachine-0.0.1 tests/test_file_watch.rb
MattHulse-eventmachine-0.12.10 tests/test_file_watch.rb
eventmachine-eventmachine-0.12.8 tests/test_file_watch.rb
eventmachine-eventmachine-0.12.9 tests/test_file_watch.rb
classiccms-0.7.2 vendor/bundle/gems/eventmachine-0.12.10/tests/test_file_watch.rb
classiccms-0.7.1 vendor/bundle/gems/eventmachine-0.12.10/tests/test_file_watch.rb
classiccms-0.7.0 vendor/bundle/gems/eventmachine-0.12.10/tests/test_file_watch.rb
classiccms-0.6.9 vendor/bundle/gems/eventmachine-0.12.10/tests/test_file_watch.rb
classiccms-0.6.8 vendor/bundle/gems/eventmachine-0.12.10/tests/test_file_watch.rb
classiccms-0.6.7 vendor/bundle/gems/eventmachine-0.12.10/tests/test_file_watch.rb
classiccms-0.6.6 vendor/bundle/gems/eventmachine-0.12.10/tests/test_file_watch.rb
classiccms-0.6.5 vendor/bundle/gems/eventmachine-0.12.10/tests/test_file_watch.rb
classiccms-0.6.4 vendor/bundle/gems/eventmachine-0.12.10/tests/test_file_watch.rb
classiccms-0.6.3 vendor/bundle/gems/eventmachine-0.12.10/tests/test_file_watch.rb
classiccms-0.6.2 vendor/bundle/gems/eventmachine-0.12.10/tests/test_file_watch.rb
classiccms-0.6.1 vendor/bundle/gems/eventmachine-0.12.10/tests/test_file_watch.rb
classiccms-0.6.0 vendor/bundle/gems/eventmachine-0.12.10/tests/test_file_watch.rb