diff --git a/lib/spring/watcher/listen.rb b/lib/spring/watcher/listen.rb index 75fabcf..e3c37ec 100644 --- a/lib/spring/watcher/listen.rb +++ b/lib/spring/watcher/listen.rb @@ -4,6 +4,11 @@ require "listen" require "listen/version" +# fork() doesn't preserve threads, so a clean +# Celluloid shutdown isn't possible, but we can +# reduce the 10 second timeout +Celluloid.shutdown_timeout = 2 + module Spring module Watcher class Listen < Abstract @@ -13,9 +18,7 @@ class Listen < Abstract def start unless @listener - @listener = ::Listen.to(*base_directories, relative_paths: false) - @listener.latency(latency) - @listener.change(&method(:changed)) + @listener = ::Listen.to(*base_directories, latency: latency, &method(:changed)) @listener.start end end @@ -49,7 +52,7 @@ def base_directories ([root] + files.reject { |f| f.start_with? "#{root}/" }.map { |f| File.expand_path("#{f}/..") } + directories.reject { |d| d.start_with? "#{root}/" } - ).uniq + ).uniq.map { |path| Pathname.new(path) } end end end diff --git a/spring-watcher-listen.gemspec b/spring-watcher-listen.gemspec index 6095ce7..abccaf8 100644 --- a/spring-watcher-listen.gemspec +++ b/spring-watcher-listen.gemspec @@ -19,5 +19,5 @@ Gem::Specification.new do |spec| spec.add_development_dependency "activesupport" spec.add_dependency "spring", "~> 1.2" - spec.add_dependency "listen", "~> 1.0" + spec.add_dependency "listen", "~> 2.7" end diff --git a/test/helper.rb b/test/helper.rb index e20d7b5..8434d03 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -4,4 +4,7 @@ require "spring/test" require "minitest/autorun" +require "celluloid/test" +Celluloid.logger.level = Logger::WARN + Spring::Test.root = File.expand_path('..', __FILE__) diff --git a/test/unit_test.rb b/test/unit_test.rb index 3acc456..a1cfc26 100644 --- a/test/unit_test.rb +++ b/test/unit_test.rb @@ -7,6 +7,12 @@ def watcher_class Spring::Watcher::Listen end + setup { + Celluloid.boot + } + + teardown { Listen.stop } + test "root directories" do begin other_dir_1 = File.realpath(Dir.mktmpdir) @@ -18,7 +24,8 @@ def watcher_class watcher.add other_dir_2 watcher.add "#{dir}/foo" - assert_equal [dir, other_dir_1, other_dir_2].sort, watcher.base_directories.sort + dirs = [dir, other_dir_1, other_dir_2].sort.map { |path| Pathname.new(path) } + assert_equal dirs, watcher.base_directories.sort ensure FileUtils.rmdir other_dir_1 FileUtils.rmdir other_dir_2 @@ -39,7 +46,8 @@ def watcher_class watcher.add "#{other_dir_1}/foo" watcher.add other_dir_2 - assert_equal [dir, other_dir_1, other_dir_2].sort, watcher.base_directories.sort + dirs = [dir, other_dir_1, other_dir_2].sort.map { |path| Pathname.new(path) } + assert_equal dirs, watcher.base_directories.sort ensure FileUtils.rmdir other_dir_1 FileUtils.rmdir other_dir_2