Skip to content

Commit 37ba942

Browse files
committed
Merge pull request #313 from rubemz/bugfix/subpath-event-watcher
fix the listen watcher
2 parents 38b1ce3 + ccf0369 commit 37ba942

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

lib/spring/watcher/listen.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ def changed(modified, added, removed)
4343

4444
def base_directories
4545
([root] +
46-
files.reject { |f| f.start_with? root }.map { |f| File.expand_path("#{f}/..") } +
47-
directories.reject { |d| d.start_with? root }
46+
files.reject { |f| f.start_with? "#{root}/" }.map { |f| File.expand_path("#{f}/..") } +
47+
directories.reject { |d| d.start_with? "#{root}/" }
4848
).uniq
4949
end
5050
end

test/unit/watcher_test.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,27 @@ def watcher_class
184184
FileUtils.rmdir other_dir_2
185185
end
186186
end
187+
188+
test "root directories with a root subpath directory" do
189+
begin
190+
other_dir_1 = "#{dir}_other"
191+
other_dir_2 = "#{dir}_core"
192+
# same subpath as dir but with _other or _core appended
193+
FileUtils::mkdir_p(other_dir_1)
194+
FileUtils::mkdir_p(other_dir_2)
195+
File.write("#{other_dir_1}/foo", "foo")
196+
File.write("#{other_dir_2}/foo", "foo")
197+
File.write("#{dir}/foo", "foo")
198+
199+
watcher.add "#{other_dir_1}/foo"
200+
watcher.add other_dir_2
201+
202+
assert_equal [dir, other_dir_1, other_dir_2].sort, watcher.base_directories.sort
203+
ensure
204+
FileUtils.rmdir other_dir_1
205+
FileUtils.rmdir other_dir_2
206+
end
207+
end
187208
end
188209

189210
class PollingWatcherTest < ActiveSupport::TestCase

0 commit comments

Comments
 (0)