 temp.track()
 
 describe 'PathWatcher', ->
-  tempFile = temp.openSync('node-pathwatcher-file')
   tempDir = temp.mkdirSync('node-pathwatcher-directory')
+  tempFile = path.join(tempDir, 'file')
 
   beforeEach ->
-    fs.writeFileSync(tempFile.path, '')
+    fs.writeFileSync(tempFile, '')
 
   afterEach ->
     pathWatcher.closeAllWatchers()

  describe '.getWatchedPaths()', ->
    it 'returns an array of all watched paths', ->
      expect(pathWatcher.getWatchedPaths()).toEqual []
      watcher1 = pathWatcher.watch tempFile.path, ->
      expect(pathWatcher.getWatchedPaths()).toEqual [tempFile.path]
      watcher2 = pathWatcher.watch tempFile.path, ->
      expect(pathWatcher.getWatchedPaths()).toEqual [tempFile.path]
      watcher1.close()
      expect(pathWatcher.getWatchedPaths()).toEqual [tempFile.path]
      watcher2.close()
      expect(pathWatcher.getWatchedPaths()).toEqual []

  describe '.closeAllWatchers()', ->
    it 'closes all watched paths', ->
      expect(pathWatcher.getWatchedPaths()).toEqual []
      watcher = pathWatcher.watch tempFile.path, ->
      expect(pathWatcher.getWatchedPaths()).toEqual [tempFile.path]
      pathWatcher.closeAllWatchers()
      expect(pathWatcher.getWatchedPaths()).toEqual []


    it 'fires the callback with the event type and empty path', ->
      eventType = null
      eventPath = null
      watcher = pathWatcher.watch tempFile, (type, path) ->
        eventType = type
        eventPath = path

      fs.writeFileSync(tempFile, 'changed')
      waitsFor -> eventType?
      runs ->
        expect(eventType).toBe 'change'
