Skip to content

fix the listen watcher #313

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 16, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/spring/watcher/listen.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ def changed(modified, added, removed)

def base_directories
([root] +
files.reject { |f| f.start_with? root }.map { |f| File.expand_path("#{f}/..") } +
directories.reject { |d| d.start_with? root }
files.reject { |f| f.start_with? "#{root}/" }.map { |f| File.expand_path("#{f}/..") } +
directories.reject { |d| d.start_with? "#{root}/" }
).uniq
end
end
Expand Down
21 changes: 21 additions & 0 deletions test/unit/watcher_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,27 @@ def watcher_class
FileUtils.rmdir other_dir_2
end
end

test "root directories with a root subpath directory" do
begin
other_dir_1 = "#{dir}_other"
other_dir_2 = "#{dir}_core"
# same subpath as dir but with _other or _core appended
FileUtils::mkdir_p(other_dir_1)
FileUtils::mkdir_p(other_dir_2)
File.write("#{other_dir_1}/foo", "foo")
File.write("#{other_dir_2}/foo", "foo")
File.write("#{dir}/foo", "foo")

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
ensure
FileUtils.rmdir other_dir_1
FileUtils.rmdir other_dir_2
end
end
end

class PollingWatcherTest < ActiveSupport::TestCase
Expand Down