diff --git a/lib/listen/adapter/config.rb b/lib/listen/adapter/config.rb index e33b13ef..5a068a7c 100644 --- a/lib/listen/adapter/config.rb +++ b/lib/listen/adapter/config.rb @@ -16,6 +16,12 @@ def initialize(directories, queue, silencer, adapter_options) Pathname.new(directory.to_s).realpath end + @directories.each do |pathname| + unless pathname.directory? + fail ArgumentError, "must be a directory: #{pathname}" + end + end + @silencer = silencer @queue = queue @adapter_options = adapter_options diff --git a/spec/lib/listen/adapter/config_spec.rb b/spec/lib/listen/adapter/config_spec.rb index 9cab26d6..ff715a8d 100644 --- a/spec/lib/listen/adapter/config_spec.rb +++ b/spec/lib/listen/adapter/config_spec.rb @@ -17,6 +17,7 @@ # Here's what may be passed to initializer let(:path1) { fake_path('/real/path1', realpath: real_path1) } let(:path2) { fake_path('/real/path2', realpath: real_path2) } + let(:path3) { fake_path('/real/path3', realpath: real_path3) } let(:current_path) do fake_path('/real/current_path', realpath: real_current_path) @@ -29,6 +30,7 @@ # something useful) let(:real_path1) { fake_path('/real/path1') } let(:real_path2) { fake_path('/real/path2') } + let(:real_path3) { fake_path('/real/path3', directory?: false) } let(:real_current_path) { fake_path('/real/current_path') } before do @@ -38,6 +40,7 @@ allow(Pathname).to receive(:new).with('/real/path1').and_return(path1) allow(Pathname).to receive(:new).with('/real/path2').and_return(path2) + allow(Pathname).to receive(:new).with('/real/path3').and_return(path3) allow(Pathname).to receive(:new).with(path1).and_return(path1) allow(Pathname).to receive(:new).with(path2).and_return(path2) @@ -90,6 +93,13 @@ expect(subject.directories).to eq([real_current_path]) end end + + context 'with file path' do + let(:directories) { ['/real/path3'] } + it 'raises argument error requesting a directory' do + expect { subject }.to raise_error(ArgumentError, /must be a directory/) + end + end end describe '#adapter_options' do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 676f51f2..7d4799ee 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -38,7 +38,7 @@ def ci? module SpecHelpers def fake_path(str, options = {}) - instance_double(Pathname, str, { to_s: str }.merge(options)) + instance_double(Pathname, str, { to_s: str, directory?: true }.merge(options)) end end