diff -Nru ruby-listen-3.0.3/debian/changelog ruby-listen-3.1.5/debian/changelog --- ruby-listen-3.0.3/debian/changelog 2016-03-03 19:27:27.000000000 +0000 +++ ruby-listen-3.1.5/debian/changelog 2017-12-05 07:21:17.000000000 +0000 @@ -1,3 +1,24 @@ +ruby-listen (3.1.5-1) unstable; urgency=medium + + * Team upload. + + [ HIGUCHI Daisuke (VDR dai) ] + * New upstream release. + * Refresh patches. + - d/p/0003-fix-listener-test-in-ruby2_3.patch: applied upstream. + * d/p/0001-Remove-OSX-specific-dependency.patch: more remove OSX deps. + * d/p/0004-disable-ruby_dep.patch: new patch. + * d/rules: remove test fixtures. + * Support autopkgtest-pkg-ruby. + * Bump Standards-Versio to 4.1.1 (no changes needed) + * Bump debhelper compatibility level to 10 + + [ Cédric Boutillier ] + * Use https:// in Vcs-* fields + * Run wrap-and-sort on packaging files + + -- HIGUCHI Daisuke (VDR dai) Tue, 05 Dec 2017 16:21:17 +0900 + ruby-listen (3.0.3-3) unstable; urgency=medium * Team Upload. diff -Nru ruby-listen-3.0.3/debian/compat ruby-listen-3.1.5/debian/compat --- ruby-listen-3.0.3/debian/compat 2016-03-03 19:26:04.000000000 +0000 +++ ruby-listen-3.1.5/debian/compat 2017-11-27 00:43:02.000000000 +0000 @@ -1 +1 @@ -9 +10 diff -Nru ruby-listen-3.0.3/debian/control ruby-listen-3.1.5/debian/control --- ruby-listen-3.0.3/debian/control 2016-03-03 19:26:04.000000000 +0000 +++ ruby-listen-3.1.5/debian/control 2017-11-27 00:43:02.000000000 +0000 @@ -2,18 +2,18 @@ Section: ruby Priority: optional Maintainer: Debian Ruby Extras Maintainers -Uploaders: Markus Tornow , Cédric Boutillier -Build-Depends: debhelper (>= 9~), +Uploaders: Markus Tornow , + Cédric Boutillier +Build-Depends: debhelper (>= 10~), gem2deb, rake, ruby-rb-inotify (>= 0.9), ruby-rspec, ruby-thor -Standards-Version: 3.9.7 +Standards-Version: 4.1.1 Vcs-Git: https://anonscm.debian.org/git/pkg-ruby-extras/ruby-listen.git Vcs-Browser: https://anonscm.debian.org/cgit/pkg-ruby-extras/ruby-listen.git Homepage: https://github.com/guard/listen -Testsuite: autopkgtest-pkg-ruby XS-Ruby-Versions: all Package: ruby-listen diff -Nru ruby-listen-3.0.3/debian/copyright ruby-listen-3.1.5/debian/copyright --- ruby-listen-3.0.3/debian/copyright 2015-12-17 21:22:54.000000000 +0000 +++ ruby-listen-3.1.5/debian/copyright 2017-11-26 14:20:08.000000000 +0000 @@ -32,4 +32,3 @@ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - diff -Nru ruby-listen-3.0.3/debian/patches/0001-Remove-OSX-specific-dependency.patch ruby-listen-3.1.5/debian/patches/0001-Remove-OSX-specific-dependency.patch --- ruby-listen-3.0.3/debian/patches/0001-Remove-OSX-specific-dependency.patch 2015-12-17 21:22:54.000000000 +0000 +++ ruby-listen-3.1.5/debian/patches/0001-Remove-OSX-specific-dependency.patch 2017-11-27 00:43:02.000000000 +0000 @@ -2,19 +2,27 @@ Date: Fri, 7 Aug 2015 18:14:14 -0300 Subject: Remove OSX-specific dependency ---- - listen.gemspec | 1 - - 1 file changed, 1 deletion(-) - -diff --git a/listen.gemspec b/listen.gemspec -index 1a0e943..032415a 100644 ---- a/listen.gemspec -+++ b/listen.gemspec -@@ -24,7 +24,6 @@ Gem::Specification.new do |s| +Index: ruby-listen/listen.gemspec +=================================================================== +--- ruby-listen.orig/listen.gemspec ++++ ruby-listen/listen.gemspec +@@ -30,7 +30,6 @@ Gem::Specification.new do |s| + abort "Install 'ruby_dep' gem before building this gem" + end - s.required_ruby_version = '>= 1.9.3' +- s.add_dependency 'rb-fsevent', '~> 0.9', '>= 0.9.4' + s.add_dependency 'rb-inotify', '~> 0.9', '>= 0.9.7' -- s.add_dependency 'rb-fsevent', '>= 0.9.3' - s.add_dependency 'rb-inotify', '>= 0.9' + # Used to show warnings at runtime +Index: ruby-listen/lib/listen/adapter/darwin.rb +=================================================================== +--- ruby-listen.orig/lib/listen/adapter/darwin.rb ++++ ruby-listen/lib/listen/adapter/darwin.rb +@@ -22,7 +22,6 @@ module Listen + EOS - s.add_development_dependency 'bundler', '>= 1.3.5' + def self.usable? +- require 'rb-fsevent' + version = RbConfig::CONFIG['target_os'][OS_REGEXP, :major_version] + return false unless version + return true if version.to_i >= 13 # darwin13 is OS X 10.9 diff -Nru ruby-listen-3.0.3/debian/patches/0002-gemspec-skip-git-usage.patch ruby-listen-3.1.5/debian/patches/0002-gemspec-skip-git-usage.patch --- ruby-listen-3.0.3/debian/patches/0002-gemspec-skip-git-usage.patch 2015-12-17 21:22:54.000000000 +0000 +++ ruby-listen-3.1.5/debian/patches/0002-gemspec-skip-git-usage.patch 2017-11-27 00:43:02.000000000 +0000 @@ -6,16 +6,16 @@ listen.gemspec | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) -diff --git a/listen.gemspec b/listen.gemspec -index 032415a..51b4137 100644 ---- a/listen.gemspec -+++ b/listen.gemspec +Index: ruby-listen/listen.gemspec +=================================================================== +--- ruby-listen.orig/listen.gemspec ++++ ruby-listen/listen.gemspec @@ -14,9 +14,7 @@ Gem::Specification.new do |s| s.description = 'The Listen gem listens to file modifications and '\ 'notifies you about the changes. Works everywhere!' -- s.files = `git ls-files -z`.split("\x0").select do |f| -- /^(?:bin|lib)\// =~ f +- s.files = `git ls-files -z`.split("\x0").select do |f| +- %r{^(?:bin|lib)\/} =~ f - end + %w(CHANGELOG.md CONTRIBUTING.md LICENSE.txt README.md) + s.files = Dir.glob('{bin,lib}/**/*') + %w(CHANGELOG.md CONTRIBUTING.md LICENSE.txt README.md) diff -Nru ruby-listen-3.0.3/debian/patches/0003-fix-listener-test-in-ruby2_3.patch ruby-listen-3.1.5/debian/patches/0003-fix-listener-test-in-ruby2_3.patch --- ruby-listen-3.0.3/debian/patches/0003-fix-listener-test-in-ruby2_3.patch 2016-03-03 18:21:37.000000000 +0000 +++ ruby-listen-3.1.5/debian/patches/0003-fix-listener-test-in-ruby2_3.patch 1970-01-01 00:00:00.000000000 +0000 @@ -1,20 +0,0 @@ -Description: Fix listener_spec test in ruby 2.3 -Author: Thiago Ribeiro -Applied-Upstream: https://github.com/guard/listen/pull/368 -Last-Update: 2016-03-03 ---- a/spec/lib/listen/listener_spec.rb -+++ b/spec/lib/listen/listener_spec.rb -@@ -86,7 +86,12 @@ - context 'with a block' do - let(:myblock) { instance_double(Proc) } - let(:block) { proc { myblock.call } } -- subject { described_class.new('dir1', &block) } -+ subject do -+ described_class.new('dir1') do |*args| -+ myblock.call(*args) -+ end -+ end -+ - - it 'passes the block to the event processor' do - allow(Event::Config).to receive(:new) do |*_args, &some_block| diff -Nru ruby-listen-3.0.3/debian/patches/0004-disable-ruby_dep.patch ruby-listen-3.1.5/debian/patches/0004-disable-ruby_dep.patch --- ruby-listen-3.0.3/debian/patches/0004-disable-ruby_dep.patch 1970-01-01 00:00:00.000000000 +0000 +++ ruby-listen-3.1.5/debian/patches/0004-disable-ruby_dep.patch 2017-11-27 00:43:02.000000000 +0000 @@ -0,0 +1,44 @@ +Description: disable ruby_dep +Author: HIGUCHI Daisuke (VDR dai) +Forwarded: not-needed +Last-Update: 2017-11-26 + +Index: ruby-listen/lib/listen.rb +=================================================================== +--- ruby-listen.orig/lib/listen.rb ++++ ruby-listen/lib/listen.rb +@@ -4,11 +4,6 @@ require 'listen/listener' + + require 'listen/internals/thread_pool' + +-# Show warnings about vulnerabilities, bugs and outdated Rubies, since previous +-# versions aren't tested or officially supported. +-require 'ruby_dep/warning' +-RubyDep::Warning.new.show_warnings +- + # Always set up logging by default first time file is required + # + # NOTE: If you need to clear the logger completely, do so *after* +Index: ruby-listen/listen.gemspec +=================================================================== +--- ruby-listen.orig/listen.gemspec ++++ ruby-listen/listen.gemspec +@@ -20,18 +20,7 @@ Gem::Specification.new do |s| + s.executable = 'listen' + s.require_path = 'lib' + +- begin +- # TODO: should this be vendored instead? +- require 'ruby_dep/travis' +- s.required_ruby_version = RubyDep::Travis.new.version_constraint +- rescue LoadError +- abort "Install 'ruby_dep' gem before building this gem" +- end +- + s.add_dependency 'rb-inotify', '~> 0.9', '>= 0.9.7' + +- # Used to show warnings at runtime +- s.add_dependency 'ruby_dep', '~> 1.2' +- + s.add_development_dependency 'bundler', '~> 1.12' + end diff -Nru ruby-listen-3.0.3/debian/patches/series ruby-listen-3.1.5/debian/patches/series --- ruby-listen-3.0.3/debian/patches/series 2016-03-03 17:38:44.000000000 +0000 +++ ruby-listen-3.1.5/debian/patches/series 2017-11-27 00:43:02.000000000 +0000 @@ -1,3 +1,3 @@ 0001-Remove-OSX-specific-dependency.patch 0002-gemspec-skip-git-usage.patch -0003-fix-listener-test-in-ruby2_3.patch +0004-disable-ruby_dep.patch diff -Nru ruby-listen-3.0.3/debian/rules ruby-listen-3.1.5/debian/rules --- ruby-listen-3.0.3/debian/rules 2015-12-17 21:22:54.000000000 +0000 +++ ruby-listen-3.1.5/debian/rules 2017-12-05 07:21:17.000000000 +0000 @@ -4,3 +4,7 @@ %: dh $@ --buildsystem=ruby --with ruby + +override_dh_auto_clean: + rm -fr $(CURDIR)/spec/.fixtures + dh_auto_clean diff -Nru ruby-listen-3.0.3/debian/tests/control ruby-listen-3.1.5/debian/tests/control --- ruby-listen-3.0.3/debian/tests/control 1970-01-01 00:00:00.000000000 +0000 +++ ruby-listen-3.1.5/debian/tests/control 2017-11-27 00:43:02.000000000 +0000 @@ -0,0 +1,3 @@ +Tests: run-test +Depends: @, quilt, gem2deb-test-runner, rake, ruby-rb-inotify, ruby-rspec, ruby-thor +Restrictions: allow-stderr diff -Nru ruby-listen-3.0.3/debian/tests/run-test ruby-listen-3.1.5/debian/tests/run-test --- ruby-listen-3.0.3/debian/tests/run-test 1970-01-01 00:00:00.000000000 +0000 +++ ruby-listen-3.1.5/debian/tests/run-test 2017-11-27 00:43:02.000000000 +0000 @@ -0,0 +1,7 @@ +#!/bin/sh + +set -e + +QUILT_PATCHES=debian/patches quilt push -a || true +gem2deb-test-runner --check-dependencies --autopkgtest 2>&1 +QUILT_PATCHES=debian/patches quilt pop -a || true diff -Nru ruby-listen-3.0.3/Gemfile ruby-listen-3.1.5/Gemfile --- ruby-listen-3.0.3/Gemfile 2015-07-23 10:00:59.000000000 +0000 +++ ruby-listen-3.1.5/Gemfile 2016-05-18 02:15:20.000000000 +0000 @@ -27,7 +27,7 @@ group :development do gem 'yard', require: false gem 'guard-rspec', require: false - gem 'rubocop', '0.25.0' # TODO: should match Gemfile HoundCi + gem 'rubocop', '0.38.0' # TODO: should match Gemfile HoundCi gem 'guard-rubocop' gem 'pry-rescue' gem 'pry-stack_explorer', platforms: [:mri, :rbx] diff -Nru ruby-listen-3.0.3/lib/listen/adapter/base.rb ruby-listen-3.1.5/lib/listen/adapter/base.rb --- ruby-listen-3.0.3/lib/listen/adapter/base.rb 2015-07-23 10:00:59.000000000 +0000 +++ ruby-listen-3.1.5/lib/listen/adapter/base.rb 2016-05-18 02:15:20.000000000 +0000 @@ -8,7 +8,7 @@ attr_reader :options # TODO: only used by tests - DEFAULTS = {} + DEFAULTS = {}.freeze attr_reader :config @@ -85,12 +85,19 @@ end end + def stop + _stop + end + def self.usable? const_get('OS_REGEXP') =~ RbConfig::CONFIG['target_os'] end private + def _stop + end + def _timed(title) start = Time.now.to_f yield @@ -122,8 +129,12 @@ _log(:error, formatted) end - def self._log(*args, &block) - Listen::Logger.send(*args, &block) + class << self + private + + def _log(*args, &block) + Listen::Logger.send(*args, &block) + end end end end diff -Nru ruby-listen-3.0.3/lib/listen/adapter/bsd.rb ruby-listen-3.1.5/lib/listen/adapter/bsd.rb --- ruby-listen-3.0.3/lib/listen/adapter/bsd.rb 2015-07-23 10:00:59.000000000 +0000 +++ ruby-listen-3.1.5/lib/listen/adapter/bsd.rb 2016-05-18 02:15:20.000000000 +0000 @@ -16,7 +16,7 @@ :rename # :link, :revoke ] - } + }.freeze BUNDLER_DECLARE_GEM = <<-EOS.gsub(/^ {6}/, '') Please add the following to your Gemfile to avoid polling for changes: @@ -38,9 +38,9 @@ private - def _configure(directory, &_callback) + def _configure(directory, &callback) @worker ||= KQueue::Queue.new - @callback = _callback + @callback = callback # use Record to make a snapshot of dir, so we # can detect new files _find(directory.to_s) { |path| _watch_file(path, @worker) } diff -Nru ruby-listen-3.0.3/lib/listen/adapter/config.rb ruby-listen-3.1.5/lib/listen/adapter/config.rb --- ruby-listen-3.0.3/lib/listen/adapter/config.rb 2015-07-23 10:00:59.000000000 +0000 +++ ruby-listen-3.1.5/lib/listen/adapter/config.rb 2016-05-18 02:15:20.000000000 +0000 @@ -9,6 +9,9 @@ attr_reader :adapter_options def initialize(directories, queue, silencer, adapter_options) + # Default to current directory if no directories are supplied + directories = [Dir.pwd] if directories.to_a.empty? + # TODO: fix (flatten, array, compact?) @directories = directories.map do |directory| Pathname.new(directory.to_s).realpath diff -Nru ruby-listen-3.0.3/lib/listen/adapter/darwin.rb ruby-listen-3.1.5/lib/listen/adapter/darwin.rb --- ruby-listen-3.0.3/lib/listen/adapter/darwin.rb 2015-07-23 10:00:59.000000000 +0000 +++ ruby-listen-3.1.5/lib/listen/adapter/darwin.rb 2016-05-18 02:15:20.000000000 +0000 @@ -6,50 +6,87 @@ # Adapter implementation for Mac OS X `FSEvents`. # class Darwin < Base - OS_REGEXP = /darwin(1.+)?$/i + OS_REGEXP = /darwin(?1\d+)/i # The default delay between checking for changes. - DEFAULTS = { latency: 0.1 } + DEFAULTS = { latency: 0.1 }.freeze + + INCOMPATIBLE_GEM_VERSION = <<-EOS.gsub(/^ {8}/, '') + rb-fsevent > 0.9.4 no longer supports OS X 10.6 through 10.8. + + Please add the following to your Gemfile to avoid polling for changes: + require 'rbconfig' + if RbConfig::CONFIG['target_os'] =~ /darwin(1[0-3])/i + gem 'rb-fsevent', '<= 0.9.4' + end + EOS + + def self.usable? + require 'rb-fsevent' + version = RbConfig::CONFIG['target_os'][OS_REGEXP, :major_version] + return false unless version + return true if version.to_i >= 13 # darwin13 is OS X 10.9 + + fsevent_version = Gem::Version.new(FSEvent::VERSION) + return true if fsevent_version <= Gem::Version.new('0.9.4') + Kernel.warn INCOMPATIBLE_GEM_VERSION + false + end private # NOTE: each directory gets a DIFFERENT callback! def _configure(dir, &callback) - require 'rb-fsevent' opts = { latency: options.latency } @workers ||= ::Queue.new @workers << FSEvent.new.tap do |worker| + _log :debug, "fsevent: watching: #{dir.to_s.inspect}" worker.watch(dir.to_s, opts, &callback) end end - # NOTE: _run is called within a thread, so run every other - # worker in it's own thread def _run first = @workers.pop - until @workers.empty? - next_worker = @workers.pop - Listen::Internals::ThreadPool.add do - begin - next_worker.run - rescue - _log_exception 'run() in extra thread(s) failed: %s: %s' - end - end - end - first.run + + # NOTE: _run is called within a thread, so run every other + # worker in it's own thread + _run_workers_in_background(_to_array(@workers)) + _run_worker(first) end def _process_event(dir, event) + _log :debug, "fsevent: processing event: #{event.inspect}" event.each do |path| - new_path = Pathname.new(path.sub(/\/$/, '')) + new_path = Pathname.new(path.sub(%r{\/$}, '')) _log :debug, "fsevent: #{new_path}" # TODO: does this preserve symlinks? rel_path = new_path.relative_path_from(dir).to_s _queue_change(:dir, dir, rel_path, recursive: true) end end + + def _run_worker(worker) + _log :debug, "fsevent: running worker: #{worker.inspect}" + worker.run + rescue + format_string = 'fsevent: running worker failed: %s:%s called from: %s' + _log_exception format_string, caller + end + + def _run_workers_in_background(workers) + workers.each do |worker| + # NOTE: while passing local variables to the block below is not + # thread safe, using 'worker' from the enumerator above is ok + Listen::Internals::ThreadPool.add { _run_worker(worker) } + end + end + + def _to_array(queue) + workers = [] + workers << queue.pop until queue.empty? + workers + end end end end diff -Nru ruby-listen-3.0.3/lib/listen/adapter/linux.rb ruby-listen-3.1.5/lib/listen/adapter/linux.rb --- ruby-listen-3.0.3/lib/listen/adapter/linux.rb 2015-07-23 10:00:59.000000000 +0000 +++ ruby-listen-3.1.5/lib/listen/adapter/linux.rb 2016-05-18 02:15:20.000000000 +0000 @@ -14,12 +14,12 @@ :close_write ], wait_for_delay: 0.1 - } + }.freeze private WIKI_URL = 'https://github.com/guard/listen'\ - '/wiki/Increasing-the-amount-of-inotify-watchers' + '/wiki/Increasing-the-amount-of-inotify-watchers'.freeze INOTIFY_LIMIT_MESSAGE = <<-EOS.gsub(/^\s*/, '') FATAL: Listen error: unable to monitor directories for changes. @@ -27,7 +27,7 @@ EOS def _configure(directory, &callback) - Kernel.require 'rb-inotify' + require 'rb-inotify' @worker ||= ::INotify::Notifier.new @worker.watch(directory.to_s, *options.events, &callback) rescue Errno::ENOSPC @@ -35,7 +35,9 @@ end def _run + Thread.current[:listen_blocking_read_thread] = true @worker.run + Thread.current[:listen_blocking_read_thread] = false end def _process_event(dir, event) @@ -50,10 +52,8 @@ if /1|true/ =~ ENV['LISTEN_GEM_SIMULATE_FSEVENT'] if (event.flags & [:moved_to, :moved_from]) || _dir_event?(event) rel_path = path.dirname.relative_path_from(dir).to_s - _queue_change(:dir, dir, rel_path, {}) - else - _queue_change(:dir, dir, rel_path, {}) end + _queue_change(:dir, dir, rel_path, {}) return end @@ -97,6 +97,10 @@ def _dir_event?(event) event.flags.include?(:isdir) end + + def _stop + @worker && @worker.close + end end end end diff -Nru ruby-listen-3.0.3/lib/listen/adapter/polling.rb ruby-listen-3.1.5/lib/listen/adapter/polling.rb --- ruby-listen-3.0.3/lib/listen/adapter/polling.rb 2015-07-23 10:00:59.000000000 +0000 +++ ruby-listen-3.1.5/lib/listen/adapter/polling.rb 2016-05-18 02:15:20.000000000 +0000 @@ -8,7 +8,7 @@ class Polling < Base OS_REGEXP = // # match every OS - DEFAULTS = { latency: 1.0, wait_for_delay: 0.05 } + DEFAULTS = { latency: 1.0, wait_for_delay: 0.05 }.freeze private diff -Nru ruby-listen-3.0.3/lib/listen/adapter/windows.rb ruby-listen-3.1.5/lib/listen/adapter/windows.rb --- ruby-listen-3.0.3/lib/listen/adapter/windows.rb 2015-07-23 10:00:59.000000000 +0000 +++ ruby-listen-3.1.5/lib/listen/adapter/windows.rb 2016-05-18 02:15:20.000000000 +0000 @@ -24,21 +24,21 @@ private - def _configure(dir, &callback) + def _configure(dir) require 'wdm' _log :debug, 'wdm - starting...' @worker ||= WDM::Monitor.new @worker.watch_recursively(dir.to_s, :files) do |change| - callback.call([:file, change]) + yield([:file, change]) end @worker.watch_recursively(dir.to_s, :directories) do |change| - callback.call([:dir, change]) + yield([:dir, change]) end events = [:attributes, :last_write] @worker.watch_recursively(dir.to_s, *events) do |change| - callback.call([:attr, change]) + yield([:attr, change]) end end @@ -70,7 +70,6 @@ _queue_change(:dir, dir, Pathname(rel_path).dirname.to_s, {}) elsif change.type == :added _queue_change(:dir, dir, rel_path, {}) - else # do nothing - changed directory means either: # - removed subdirs (handled above) # - added subdirs (handled above) @@ -81,7 +80,7 @@ end rescue details = event.inspect - _log :error, format('wdm - callback (%): %s:%s', details, $ERROR_INFO, + _log :error, format('wdm - callback (%s): %s:%s', details, $ERROR_INFO, $ERROR_POSITION * "\n") raise end diff -Nru ruby-listen-3.0.3/lib/listen/adapter.rb ruby-listen-3.1.5/lib/listen/adapter.rb --- ruby-listen-3.0.3/lib/listen/adapter.rb 2015-07-23 10:00:59.000000000 +0000 +++ ruby-listen-3.1.5/lib/listen/adapter.rb 2016-05-18 02:15:20.000000000 +0000 @@ -7,37 +7,39 @@ module Listen module Adapter - OPTIMIZED_ADAPTERS = [Darwin, Linux, BSD, Windows] + OPTIMIZED_ADAPTERS = [Darwin, Linux, BSD, Windows].freeze POLLING_FALLBACK_MESSAGE = 'Listen will be polling for changes.'\ - 'Learn more at https://github.com/guard/listen#listen-adapters.' + 'Learn more at https://github.com/guard/listen#listen-adapters.'.freeze - def self.select(options = {}) - _log :debug, 'Adapter: considering polling ...' - return Polling if options[:force_polling] - _log :debug, 'Adapter: considering optimized backend...' - return _usable_adapter_class if _usable_adapter_class - _log :debug, 'Adapter: falling back to polling...' - _warn_polling_fallback(options) - Polling - rescue - _log :warn, format('Adapter: failed: %s:%s', $ERROR_POSITION.inspect, - $ERROR_POSITION * "\n") - raise - end - - private - - def self._usable_adapter_class - OPTIMIZED_ADAPTERS.detect(&:usable?) - end - - def self._warn_polling_fallback(options) - msg = options.fetch(:polling_fallback_message, POLLING_FALLBACK_MESSAGE) - Kernel.warn "[Listen warning]:\n #{msg}" if msg - end - - def self._log(type, message) - Listen::Logger.send(type, message) + class << self + def select(options = {}) + _log :debug, 'Adapter: considering polling ...' + return Polling if options[:force_polling] + _log :debug, 'Adapter: considering optimized backend...' + return _usable_adapter_class if _usable_adapter_class + _log :debug, 'Adapter: falling back to polling...' + _warn_polling_fallback(options) + Polling + rescue + _log :warn, format('Adapter: failed: %s:%s', $ERROR_POSITION.inspect, + $ERROR_POSITION * "\n") + raise + end + + private + + def _usable_adapter_class + OPTIMIZED_ADAPTERS.detect(&:usable?) + end + + def _warn_polling_fallback(options) + msg = options.fetch(:polling_fallback_message, POLLING_FALLBACK_MESSAGE) + Kernel.warn "[Listen warning]:\n #{msg}" if msg + end + + def _log(type, message) + Listen::Logger.send(type, message) + end end end end diff -Nru ruby-listen-3.0.3/lib/listen/backend.rb ruby-listen-3.1.5/lib/listen/backend.rb --- ruby-listen-3.0.3/lib/listen/backend.rb 2015-07-23 10:00:59.000000000 +0000 +++ ruby-listen-3.1.5/lib/listen/backend.rb 2016-05-18 02:15:20.000000000 +0000 @@ -2,10 +2,14 @@ require 'listen/adapter/base' require 'listen/adapter/config' +require 'forwardable' + # This class just aggregates configuration object to avoid Listener specs # from exploding with huge test setup blocks module Listen class Backend + extend Forwardable + def initialize(directories, queue, silencer, config) adapter_select_opts = config.adapter_select_options @@ -22,17 +26,10 @@ @adapter = adapter_class.new(aconfig) end - def start - adapter.start - end - - def stop - # TODO: does nothing - end + delegate start: :adapter + delegate stop: :adapter - def min_delay_between_events - @min_delay_between_events - end + attr_reader :min_delay_between_events private diff -Nru ruby-listen-3.0.3/lib/listen/change.rb ruby-listen-3.1.5/lib/listen/change.rb --- ruby-listen-3.0.3/lib/listen/change.rb 2015-07-23 10:00:59.000000000 +0000 +++ ruby-listen-3.1.5/lib/listen/change.rb 2016-05-18 02:15:20.000000000 +0000 @@ -35,7 +35,7 @@ cookie = options[:cookie] if !cookie && config.silenced?(rel_path, type) - Listen::Logger.debug { "(silenced): #{rel_path.inspect}" } + Listen::Logger.debug { "(silenced): #{rel_path.inspect}" } return end @@ -49,16 +49,14 @@ if change options = cookie ? { cookie: cookie } : {} config.queue(type, change, watched_dir, rel_path, options) + elsif type == :dir + # NOTE: POSSIBLE RECURSION + # TODO: fix - use a queue instead + Directory.scan(self, rel_path, options) else - if type == :dir - # NOTE: POSSIBLE RECURSION - # TODO: fix - use a queue instead - Directory.scan(self, rel_path, options) - else - change = File.change(record, rel_path) - return if !change || options[:silence] - config.queue(:file, change, watched_dir, rel_path) - end + change = File.change(record, rel_path) + return if !change || options[:silence] + config.queue(:file, change, watched_dir, rel_path) end rescue RuntimeError => ex msg = format( diff -Nru ruby-listen-3.0.3/lib/listen/directory.rb ruby-listen-3.1.5/lib/listen/directory.rb --- ruby-listen-3.0.3/lib/listen/directory.rb 2015-07-23 10:00:59.000000000 +0000 +++ ruby-listen-3.1.5/lib/listen/directory.rb 2016-05-18 02:15:20.000000000 +0000 @@ -12,7 +12,7 @@ # TODO: use children(with_directory: false) path = dir + rel_path - current = Set.new(path.children) + current = Set.new(_children(path)) Listen::Logger.debug do format('%s: %s(%s): %s -> %s', @@ -20,10 +20,16 @@ rel_path, options.inspect, previous.inspect, current.inspect) end - current.each do |full_path| - type = detect_type(full_path) - item_rel_path = full_path.relative_path_from(dir).to_s - _change(snapshot, type, item_rel_path, options) + begin + current.each do |full_path| + type = ::File.lstat(full_path.to_s).directory? ? :dir : :file + item_rel_path = full_path.relative_path_from(dir).to_s + _change(snapshot, type, item_rel_path, options) + end + rescue Errno::ENOENT + # The directory changed meanwhile, so rescan it + current = Set.new(_children(path)) + retry end # TODO: this is not tested properly @@ -67,14 +73,15 @@ snapshot.invalidate(type, path, opts) end - def self.detect_type(full_path) - # TODO: should probably check record first - stat = ::File.lstat(full_path.to_s) - stat.directory? ? :dir : :file - rescue Errno::ENOENT - # TODO: ok, it should really check the record here - # report as dir for scanning - :dir + def self._children(path) + return path.children unless RUBY_ENGINE == 'jruby' + + # JRuby inconsistency workaround, see: + # https://github.com/jruby/jruby/issues/3840 + exists = path.exist? + directory = path.directory? + return path.children unless exists && !directory + raise Errno::ENOTDIR, path.to_s end end end diff -Nru ruby-listen-3.0.3/lib/listen/event/config.rb ruby-listen-3.1.5/lib/listen/event/config.rb --- ruby-listen-3.0.3/lib/listen/event/config.rb 2015-07-23 10:00:59.000000000 +0000 +++ ruby-listen-3.1.5/lib/listen/event/config.rb 2016-05-18 02:15:20.000000000 +0000 @@ -27,9 +27,7 @@ Time.now.to_f end - def event_queue - @event_queue - end + attr_reader :event_queue def callable? @block @@ -39,9 +37,7 @@ @queue_optimizer.smoosh_changes(changes) end - def min_delay_between_events - @min_delay_between_events - end + attr_reader :min_delay_between_events def stopped? listener.state == :stopped diff -Nru ruby-listen-3.0.3/lib/listen/event/queue.rb ruby-listen-3.1.5/lib/listen/event/queue.rb --- ruby-listen-3.0.3/lib/listen/event/queue.rb 2015-07-23 10:00:59.000000000 +0000 +++ ruby-listen-3.1.5/lib/listen/event/queue.rb 2016-05-18 02:15:20.000000000 +0000 @@ -1,8 +1,12 @@ require 'thread' +require 'forwardable' + module Listen module Event class Queue + extend Forwardable + class Config def initialize(relative) @relative = relative @@ -31,13 +35,8 @@ block.call(args) if block end - def empty? - event_queue.empty? - end - - def pop - event_queue.pop - end + delegate empty?: :event_queue + delegate pop: :event_queue private diff -Nru ruby-listen-3.0.3/lib/listen/file.rb ruby-listen-3.1.5/lib/listen/file.rb --- ruby-listen-3.0.3/lib/listen/file.rb 2015-07-23 10:00:59.000000000 +0000 +++ ruby-listen-3.1.5/lib/listen/file.rb 2016-05-18 02:15:20.000000000 +0000 @@ -26,7 +26,7 @@ end return if /1|true/ =~ ENV['LISTEN_GEM_DISABLE_HASHING'] - return unless self.inaccurate_mac_time?(lstat) + return unless inaccurate_mac_time?(lstat) # Check if change happened within 1 second (maybe it's even # too much, e.g. 0.3-0.5 could be sufficient). diff -Nru ruby-listen-3.0.3/lib/listen/fsm.rb ruby-listen-3.1.5/lib/listen/fsm.rb --- ruby-listen-3.0.3/lib/listen/fsm.rb 2015-07-23 10:00:59.000000000 +0000 +++ ruby-listen-3.1.5/lib/listen/fsm.rb 2016-05-18 02:15:20.000000000 +0000 @@ -111,7 +111,8 @@ attr_reader :name, :transitions def initialize(name, transitions = nil, &block) - @name, @block = name, block + @name = name + @block = block @transitions = nil @transitions = Array(transitions).map(&:to_sym) if transitions end diff -Nru ruby-listen-3.0.3/lib/listen/internals/thread_pool.rb ruby-listen-3.1.5/lib/listen/internals/thread_pool.rb --- ruby-listen-3.0.3/lib/listen/internals/thread_pool.rb 2015-07-23 10:00:59.000000000 +0000 +++ ruby-listen-3.1.5/lib/listen/internals/thread_pool.rb 2016-05-18 02:15:20.000000000 +0000 @@ -13,8 +13,16 @@ return if @threads.empty? # return to avoid using possibly stubbed Queue killed = Queue.new + # You can't kill a read on a descriptor in JRuby, so let's just + # ignore running threads (listen rb-inotify waiting for disk activity + # before closing) pray threads die faster than they are created... + limit = RUBY_ENGINE == 'jruby' ? [1] : [] + killed << @threads.pop.kill until @threads.empty? - killed.pop.join until killed.empty? + until killed.empty? + th = killed.pop + th.join(*limit) unless th[:listen_blocking_read_thread] + end end end end diff -Nru ruby-listen-3.0.3/lib/listen/listener/config.rb ruby-listen-3.1.5/lib/listen/listener/config.rb --- ruby-listen-3.0.3/lib/listen/listener/config.rb 2015-07-23 10:00:59.000000000 +0000 +++ ruby-listen-3.1.5/lib/listen/listener/config.rb 2016-05-18 02:15:20.000000000 +0000 @@ -10,7 +10,7 @@ # Backend selecting options force_polling: false, polling_fallback_message: nil - } + }.freeze def initialize(opts) @options = DEFAULTS.merge(opts) @@ -23,13 +23,9 @@ @relative end - def min_delay_between_events - @min_delay_between_events - end + attr_reader :min_delay_between_events - def silencer_rules - @silencer_rules - end + attr_reader :silencer_rules def adapter_instance_options(klass) valid_keys = klass.const_get('DEFAULTS').keys diff -Nru ruby-listen-3.0.3/lib/listen/listener.rb ruby-listen-3.1.5/lib/listen/listener.rb --- ruby-listen-3.0.3/lib/listen/listener.rb 2015-07-23 10:00:59.000000000 +0000 +++ ruby-listen-3.1.5/lib/listen/listener.rb 2016-05-18 02:15:20.000000000 +0000 @@ -19,6 +19,7 @@ module Listen class Listener + # TODO: move the state machine's methods private include Listen::FSM # Initializes the directories listener. @@ -61,13 +62,13 @@ default_state :initializing - state :initializing, to: :backend_started + state :initializing, to: [:backend_started, :stopped] - state :backend_started, to: [:frontend_ready] do + state :backend_started, to: [:frontend_ready, :stopped] do backend.start end - state :frontend_ready, to: [:processing_events] do + state :frontend_ready, to: [:processing_events, :stopped] do processor.setup end diff -Nru ruby-listen-3.0.3/lib/listen/queue_optimizer.rb ruby-listen-3.1.5/lib/listen/queue_optimizer.rb --- ruby-listen-3.0.3/lib/listen/queue_optimizer.rb 2015-07-23 10:00:59.000000000 +0000 +++ ruby-listen-3.1.5/lib/listen/queue_optimizer.rb 2016-05-18 02:15:20.000000000 +0000 @@ -88,7 +88,7 @@ # editor rename() call (e.g. Kate and Sublime) def _reinterpret_related_changes(cookies) table = { moved_to: :added, moved_from: :removed } - cookies.map do |_, changes| + cookies.flat_map do |_, changes| data = _detect_possible_editor_save(changes) if data to_dir, to_file = data @@ -101,7 +101,7 @@ [table.fetch(change, change), dir, path] end end - end.flatten(1) + end end def _detect_possible_editor_save(changes) @@ -113,9 +113,9 @@ changes.each do |data| case data[1] when :moved_from - from_type, from_change, _, from, _ = data + from_type, from_change, _, from, = data when :moved_to - to_type, to_change, to_dir, to, _ = data + to_type, to_change, to_dir, to, = data else return nil end diff -Nru ruby-listen-3.0.3/lib/listen/record/entry.rb ruby-listen-3.1.5/lib/listen/record/entry.rb --- ruby-listen-3.0.3/lib/listen/record/entry.rb 2015-07-23 10:00:59.000000000 +0000 +++ ruby-listen-3.1.5/lib/listen/record/entry.rb 2016-05-18 02:15:20.000000000 +0000 @@ -6,14 +6,16 @@ # file: "/home/me/watched_dir", "app/models", "foo.rb" # dir, "/home/me/watched_dir", "." def initialize(root, relative, name = nil) - @root, @relative, @name = root, relative, name + @root = root + @relative = relative + @name = name end attr_reader :root, :relative, :name def children child_relative = _join - (Dir.entries(sys_path) - %w(. ..)).map do |name| + (_entries(sys_path) - %w(. ..)).map do |name| Entry.new(@root, child_relative, name) end end @@ -46,6 +48,17 @@ args = [@relative, @name].compact args.empty? ? nil : ::File.join(*args) end + + def _entries(dir) + return Dir.entries(dir) unless RUBY_ENGINE == 'jruby' + + # JRuby inconsistency workaround, see: + # https://github.com/jruby/jruby/issues/3840 + exists = ::File.exist?(dir) + directory = ::File.directory?(dir) + return Dir.entries(dir) unless exists && !directory + raise Errno::ENOTDIR, dir + end end end end diff -Nru ruby-listen-3.0.3/lib/listen/record/symlink_detector.rb ruby-listen-3.1.5/lib/listen/record/symlink_detector.rb --- ruby-listen-3.0.3/lib/listen/record/symlink_detector.rb 2015-07-23 10:00:59.000000000 +0000 +++ ruby-listen-3.1.5/lib/listen/record/symlink_detector.rb 2016-05-18 02:15:20.000000000 +0000 @@ -4,14 +4,14 @@ # @private api class Record class SymlinkDetector - WIKI = 'https://github.com/guard/listen/wiki/Duplicate-directory-errors' + WIKI = 'https://github.com/guard/listen/wiki/Duplicate-directory-errors'.freeze - SYMLINK_LOOP_ERROR = <<-EOS + SYMLINK_LOOP_ERROR = <<-EOS.freeze ** ERROR: directory is already being watched! ** Directory: %s - is already begin watched through: %s + is already being watched through: %s MORE INFO: #{WIKI} EOS diff -Nru ruby-listen-3.0.3/lib/listen/record.rb ruby-listen-3.1.5/lib/listen/record.rb --- ruby-listen-3.0.3/lib/listen/record.rb 2015-07-23 10:00:59.000000000 +0000 +++ ruby-listen-3.1.5/lib/listen/record.rb 2016-05-18 02:15:20.000000000 +0000 @@ -74,9 +74,7 @@ Hash.new { |h, k| h[k] = Hash.new } end - def tree - @tree - end + attr_reader :tree def _fast_update_file(dirname, basename, data) if [nil, '', '.'].include? dirname diff -Nru ruby-listen-3.0.3/lib/listen/silencer.rb ruby-listen-3.1.5/lib/listen/silencer.rb --- ruby-listen-3.0.3/lib/listen/silencer.rb 2015-07-23 10:00:59.000000000 +0000 +++ ruby-listen-3.1.5/lib/listen/silencer.rb 2016-05-18 02:15:20.000000000 +0000 @@ -15,7 +15,7 @@ )(/|$)}x # The default list of files that get ignored. - DEFAULT_IGNORED_EXTENSIONS = /(?: + DEFAULT_IGNORED_EXTENSIONS = %r{(?: # Kate's tmp\/swp files \..*\d+\.new | \.kate-swp @@ -50,7 +50,7 @@ | \.DS_Store | \.tmp | ~ - )$/x + )$}x attr_accessor :only_patterns, :ignore_patterns diff -Nru ruby-listen-3.0.3/lib/listen/version.rb ruby-listen-3.1.5/lib/listen/version.rb --- ruby-listen-3.0.3/lib/listen/version.rb 2015-07-23 10:00:59.000000000 +0000 +++ ruby-listen-3.1.5/lib/listen/version.rb 2016-05-18 02:15:20.000000000 +0000 @@ -1,3 +1,3 @@ module Listen - VERSION = '3.0.3' + VERSION = '3.1.5'.freeze end diff -Nru ruby-listen-3.0.3/lib/listen.rb ruby-listen-3.1.5/lib/listen.rb --- ruby-listen-3.0.3/lib/listen.rb 2015-07-23 10:00:59.000000000 +0000 +++ ruby-listen-3.1.5/lib/listen.rb 2016-05-18 02:15:20.000000000 +0000 @@ -4,6 +4,11 @@ require 'listen/internals/thread_pool' +# Show warnings about vulnerabilities, bugs and outdated Rubies, since previous +# versions aren't tested or officially supported. +require 'ruby_dep/warning' +RubyDep::Warning.new.show_warnings + # Always set up logging by default first time file is required # # NOTE: If you need to clear the logger completely, do so *after* @@ -45,10 +50,7 @@ @listeners ||= [] # TODO: should use a mutex for this - @listeners.each do |listener| - # call stop to halt the main loop - listener.stop - end + @listeners.each(&:stop) @listeners = nil end end diff -Nru ruby-listen-3.0.3/listen.gemspec ruby-listen-3.1.5/listen.gemspec --- ruby-listen-3.0.3/listen.gemspec 2015-07-23 10:00:59.000000000 +0000 +++ ruby-listen-3.1.5/listen.gemspec 2016-05-18 02:15:20.000000000 +0000 @@ -14,18 +14,27 @@ s.description = 'The Listen gem listens to file modifications and '\ 'notifies you about the changes. Works everywhere!' - s.files = `git ls-files -z`.split("\x0").select do |f| - /^(?:bin|lib)\// =~ f + s.files = `git ls-files -z`.split("\x0").select do |f| + %r{^(?:bin|lib)\/} =~ f end + %w(CHANGELOG.md CONTRIBUTING.md LICENSE.txt README.md) s.test_files = [] s.executable = 'listen' s.require_path = 'lib' - s.required_ruby_version = '>= 1.9.3' + begin + # TODO: should this be vendored instead? + require 'ruby_dep/travis' + s.required_ruby_version = RubyDep::Travis.new.version_constraint + rescue LoadError + abort "Install 'ruby_dep' gem before building this gem" + end - s.add_dependency 'rb-fsevent', '>= 0.9.3' - s.add_dependency 'rb-inotify', '>= 0.9' + s.add_dependency 'rb-fsevent', '~> 0.9', '>= 0.9.4' + s.add_dependency 'rb-inotify', '~> 0.9', '>= 0.9.7' - s.add_development_dependency 'bundler', '>= 1.3.5' + # Used to show warnings at runtime + s.add_dependency 'ruby_dep', '~> 1.2' + + s.add_development_dependency 'bundler', '~> 1.12' end diff -Nru ruby-listen-3.0.3/README.md ruby-listen-3.1.5/README.md --- ruby-listen-3.0.3/README.md 2015-07-23 10:00:59.000000000 +0000 +++ ruby-listen-3.1.5/README.md 2016-05-18 02:15:20.000000000 +0000 @@ -1,4 +1,8 @@ -### :warning: Listen is [looking for new maintainers](https://groups.google.com/forum/#!topic/guard-dev/2Td0QTvTIsE). Please [contact me](mailto:thibaud@thibaud.gg) if you're interested. +## IMPORTANT: [Ruby 2.1 is officially outdated and unsupported!](https://www.ruby-lang.org/en/news/2016/03/30/ruby-2-1-9-released/) Please upgrade to Ruby 2.2 before installing Listen! + +### (To install for older versions, update Bundler to a prerelease version: `gem install bundler --pre` and Bundler should correctly resolve to an earlier gems for your given Ruby version). + +:exclamation: Listen is currently accepting more maintainers. Please [read this](https://github.com/guard/guard/wiki/Maintainers) if you're interested in joining the team. # Listen @@ -6,19 +10,6 @@ The Listen gem listens to file modifications and notifies you about the changes. -## Known issues / Quickfixes / Workarounds - -*NOTE: TCP functionality has been removed from Listen 3.x - please use Listen -2.x until alternative server and client gems are created/released for 3.x.* - -*NOTE: Ruby 1.9.3 is no longer maintained (and may not work with Listen) - it's best to upgrade to Ruby 2.2.2* - -For other issues, just head over here: https://github.com/guard/listen/wiki/Quickfixes,-known-issues-and-workarounds - -## Tips and Techniques - -Make sure you know these few basic tricks: https://github.com/guard/listen/wiki/Tips-and-Techniques - ## Features * OS-optimized adapters on MRI for Mac OS X 10.6+, Linux, \*BSD and Windows, [more info](#listen-adapters) below. @@ -26,23 +17,23 @@ * You can watch multiple directories. * Regexp-patterns for ignoring paths for more accuracy and speed * Increased change detection accuracy on OS X HFS and VFAT volumes. -* Tested on MRI Ruby environments (2.0+ only) via [Travis CI](https://travis-ci.org/guard/listen), - -NOTE: TCP functionality has been moved to a separate gem (listen-server and listen-client) +* Tested on selected Ruby environments via [Travis CI](https://travis-ci.org/guard/listen). (See [.travis.yml](https:///github.com/guard/listen/master/.travis.yml) for supported/tested Ruby Versions), -NOTES: -- Some filesystems won't work without polling (VM/Vagrant Shared folders, NFS, Samba, sshfs, etc.) -- Specs suite on JRuby and Rubinius aren't reliable on Travis CI, but should work. -- Windows and \*BSD adapter aren't continuously and automaticaly tested. +## Issues / limitations +* Limited support for symlinked directories ([#279](https://github.com/guard/listen/issues/279)): + * Symlinks are always followed ([#25](https://github.com/guard/listen/issues/25)). + * Symlinked directories pointing within a watched directory are not supported ([#273](https://github.com/guard/listen/pull/273)- see [Duplicate directory errors](https://github.com/guard/listen/wiki/Duplicate-directory-errors)). +* No directory/adapter-specific configuration options. +* Support for plugins planned for future. +* TCP functionality was removed in Listen [3.0.0](https://github.com/guard/listen/releases/tag/v3.0.0) ([#319](https://github.com/guard/listen/issues/319), [#218](https://github.com/guard/listen/issues/218)). There are plans to extract this feature to separate gems ([#258](https://github.com/guard/listen/issues/258)), until this is finished, you can use by locking the `listen` gem to version `'~> 2.10'`. +* Some filesystems won't work without polling (VM/Vagrant Shared folders, NFS, Samba, sshfs, etc.). +* Specs suite on JRuby and Rubinius aren't reliable on Travis CI, but should work. +* Windows and \*BSD adapter aren't continuously and automatically tested. +* OSX adapter has some performance limitations ([#342](https://github.com/guard/listen/issues/342)). +* Ruby < 2.2.x is no longer supported - upgrade to Ruby 2.2 or 2.3 -## Pending features / issues - -* symlinked directories aren't fully transparent yet: https://github.com/guard/listen/issues/279 -* Directory/adapter specific configuration options -* Support for plugins - -Pull request or help is very welcome for these. +Pull requests or help is very welcome for these. ## Install @@ -52,7 +43,6 @@ gem 'listen', '~> 3.0' # NOTE: for TCP functionality, use '~> 2.10' for now ``` - ## Usage Call `Listen.to` with either a single directory or multiple directories, then define the "changes" callback in a block. @@ -72,7 +62,7 @@ Listeners can also be easily paused/unpaused: ``` ruby -listener = Listen.to('dir/path/to/listen') { |modified, added, removed| # ... } +listener = Listen.to('dir/path/to/listen') { |modified, added, removed| puts 'handle changes here...' } listener.start listener.paused? # => false @@ -102,13 +92,13 @@ sleep ``` -Note: Ignoring regexp patterns are evaluated against relative paths. +Note: `:ignore` regexp patterns are evaluated against relative paths. -Note: ignoring paths does not improve performance - except when Polling +Note: Ignoring paths does not improve performance, except when Polling ([#274](https://github.com/guard/listen/issues/274)) ### Only -Listen catches all files (less the ignored once) by default, if you want to only listen to a specific type of file (ie: just rb extension) you should use the `only` option/method. +Listen catches all files (less the ignored ones) by default. If you want to only listen to a specific type of file (i.e., just `.rb` extension), you should use the `only` option/method. ``` ruby listener = Listen.to('dir/path/to/listen', only: /\.rb$/) { |modified, added, removed| # ... } @@ -117,7 +107,7 @@ sleep ``` -Note: ':only' regexp patterns are evaluated only against relative **file** paths. +Note: `:only` regexp patterns are evaluated only against relative **file** paths. ## Changes callback @@ -174,14 +164,15 @@ relative: false # Whether changes should be relative to current dir or not # default: false -debug: true # Enable Listen logger - # default: false - polling_fallback_message: 'custom message' # Set a custom polling fallback message (or disable it with false) # default: "Listen will be polling for changes. Learn more at https://github.com/guard/listen#listen-adapters." ``` -Also, setting the environment variable `LISTEN_GEM_DEBUGGING=1` does the same as `debug: true` above. +## Debugging + +Setting the environment variable `LISTEN_GEM_DEBUGGING=1` sets up the INFO level logger, while `LISTEN_GEM_DEBUGGING=2` sets up the DEBUG level logger. + +You can also set `Listen.logger` to a custom logger. ## Listen adapters @@ -202,7 +193,7 @@ ### On Windows -If your are on Windows, it's recommended to use the [`wdm`](https://github.com/Maher4Ever/wdm) adapter instead of polling. +If you are on Windows, it's recommended to use the [`wdm`](https://github.com/Maher4Ever/wdm) adapter instead of polling. Please add the following to your Gemfile: @@ -212,7 +203,7 @@ ### On \*BSD -If your are on \*BSD you can try to use the [`rb-kqueue`](https://github.com/mat813/rb-kqueue) adapter instead of polling. +If you are on \*BSD you can try to use the [`rb-kqueue`](https://github.com/mat813/rb-kqueue) adapter instead of polling. Please add the following to your Gemfile: @@ -234,7 +225,6 @@ See [TROUBLESHOOTING](https://github.com/guard/listen/wiki/Troubleshooting) - ## Performance If Listen seems slow or unresponsive, make sure you're not using the Polling adapter (you should see a warning upon startup if you are). @@ -255,6 +245,8 @@ When in doubt, LISTEN_GEM_DEBUGGING=2 can help discover the actual events and time they happened. +See also [Tips and Techniques](https://github.com/guard/listen/wiki/Tips-and-Techniques). + ## Development * Documentation hosted at [RubyDoc](http://rubydoc.info/github/guard/listen/master/frames). diff -Nru ruby-listen-3.0.3/.rubocop_todo.yml ruby-listen-3.1.5/.rubocop_todo.yml --- ruby-listen-3.0.3/.rubocop_todo.yml 2015-07-23 10:00:59.000000000 +0000 +++ ruby-listen-3.1.5/.rubocop_todo.yml 1970-01-01 00:00:00.000000000 +0000 @@ -1,33 +0,0 @@ -# This configuration was generated by `rubocop --auto-gen-config` -# on 2014-11-11 16:35:31 +0100 using RuboCop version 0.25.0. -# The point is for the user to remove these configuration records -# one by one as the offenses are removed from the code base. -# Note that changes in the inspected code, or installation of new -# versions of RuboCop, may require this file to be generated again. - -# Offense count: 2 -# Configuration parameters: CountComments. -Metrics/ClassLength: - Max: 223 - -# Offense count: 7 -Metrics/CyclomaticComplexity: - Max: 14 - -# Offense count: 27 -# Configuration parameters: CountComments. -Metrics/MethodLength: - Max: 34 - -# Offense count: 5 -Metrics/PerceivedComplexity: - Max: 16 - -# Offense count: 19 -Style/Documentation: - Enabled: false - -# Offense count: 44 -# Configuration parameters: EnforcedStyle, SupportedStyles. -Style/DotPosition: - Enabled: false diff -Nru ruby-listen-3.0.3/.rubocop.yml ruby-listen-3.1.5/.rubocop.yml --- ruby-listen-3.0.3/.rubocop.yml 2015-07-23 10:00:59.000000000 +0000 +++ ruby-listen-3.1.5/.rubocop.yml 2016-05-18 02:15:20.000000000 +0000 @@ -1,13 +1,13 @@ inherit_from: - vendor/hound/config/style_guides/ruby.yml - - .rubocop_todo.yml # Rails cops AllCops: - RunRailsCops: true + RunRailsCops: false # Files you want to exclude AllCops: + TargetRubyVersion: 2.2 Exclude: - db/schema.rb - Gemfile diff -Nru ruby-listen-3.0.3/spec/acceptance/listen_spec.rb ruby-listen-3.1.5/spec/acceptance/listen_spec.rb --- ruby-listen-3.0.3/spec/acceptance/listen_spec.rb 2015-07-23 10:00:59.000000000 +0000 +++ ruby-listen-3.1.5/spec/acceptance/listen_spec.rb 2016-05-18 02:15:20.000000000 +0000 @@ -65,7 +65,6 @@ context 'with default ignore options' do context 'with nothing in listen dir' do - it { is_expected.to process_addition_of('file.rb') } it { is_expected.to process_addition_of('.hidden') } diff -Nru ruby-listen-3.0.3/spec/lib/listen/adapter/base_spec.rb ruby-listen-3.1.5/spec/lib/listen/adapter/base_spec.rb --- ruby-listen-3.0.3/spec/lib/listen/adapter/base_spec.rb 2015-07-23 10:00:59.000000000 +0000 +++ ruby-listen-3.1.5/spec/lib/listen/adapter/base_spec.rb 2016-05-18 02:15:20.000000000 +0000 @@ -1,5 +1,4 @@ RSpec.describe Listen::Adapter::Base do - class FakeAdapter < described_class def initialize(config) @my_callbacks = {} diff -Nru ruby-listen-3.0.3/spec/lib/listen/adapter/config_spec.rb ruby-listen-3.1.5/spec/lib/listen/adapter/config_spec.rb --- ruby-listen-3.0.3/spec/lib/listen/adapter/config_spec.rb 2015-07-23 10:00:59.000000000 +0000 +++ ruby-listen-3.1.5/spec/lib/listen/adapter/config_spec.rb 2016-05-18 02:15:20.000000000 +0000 @@ -16,6 +16,10 @@ let(:path1) { fake_path('/real/path1', realpath: real_path1) } let(:path2) { fake_path('/real/path2', realpath: real_path2) } + let(:current_path) do + fake_path('/real/current_path', realpath: real_current_path) + end + let(:symlinked_dir1) { fake_path('symlinked_dir1', realpath: real_path1) } let(:symlinked_dir2) { fake_path('symlinked_dir1', realpath: real_path2) } @@ -23,6 +27,7 @@ # something useful) let(:real_path1) { fake_path('/real/path1') } let(:real_path2) { fake_path('/real/path2') } + let(:real_current_path) { fake_path('/real/current_path') } before do allow(Pathname).to receive(:new) do |*args| @@ -40,6 +45,11 @@ allow(Pathname).to receive(:new).with('symlinked_dir2'). and_return(symlinked_dir2) + + allow(Dir).to receive(:pwd).and_return('/real/current_path') + + allow(Pathname).to receive(:new). + with('/real/current_path').and_return(current_path) end describe '#initialize' do @@ -53,7 +63,7 @@ end context 'when not resolved' do - let(:directories) { ['symlinked_dir1', 'symlinked_dir2'] } + let(:directories) { %w(symlinked_dir1 symlinked_dir2) } it 'returns array of resolved pathnames' do expect(subject.directories).to eq([real_path1, real_path2]) end @@ -73,7 +83,10 @@ end context 'with no directories' do - pending 'implement me' + let(:directories) {} + it 'returns the current path in array' do + expect(subject.directories).to eq([real_current_path]) + end end end diff -Nru ruby-listen-3.0.3/spec/lib/listen/adapter/darwin_spec.rb ruby-listen-3.1.5/spec/lib/listen/adapter/darwin_spec.rb --- ruby-listen-3.0.3/spec/lib/listen/adapter/darwin_spec.rb 2015-07-23 10:00:59.000000000 +0000 +++ ruby-listen-3.1.5/spec/lib/listen/adapter/darwin_spec.rb 2016-05-18 02:15:20.000000000 +0000 @@ -9,9 +9,35 @@ describe 'class' do subject { described_class } - if darwin? + context 'on darwin 13.0 (OS X Mavericks)' do + before do + allow(RbConfig::CONFIG).to receive(:[]).and_return('darwin13.0') + end + it { should be_usable } - else + end + + context 'on darwin10.0 (OS X Snow Leopard)' do + before do + allow(RbConfig::CONFIG).to receive(:[]).and_return('darwin10.0') + end + + context 'with rb-fsevent > 0.9.4' do + before { stub_const('FSEvent::VERSION', '0.9.6') } + it 'shows a warning and should not be usable' do + expect(Kernel).to receive(:warn) + expect(subject).to_not be_usable + end + end + + context 'with rb-fsevent <= 0.9.4' do + before { stub_const('FSEvent::VERSION', '0.9.4') } + it { should be_usable } + end + end + + context 'on another platform (linux)' do + before { allow(RbConfig::CONFIG).to receive(:[]).and_return('linux') } it { should_not be_usable } end end @@ -134,9 +160,7 @@ Timeout.timeout(max_test_time) do subject.start - until started.size == expectations.size - sleep 0.1 - end + sleep 0.1 until started.size == expectations.size end running << started.pop until started.empty? diff -Nru ruby-listen-3.0.3/spec/lib/listen/adapter/linux_spec.rb ruby-listen-3.1.5/spec/lib/listen/adapter/linux_spec.rb --- ruby-listen-3.0.3/spec/lib/listen/adapter/linux_spec.rb 2015-07-23 10:00:59.000000000 +0000 +++ ruby-listen-3.1.5/spec/lib/listen/adapter/linux_spec.rb 2016-05-18 02:15:20.000000000 +0000 @@ -59,7 +59,6 @@ let(:adapter_options) { { events: [:recursive, :close_write] } } before do - allow(Kernel).to receive(:require).with('rb-inotify') fake_worker = double(:fake_worker) events = [:recursive, :close_write] allow(fake_worker).to receive(:watch).with('/foo/dir1', *events) @@ -78,6 +77,7 @@ allow(Listen::Change).to receive(:new).with(config, record). and_return(snapshot) + allow(subject).to receive(:require).with('rb-inotify') subject.configure end @@ -124,5 +124,45 @@ end end end + + describe '#stop' do + let(:fake_worker) { double(:fake_worker, close: true) } + let(:directories) { [dir1] } + let(:adapter_options) { { events: [:recursive, :close_write] } } + + before do + allow(config).to receive(:directories).and_return(directories) + allow(config).to receive(:adapter_options).and_return(adapter_options) + end + + context 'when configured' do + before do + events = [:recursive, :close_write] + allow(fake_worker).to receive(:watch).with('/foo/dir1', *events) + + fake_notifier = double(:fake_notifier, new: fake_worker) + stub_const('INotify::Notifier', fake_notifier) + + allow(config).to receive(:queue).and_return(queue) + allow(config).to receive(:silencer).and_return(silencer) + + allow(subject).to receive(:require).with('rb-inotify') + subject.configure + end + + it 'stops the worker' do + expect(fake_worker).to receive(:close) + subject.stop + end + end + + context 'when not even initialized' do + it 'does not crash' do + expect do + subject.stop + end.to_not raise_error + end + end + end end end diff -Nru ruby-listen-3.0.3/spec/lib/listen/adapter_spec.rb ruby-listen-3.1.5/spec/lib/listen/adapter_spec.rb --- ruby-listen-3.0.3/spec/lib/listen/adapter_spec.rb 2015-07-23 10:00:59.000000000 +0000 +++ ruby-listen-3.1.5/spec/lib/listen/adapter_spec.rb 2016-05-18 02:15:20.000000000 +0000 @@ -1,5 +1,4 @@ RSpec.describe Listen::Adapter do - let(:listener) { instance_double(Listen::Listener, options: {}) } before do allow(Listen::Adapter::BSD).to receive(:usable?) { false } diff -Nru ruby-listen-3.0.3/spec/lib/listen/backend_spec.rb ruby-listen-3.1.5/spec/lib/listen/backend_spec.rb --- ruby-listen-3.0.3/spec/lib/listen/backend_spec.rb 2015-07-23 10:00:59.000000000 +0000 +++ ruby-listen-3.1.5/spec/lib/listen/backend_spec.rb 2016-05-18 02:15:20.000000000 +0000 @@ -73,7 +73,7 @@ describe '#stop' do it 'stops the adapter' do - # TODO: does nothing for now + expect(adapter).to receive(:stop) subject.stop end end diff -Nru ruby-listen-3.0.3/spec/lib/listen/change_spec.rb ruby-listen-3.1.5/spec/lib/listen/change_spec.rb --- ruby-listen-3.0.3/spec/lib/listen/change_spec.rb 2015-07-23 10:00:59.000000000 +0000 +++ ruby-listen-3.1.5/spec/lib/listen/change_spec.rb 2016-05-18 02:15:20.000000000 +0000 @@ -42,7 +42,6 @@ end context 'with unknown change' do - it 'calls Listen::File#change' do expect(Listen::File).to receive(:change).with(record, 'file.rb') subject.invalidate(:file, 'file.rb', {}) diff -Nru ruby-listen-3.0.3/spec/lib/listen/directory_spec.rb ruby-listen-3.1.5/spec/lib/listen/directory_spec.rb --- ruby-listen-3.0.3/spec/lib/listen/directory_spec.rb 2015-07-23 10:00:59.000000000 +0000 +++ ruby-listen-3.1.5/spec/lib/listen/directory_spec.rb 2016-05-18 02:15:20.000000000 +0000 @@ -11,6 +11,16 @@ instance_double(::File::Stat, name, defaults.merge(options)) end + def fake_children(ex, dir, *args, &block) + if block_given? + ex.send(:allow, dir).to receive(:children, &block) + else + ex.send(:allow, dir).to receive(:children).and_return(*args) + end + ex.send(:allow, dir).to receive(:exist?).and_return(true) + ex.send(:allow, dir).to receive(:directory?).and_return(true) + end + let(:dir) { double(:dir) } let(:file) { fake_path('file.rb') } let(:file2) { fake_path('file2.rb') } @@ -53,7 +63,7 @@ end context 'with empty dir' do - before { allow(dir).to receive(:children) { [] } } + before { fake_children(self, dir, []) } it 'sets record dir path' do expect(record).to receive(:add_dir).with('.') @@ -71,9 +81,8 @@ end context 'when subdir is removed' do - before do - allow(dir).to receive(:children) { [file] } - + before do + fake_children(self, dir, [file]) allow(::File).to receive(:lstat).with('file.rb'). and_return(fake_file_stat('file.rb')) end @@ -88,7 +97,7 @@ context 'when file.rb removed' do before do - allow(dir).to receive(:children) { [subdir] } + fake_children(self, dir, [subdir]) allow(::File).to receive(:lstat).with('subdir'). and_return(fake_dir_stat('subdir')) @@ -100,9 +109,26 @@ end end + context 'when file.rb no longer exists after scan' do + before do + fake_children(self, dir, [file], [file2]) + + allow(::File).to receive(:lstat).with('file.rb'). + and_raise(Errno::ENOENT) + + allow(::File).to receive(:lstat).with('file2.rb'). + and_return(fake_file_stat('file2.rb')) + end + + it 'rescans' do + expect(snapshot).to receive(:invalidate).with(:file, 'file2.rb', {}) + described_class.scan(snapshot, '.', options) + end + end + context 'when file2.rb is added' do before do - allow(dir).to receive(:children) { [file, file2, subdir] } + fake_children(self, dir, [file, file2, subdir]) allow(::File).to receive(:lstat).with('file.rb'). and_return(fake_file_stat('file.rb')) @@ -125,7 +151,7 @@ let(:record_entries) { {} } context 'with non-existing dir path' do - before { allow(dir).to receive(:children) { fail Errno::ENOENT } } + before { fake_children(self, dir) { fail Errno::ENOENT } } it 'reports no changes' do expect(snapshot).to_not receive(:invalidate) @@ -139,7 +165,7 @@ end context 'when network share is disconnected' do - before { allow(dir).to receive(:children) { fail Errno::EHOSTDOWN } } + before { fake_children(self, dir) { fail Errno::EHOSTDOWN } } it 'reports no changes' do expect(snapshot).to_not receive(:invalidate) @@ -154,7 +180,7 @@ context 'with file.rb in dir' do before do - allow(dir).to receive(:children) { [file] } + fake_children(self, dir, [file]) allow(::File).to receive(:lstat).with('file.rb'). and_return(fake_file_stat('file.rb')) @@ -185,9 +211,7 @@ end context 'with empty dir' do - before do - allow(dir).to receive(:children) { [] } - end + before { fake_children(self, dir, []) } it 'snapshots changes for file & subdir path' do expect(snapshot).to receive(:invalidate).with(:file, 'file.rb', {}) @@ -203,7 +227,7 @@ let(:subdir2) { fake_path('subdir2', children: []) } before do - allow(dir).to receive(:children) { [subdir2] } + fake_children(self, dir, [subdir2]) allow(subdir2).to receive(:relative_path_from).with(dir) { 'subdir2' } allow(::File).to receive(:lstat).with('subdir2'). @@ -229,7 +253,7 @@ context 'with non-existing dir' do before do - allow(dir).to receive(:children) { fail Errno::ENOENT } + fake_children(self, dir) { fail Errno::ENOENT } end it 'reports no changes' do @@ -240,8 +264,8 @@ context 'with subdir present in dir' do before do - allow(dir).to receive(:children) { [subdir] } - allow(subdir).to receive(:children) { [] } + fake_children(self, dir, [subdir]) + fake_children(self, subdir, []) allow(::File).to receive(:lstat).with('subdir'). and_return(fake_dir_stat('subdir')) end diff -Nru ruby-listen-3.0.3/spec/lib/listen/event/loop_spec.rb ruby-listen-3.1.5/spec/lib/listen/event/loop_spec.rb --- ruby-listen-3.0.3/spec/lib/listen/event/loop_spec.rb 2015-07-23 10:00:59.000000000 +0000 +++ ruby-listen-3.1.5/spec/lib/listen/event/loop_spec.rb 2016-05-18 02:15:20.000000000 +0000 @@ -48,7 +48,7 @@ allow(subject).to receive(:_nice_error) do |ex| indent = "\n -- " - backtrace = ex.backtrace.reject { |line| line =~ /\/gems\// } + backtrace = ex.backtrace.reject { |line| line =~ %r{\/gems\/} } fail "error called: #{ex}: #{indent}#{backtrace * indent}" end end diff -Nru ruby-listen-3.0.3/spec/lib/listen/event/processor_spec.rb ruby-listen-3.1.5/spec/lib/listen/event/processor_spec.rb --- ruby-listen-3.0.3/spec/lib/listen/event/processor_spec.rb 2015-07-23 10:00:59.000000000 +0000 +++ ruby-listen-3.1.5/spec/lib/listen/event/processor_spec.rb 2016-05-18 02:15:20.000000000 +0000 @@ -61,9 +61,9 @@ it 'does not sleep' do expect(config).to_not receive(:sleep) - t = Time.now + t = Time.now.to_f subject.loop_for(1) - diff = Time.now.to_f - t.to_f + diff = Time.now.to_f - t expect(diff).to be < 0.01 end end diff -Nru ruby-listen-3.0.3/spec/lib/listen/file_spec.rb ruby-listen-3.1.5/spec/lib/listen/file_spec.rb --- ruby-listen-3.0.3/spec/lib/listen/file_spec.rb 2015-07-23 10:00:59.000000000 +0000 +++ ruby-listen-3.1.5/spec/lib/listen/file_spec.rb 2016-05-18 02:15:20.000000000 +0000 @@ -108,17 +108,17 @@ let(:record_mtime) { stat_mtime.to_f } context 'with accurate stat times' do - let(:stat_mtime) { Time.at(1_401_235_714.123) } - let(:stat_atime) { Time.at(1_401_235_714.123) } - let(:stat_ctime) { Time.at(1_401_235_714.123) } + let(:stat_mtime) { Time.at(1_401_235_714.123).utc } + let(:stat_atime) { Time.at(1_401_235_714.123).utc } + let(:stat_ctime) { Time.at(1_401_235_714.123).utc } let(:record_mtime) { stat_mtime.to_f } it { should be_nil } end context 'with inaccurate stat times' do - let(:stat_mtime) { Time.at(1_401_235_714.0) } - let(:stat_atime) { Time.at(1_401_235_714.0) } - let(:stat_ctime) { Time.at(1_401_235_714.0) } + let(:stat_mtime) { Time.at(1_401_235_714.0).utc } + let(:stat_atime) { Time.at(1_401_235_714.0).utc } + let(:stat_ctime) { Time.at(1_401_235_714.0).utc } let(:record_mtime) { stat_mtime.to_f } @@ -127,7 +127,7 @@ # NOTE: if real mtime is ???14.99, the # saved mtime is ???14.0 - let(:now) { Time.at(1_401_235_716.00) } + let(:now) { Time.at(1_401_235_716.00).utc } it { should be_nil } end @@ -136,7 +136,7 @@ # so saved mtime at ???14.0 means it could be # ???14.999, so ???15.999 could still be within 1 second # range - let(:now) { Time.at(1_401_235_715.999999) } + let(:now) { Time.at(1_401_235_715.999999).utc } before { allow(Time).to receive(:now) { now } } @@ -222,23 +222,23 @@ subject { Listen::File.inaccurate_mac_time?(stat) } context 'with no accurate times' do - let(:mtime) { Time.at(1_234_567.0) } - let(:atime) { Time.at(1_234_567.0) } - let(:ctime) { Time.at(1_234_567.0) } + let(:mtime) { Time.at(1_234_567.0).utc } + let(:atime) { Time.at(1_234_567.0).utc } + let(:ctime) { Time.at(1_234_567.0).utc } it { should be_truthy } end context 'with all accurate times' do - let(:mtime) { Time.at(1_234_567.89) } - let(:atime) { Time.at(1_234_567.89) } - let(:ctime) { Time.at(1_234_567.89) } + let(:mtime) { Time.at(1_234_567.89).utc } + let(:atime) { Time.at(1_234_567.89).utc } + let(:ctime) { Time.at(1_234_567.89).utc } it { should be_falsey } end context 'with one accurate time' do - let(:mtime) { Time.at(1_234_567.0) } - let(:atime) { Time.at(1_234_567.89) } - let(:ctime) { Time.at(1_234_567.0) } + let(:mtime) { Time.at(1_234_567.0).utc } + let(:atime) { Time.at(1_234_567.89).utc } + let(:ctime) { Time.at(1_234_567.0).utc } it { should be_falsey } end end diff -Nru ruby-listen-3.0.3/spec/lib/listen/listener/config_spec.rb ruby-listen-3.1.5/spec/lib/listen/listener/config_spec.rb --- ruby-listen-3.0.3/spec/lib/listen/listener/config_spec.rb 2015-07-23 10:00:59.000000000 +0000 +++ ruby-listen-3.1.5/spec/lib/listen/listener/config_spec.rb 2016-05-18 02:15:20.000000000 +0000 @@ -12,7 +12,7 @@ it 'extracts adapter options' do klass = Class.new do - DEFAULTS = { latency: 5.4321 } + DEFAULTS = { latency: 5.4321 }.freeze end expected = { latency: 1.234 } expect(subject.adapter_instance_options(klass)).to eq(expected) diff -Nru ruby-listen-3.0.3/spec/lib/listen/listener_spec.rb ruby-listen-3.1.5/spec/lib/listen/listener_spec.rb --- ruby-listen-3.0.3/spec/lib/listen/listener_spec.rb 2015-07-23 10:00:59.000000000 +0000 +++ ruby-listen-3.1.5/spec/lib/listen/listener_spec.rb 2016-05-18 02:15:20.000000000 +0000 @@ -1,7 +1,6 @@ include Listen RSpec.describe Listener do - let(:realdir1) { fake_path('/foo/dir1', children: []) } let(:realdir2) { fake_path('/foo/dir2', children: []) } @@ -85,8 +84,12 @@ context 'with a block' do let(:myblock) { instance_double(Proc) } - let(:block) { proc { myblock.call } } - subject { described_class.new('dir1', &block) } + let(:block) { proc { myblock.call } } + subject do + described_class.new('dir1') do |*args| + myblock.call(*args) + end + end it 'passes the block to the event processor' do allow(Event::Config).to receive(:new) do |*_args, &some_block| @@ -104,7 +107,7 @@ it 'passes directories to backend' do allow(Backend).to receive(:new). - with(['dir1', 'dir2'], anything, anything, anything). + with(%w(dir1 dir2), anything, anything, anything). and_return(backend) subject end @@ -137,13 +140,55 @@ allow(backend).to receive(:start) allow(processor).to receive(:setup) allow(processor).to receive(:resume) - subject.start end - it 'terminates' do - allow(backend).to receive(:stop) - allow(processor).to receive(:teardown) - subject.stop + context 'when fully started' do + before do + subject.start + end + + it 'terminates' do + allow(backend).to receive(:stop) + allow(processor).to receive(:teardown) + subject.stop + end + end + + context 'when frontend is ready' do + before do + subject.transition :backend_started + subject.transition :frontend_ready + end + + it 'terminates' do + allow(backend).to receive(:stop) + allow(processor).to receive(:teardown) + subject.stop + end + end + + context 'when only backend is already started' do + before do + subject.transition :backend_started + end + + it 'terminates' do + allow(backend).to receive(:stop) + allow(processor).to receive(:teardown) + subject.stop + end + end + + context 'when only initialized' do + before do + subject + end + + it 'terminates' do + allow(backend).to receive(:stop) + allow(processor).to receive(:teardown) + subject.stop + end end end @@ -304,17 +349,4 @@ end end end - - describe 'processing changes' do - before do - allow(backend).to receive(:start) - end - end - - context 'when listener is stopped' do - before do - subject.stop - allow(silencer).to receive(:silenced?) { true } - end - end end diff -Nru ruby-listen-3.0.3/spec/lib/listen/record_spec.rb ruby-listen-3.1.5/spec/lib/listen/record_spec.rb --- ruby-listen-3.0.3/spec/lib/listen/record_spec.rb 2015-07-23 10:00:59.000000000 +0000 +++ ruby-listen-3.1.5/spec/lib/listen/record_spec.rb 2016-05-18 02:15:20.000000000 +0000 @@ -32,7 +32,7 @@ end def symlink(hash_or_dir) - if String === hash_or_dir + if hash_or_dir.is_a?(String) allow(::File).to receive(:realpath).with(hash_or_dir). and_return(hash_or_dir) else @@ -277,14 +277,14 @@ real_directory('/dir/dir2' => []) end - it 'builds record' do + it 'builds record' do record.build expect(record_tree(record)). to eq( 'dir1' => {}, 'dir1/foo' => { 'bar' => { mtime: 2.3, mode: 0755 } }, 'dir2' => {}, - ) + ) end end @@ -300,7 +300,7 @@ allow(::File).to receive(:realpath) { |path| path } end - it 'builds record' do + it 'builds record' do record.build expect(record_tree(record)). to eq( @@ -309,7 +309,7 @@ 'dir1/foo/bar' => {}, 'dir1/foo/baz' => {}, 'dir2' => {}, - ) + ) end end diff -Nru ruby-listen-3.0.3/spec/lib/listen/silencer_spec.rb ruby-listen-3.1.5/spec/lib/listen/silencer_spec.rb --- ruby-listen-3.0.3/spec/lib/listen/silencer_spec.rb 2015-07-23 10:00:59.000000000 +0000 +++ ruby-listen-3.1.5/spec/lib/listen/silencer_spec.rb 2016-05-18 02:15:20.000000000 +0000 @@ -61,7 +61,7 @@ end context 'when ignoring foo/bar* and *.pid' do - let(:options) { { ignore: [/^foo\/bar/, /\.pid$/] } } + let(:options) { { ignore: [%r{^foo\/bar}, /\.pid$/] } } it { should_not accept(:file, 'foo/bar/baz') } it { should_not accept(:file, 'foo.pid') } end @@ -79,7 +79,7 @@ end context 'when accepting only foo/* and *.txt' do - let(:options) { { only: [/^foo\//, /\.txt$/] } } + let(:options) { { only: [%r{^foo\/}, /\.txt$/] } } it { should accept(:file, 'foo/bar.rb') } it { should accept(:file, 'bar.txt') } it { should_not accept(:file, 'bar/baz.rb') } diff -Nru ruby-listen-3.0.3/spec/support/acceptance_helper.rb ruby-listen-3.1.5/spec/support/acceptance_helper.rb --- ruby-listen-3.0.3/spec/support/acceptance_helper.rb 2015-07-23 10:00:59.000000000 +0000 +++ ruby-listen-3.1.5/spec/support/acceptance_helper.rb 2016-05-18 02:15:20.000000000 +0000 @@ -5,7 +5,6 @@ queued_modification: :modified, queued_addition: :added }.each do |description, type| - RSpec::Matchers.define "process_#{description}_of".to_sym do |expected| match do |actual| # Use cases: @@ -94,7 +93,7 @@ def _sleep_until_next_second(path) Listen::File.inaccurate_mac_time?(path) - t = Time.now + t = Time.now.utc diff = t.to_f - t.to_i sleep(1.05 - diff) @@ -165,7 +164,7 @@ @timed_changes = TimedChanges.new if callback - @listener = Listen.send(*args) do |modified, added, removed| + @listener = Listen.send(*args) do |modified, added, removed| # Add changes to trigger frozen Hash error, making sure lag is enough _add_changes(:modified, modified, changes) _add_changes(:added, added, changes) @@ -190,7 +189,6 @@ sleep lag @timed_changes.allow_changes(reset_queue) do - yield # Polling sleep (default: 1s) @@ -201,7 +199,6 @@ # Lag should include: # 0.1s - 0.2s if the test needs Listener queue to be processed # 0.1s in case the system is busy - # 0.1s - for celluloid overhead and scheduling sleep lag end @@ -228,9 +225,6 @@ freeze_offset = @timed_changes.freeze_offset msg = "Changes took #{change_offset}s (allowed lag: #{freeze_offset})s" - - # Use STDERR (workaround for Celluloid, since it catches abort) - STDERR.puts msg abort(msg) end @@ -238,8 +232,8 @@ changes.map do |change| unfrozen_copy = change.dup [@paths].flatten.each do |path| - sub = path.sub(/\/$/, '').to_s - unfrozen_copy.gsub!(/^#{sub}\//, '') + sub = path.sub(%r{\/$}, '').to_s + unfrozen_copy.gsub!(%r{^#{sub}\/}, '') end unfrozen_copy end @@ -258,9 +252,8 @@ # separate the events or Darwin and Polling # will detect only the :added event # - # (This is because both use directory scanning - # through Celluloid tasks, which may not kick in - # time before the next filesystem change) + # (This is because both use directory scanning which may not kick in time + # before the next filesystem change) # # The minimum for this is the time it takes between a syscall # changing the filesystem ... and ... an async diff -Nru ruby-listen-3.0.3/.travis.yml ruby-listen-3.1.5/.travis.yml --- ruby-listen-3.0.3/.travis.yml 2015-07-23 10:00:59.000000000 +0000 +++ ruby-listen-3.1.5/.travis.yml 2016-05-18 02:15:20.000000000 +0000 @@ -1,9 +1,15 @@ language: ruby bundler_args: --without development +before_install: + - gem install bundler + - gem update bundler + - gem install ruby_dep + - gem update ruby_dep rvm: - - 2.2.2 + - 2.2.4 - jruby-head - rbx-2 + - jruby-9.0.5.0 matrix: allow_failures: - rvm: jruby-head @@ -16,6 +22,8 @@ os: - linux - osx +osx_image: xcode7.1 env: - - LISTEN_TESTS_DEFAULT_LAG=0.8 + # TODO: 0.8 is enough on Linux, but 2 seems needed for Travis/OSX + - LISTEN_TESTS_DEFAULT_LAG=2 sudo: false diff -Nru ruby-listen-3.0.3/vendor/hound/config/style_guides/ruby.yml ruby-listen-3.1.5/vendor/hound/config/style_guides/ruby.yml --- ruby-listen-3.0.3/vendor/hound/config/style_guides/ruby.yml 2015-07-23 10:00:59.000000000 +0000 +++ ruby-listen-3.1.5/vendor/hound/config/style_guides/ruby.yml 2016-05-18 02:15:20.000000000 +0000 @@ -1,259 +1,243 @@ AllCops: Exclude: - - db/schema.rb - -AccessorMethodName: - Enabled: false - -ActionFilter: - Enabled: false - -Alias: - Enabled: false - -ArrayJoin: - Enabled: false - -AsciiComments: - Enabled: false - -AsciiIdentifiers: - Enabled: false - -Attr: - Enabled: false - -BlockNesting: - Enabled: false - -CaseEquality: - Enabled: false - -CharacterLiteral: - Enabled: false - -ClassAndModuleChildren: - Enabled: false - -ClassLength: - Enabled: false - -ClassVars: - Enabled: false - + - "vendor/**/*" + - "db/schema.rb" + UseCache: false Style/CollectionMethods: + Description: Preferred collection methods. + StyleGuide: https://github.com/bbatsov/ruby-style-guide#map-find-select-reduce-size + Enabled: true PreferredMethods: - find: detect - reduce: inject collect: map + collect!: map! + find: detect find_all: select - -ColonMethodCall: - Enabled: false - -CommentAnnotation: - Enabled: false - -CyclomaticComplexity: - Enabled: false - -Delegate: - Enabled: false - -DeprecatedHashMethods: - Enabled: false - -Documentation: - Enabled: false - -DotPosition: + reduce: inject +Style/DotPosition: + Description: Checks the position of the dot in multi-line method calls. + StyleGuide: https://github.com/bbatsov/ruby-style-guide#consistent-multi-line-chains + Enabled: true EnforcedStyle: trailing - -DoubleNegation: - Enabled: false - -EachWithObject: - Enabled: false - -EmptyLiteral: - Enabled: false - -Encoding: - Enabled: false - -EvenOdd: - Enabled: false - -FileName: - Enabled: false - -FlipFlop: - Enabled: false - -FormatString: - Enabled: false - -GlobalVars: - Enabled: false - -GuardClause: - Enabled: false - -IfUnlessModifier: - Enabled: false - -IfWithSemicolon: - Enabled: false - -InlineComment: - Enabled: false - -Lambda: - Enabled: false - -LambdaCall: - Enabled: false - -LineEndConcatenation: - Enabled: false - -LineLength: - Max: 80 - -MethodLength: - Enabled: false - -ModuleFunction: - Enabled: false - -NegatedIf: - Enabled: false - -NegatedWhile: - Enabled: false - -Next: - Enabled: false - -NilComparison: - Enabled: false - -Not: - Enabled: false - -NumericLiterals: - Enabled: false - -OneLineConditional: - Enabled: false - -OpMethod: - Enabled: false - -ParameterLists: - Enabled: false - -PercentLiteralDelimiters: - Enabled: false - -PerlBackrefs: - Enabled: false - -PredicateName: + SupportedStyles: + - leading + - trailing +Style/FileName: + Description: Use snake_case for source file names. + StyleGuide: https://github.com/bbatsov/ruby-style-guide#snake-case-files + Enabled: false + Exclude: [] +Style/GuardClause: + Description: Check for conditionals that can be replaced with guard clauses + StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-nested-conditionals + Enabled: false + MinBodyLength: 1 +Style/IfUnlessModifier: + Description: Favor modifier if/unless usage when you have a single-line body. + StyleGuide: https://github.com/bbatsov/ruby-style-guide#if-as-a-modifier + Enabled: false + MaxLineLength: 80 +Style/OptionHash: + Description: Don't use option hashes when you can use keyword arguments. + Enabled: false +Style/PercentLiteralDelimiters: + Description: Use `%`-literal delimiters consistently + StyleGuide: https://github.com/bbatsov/ruby-style-guide#percent-literal-braces + Enabled: false + PreferredDelimiters: + "%": "()" + "%i": "()" + "%q": "()" + "%Q": "()" + "%r": "{}" + "%s": "()" + "%w": "()" + "%W": "()" + "%x": "()" +Style/PredicateName: + Description: Check the names of predicate methods. + StyleGuide: https://github.com/bbatsov/ruby-style-guide#bool-methods-qmark + Enabled: true + NamePrefix: + - is_ + - has_ + - have_ NamePrefixBlacklist: - is_ - -Proc: - Enabled: false - -RaiseArgs: - Enabled: false - -RegexpLiteral: - Enabled: false - -SelfAssignment: - Enabled: false - -SingleLineBlockParams: - Enabled: false - -SingleLineMethods: - Enabled: false - -SignalException: - Enabled: false - -SpecialGlobalVars: - Enabled: false - -StringLiterals: + Exclude: + - spec/**/* +Style/RaiseArgs: + Description: Checks the arguments passed to raise/fail. + StyleGuide: https://github.com/bbatsov/ruby-style-guide#exception-class-messages + Enabled: false + EnforcedStyle: exploded + SupportedStyles: + - compact + - exploded +Style/SignalException: + Description: Checks for proper usage of fail and raise. + StyleGuide: https://github.com/bbatsov/ruby-style-guide#fail-method + Enabled: false + EnforcedStyle: semantic + SupportedStyles: + - only_raise + - only_fail + - semantic +Style/SingleLineBlockParams: + Description: Enforces the names of some block params. + StyleGuide: https://github.com/bbatsov/ruby-style-guide#reduce-blocks + Enabled: false + Methods: + - reduce: + - a + - e + - inject: + - a + - e +Style/SingleLineMethods: + Description: Avoid single-line methods. + StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-single-line-methods + Enabled: false + AllowIfMethodIsEmpty: true +Style/StringLiterals: + Description: Checks if uses of quotes match the configured preference. + StyleGuide: https://github.com/bbatsov/ruby-style-guide#consistent-string-literals + Enabled: true EnforcedStyle: double_quotes - -VariableInterpolation: - Enabled: false - -TrailingComma: - Enabled: false - -TrivialAccessors: - Enabled: false - -VariableInterpolation: - Enabled: false - -WhenThen: - Enabled: false - -WhileUntilModifier: - Enabled: false - -WordArray: - Enabled: false - -# Lint - -AmbiguousOperator: - Enabled: false - -AmbiguousRegexpLiteral: - Enabled: false - -AssignmentInCondition: - Enabled: false - -ConditionPosition: - Enabled: false - -DeprecatedClassMethods: - Enabled: false - -ElseLayout: - Enabled: false - -HandleExceptions: - Enabled: false - -InvalidCharacterLiteral: - Enabled: false - -LiteralInCondition: - Enabled: false - -LiteralInInterpolation: - Enabled: false - -Loop: - Enabled: false - -ParenthesesAsGroupedExpression: - Enabled: false - -RequireParentheses: + SupportedStyles: + - single_quotes + - double_quotes +Style/StringLiteralsInInterpolation: + Description: Checks if uses of quotes inside expressions in interpolated strings + match the configured preference. + Enabled: true + EnforcedStyle: single_quotes + SupportedStyles: + - single_quotes + - double_quotes +Style/TrailingCommaInArguments: + Description: 'Checks for trailing comma in argument lists.' + StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-trailing-array-commas' + Enabled: false + EnforcedStyleForMultiline: no_comma + SupportedStyles: + - comma + - consistent_comma + - no_comma +Style/TrailingCommaInLiteral: + Description: 'Checks for trailing comma in array and hash literals.' + StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-trailing-array-commas' + Enabled: false + EnforcedStyleForMultiline: no_comma + SupportedStyles: + - comma + - consistent_comma + - no_comma +Metrics/AbcSize: + Description: A calculated magnitude based on number of assignments, branches, and + conditions. + Enabled: false + Max: 15 +Metrics/ClassLength: + Description: Avoid classes longer than 100 lines of code. + Enabled: false + CountComments: false + Max: 100 +Metrics/ModuleLength: + CountComments: false + Max: 100 + Description: Avoid modules longer than 100 lines of code. + Enabled: false +Metrics/CyclomaticComplexity: + Description: A complexity metric that is strongly correlated to the number of test + cases needed to validate a method. + Enabled: false + Max: 6 +Metrics/MethodLength: + Description: Avoid methods longer than 10 lines of code. + StyleGuide: https://github.com/bbatsov/ruby-style-guide#short-methods + Enabled: false + CountComments: false + Max: 10 +Metrics/ParameterLists: + Description: Avoid parameter lists longer than three or four parameters. + StyleGuide: https://github.com/bbatsov/ruby-style-guide#too-many-params + Enabled: false + Max: 5 + CountKeywordArgs: true +Metrics/PerceivedComplexity: + Description: A complexity metric geared towards measuring complexity for a human + reader. + Enabled: false + Max: 7 +Lint/AssignmentInCondition: + Description: Don't use assignment in conditions. + StyleGuide: https://github.com/bbatsov/ruby-style-guide#safe-assignment-in-condition + Enabled: false + AllowSafeAssignment: true +Style/InlineComment: + Description: Avoid inline comments. + Enabled: false +Style/AccessorMethodName: + Description: Check the naming of accessor methods for get_/set_. + Enabled: false +Style/Alias: + Description: Use alias_method instead of alias. + StyleGuide: https://github.com/bbatsov/ruby-style-guide#alias-method + Enabled: false +Style/Documentation: + Description: Document classes and non-namespace modules. + Enabled: false +Style/DoubleNegation: + Description: Checks for uses of double negation (!!). + StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-bang-bang + Enabled: false +Style/EachWithObject: + Description: Prefer `each_with_object` over `inject` or `reduce`. + Enabled: false +Style/EmptyLiteral: + Description: Prefer literals to Array.new/Hash.new/String.new. + StyleGuide: https://github.com/bbatsov/ruby-style-guide#literal-array-hash + Enabled: false +Style/ModuleFunction: + Description: Checks for usage of `extend self` in modules. + StyleGuide: https://github.com/bbatsov/ruby-style-guide#module-function + Enabled: false +Style/OneLineConditional: + Description: Favor the ternary operator(?:) over if/then/else/end constructs. + StyleGuide: https://github.com/bbatsov/ruby-style-guide#ternary-operator + Enabled: false +Style/PerlBackrefs: + Description: Avoid Perl-style regex back references. + StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-perl-regexp-last-matchers + Enabled: false +Style/Send: + Description: Prefer `Object#__send__` or `Object#public_send` to `send`, as `send` + may overlap with existing methods. + StyleGuide: https://github.com/bbatsov/ruby-style-guide#prefer-public-send + Enabled: false +Style/SpecialGlobalVars: + Description: Avoid Perl-style global variables. + StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-cryptic-perlisms + Enabled: false +Style/VariableInterpolation: + Description: Don't interpolate global, instance and class variables directly in + strings. + StyleGuide: https://github.com/bbatsov/ruby-style-guide#curlies-interpolate + Enabled: false +Style/WhenThen: + Description: Use when x then ... for one-line cases. + StyleGuide: https://github.com/bbatsov/ruby-style-guide#one-line-cases + Enabled: false +Lint/EachWithObjectArgument: + Description: Check for immutable argument given to each_with_object. + Enabled: true +Lint/HandleExceptions: + Description: Don't suppress exception. + StyleGuide: https://github.com/bbatsov/ruby-style-guide#dont-hide-exceptions Enabled: false - -UnderscorePrefixedVariableName: +Lint/LiteralInCondition: + Description: Checks of literals used in conditions. Enabled: false - -Void: +Lint/LiteralInInterpolation: + Description: Checks for literals used in interpolation. Enabled: false