|
87 | 87 | end |
88 | 88 |
|
89 | 89 | describe '.invalid_directories?' do |
90 | | - let(:valid_path_a) { 'C:/some/folder' } |
91 | | - let(:valid_path_b) { 'C:/another/folder' } |
92 | | - let(:valid_paths) { 'C:/some/folder;C:/another/folder' } |
93 | | - let(:invalid_path) { 'C:/invalid/path' } |
94 | | - let(:mixed_paths) { 'C:/some/folder;C:/invalid/path;C:/another/folder' } |
95 | | - let(:empty_string) { '' } |
96 | | - let(:empty_members) { 'C:/some/folder;;C:/another/folder' } |
| 90 | + let(:valid_path_a) { 'C:/some/folder' } |
| 91 | + let(:valid_path_b) { 'C:/another/folder' } |
| 92 | + let(:valid_paths) { 'C:/some/folder;C:/another/folder' } |
| 93 | + let(:invalid_path) { 'C:/invalid/path' } |
| 94 | + let(:mixed_paths) { 'C:/some/folder;C:/another/folder;C:/invalid/path' } |
| 95 | + let(:empty_string) { '' } |
| 96 | + let(:file_path) { 'C:/some/folder/file.txt' } |
| 97 | + let(:non_existent_dir) { 'C:/some/dir/that/doesnt/exist' } |
| 98 | + let(:empty_members) { 'C:/some/folder;;C:/another/folder' } |
97 | 99 |
|
98 | 100 | it 'returns false if passed nil' do |
99 | 101 | expect(described_class.invalid_directories?(nil)).to be false |
|
103 | 105 | expect(described_class.invalid_directories?('')).to be false |
104 | 106 | end |
105 | 107 |
|
| 108 | + it 'returns false if a file path is provided' do |
| 109 | + expect(described_class.invalid_directories?(file_path)).to be false |
| 110 | + end |
| 111 | + |
106 | 112 | it 'returns false if one valid path is provided' do |
107 | 113 | expect(described_class).to receive(:on_windows?).and_return(true) |
| 114 | + expect(File).to receive(:exist?).with(valid_path_a).and_return(true) |
108 | 115 | expect(File).to receive(:directory?).with(valid_path_a).and_return(true) |
109 | 116 | expect(described_class.invalid_directories?(valid_path_a)).to be false |
110 | 117 | end |
111 | 118 |
|
112 | 119 | it 'returns false if a collection of valid paths is provided' do |
113 | 120 | expect(described_class).to receive(:on_windows?).and_return(true) |
114 | 121 | expect(File).to receive(:directory?).with(valid_path_a).and_return(true) |
| 122 | + expect(File).to receive(:exist?).with(valid_path_a).and_return(true) |
115 | 123 | expect(File).to receive(:directory?).with(valid_path_b).and_return(true) |
| 124 | + expect(File).to receive(:exist?).with(valid_path_b).and_return(true) |
116 | 125 | expect(described_class.invalid_directories?(valid_paths)).to be false |
117 | 126 | end |
118 | 127 |
|
119 | 128 | it 'returns true if there is only one path and it is invalid' do |
120 | 129 | expect(described_class).to receive(:on_windows?).and_return(true) |
| 130 | + expect(File).to receive(:exist?).with(invalid_path).and_return(true) |
121 | 131 | expect(File).to receive(:directory?).with(invalid_path).and_return(false) |
122 | 132 | expect(described_class.invalid_directories?(invalid_path)).to be true |
123 | 133 | end |
124 | 134 |
|
125 | 135 | it 'returns true if the collection has on valid and one invalid member' do |
126 | 136 | expect(described_class).to receive(:on_windows?).and_return(true) |
| 137 | + expect(File).to receive(:exist?).with(valid_path_a).and_return(true) |
127 | 138 | expect(File).to receive(:directory?).with(valid_path_a).and_return(true) |
| 139 | + expect(File).to receive(:exist?).with(valid_path_b).and_return(true) |
128 | 140 | expect(File).to receive(:directory?).with(valid_path_b).and_return(true) |
| 141 | + expect(File).to receive(:exist?).with(invalid_path).and_return(true) |
129 | 142 | expect(File).to receive(:directory?).with(invalid_path).and_return(false) |
130 | 143 | expect(described_class.invalid_directories?(mixed_paths)).to be true |
131 | 144 | end |
132 | 145 |
|
133 | 146 | it 'returns false if collection has empty members but other entries are valid' do |
134 | 147 | expect(described_class).to receive(:on_windows?).and_return(true) |
| 148 | + expect(File).to receive(:exist?).with(valid_path_a).and_return(true) |
135 | 149 | expect(File).to receive(:directory?).with(valid_path_a).and_return(true) |
| 150 | + expect(File).to receive(:exist?).with(valid_path_b).and_return(true) |
136 | 151 | expect(File).to receive(:directory?).with(valid_path_b).and_return(true) |
137 | 152 | allow(File).to receive(:directory?).with('') |
138 | 153 | expect(described_class.invalid_directories?(empty_members)).to be false |
139 | 154 | end |
| 155 | + |
| 156 | + it 'returns true if a collection has valid members but also contains a file path' do |
| 157 | + expect(described_class).to receive(:on_windows?).and_return(true) |
| 158 | + expect(File).to receive(:exist?).with(valid_path_a).and_return(true) |
| 159 | + expect(File).to receive(:directory?).with(valid_path_a).and_return(true) |
| 160 | + expect(File).to receive(:exist?).with(file_path).and_return(true) |
| 161 | + expect(File).to receive(:directory?).with(file_path).and_return(false) |
| 162 | + expect(described_class.invalid_directories?("#{valid_path_a};#{file_path}")).to be true |
| 163 | + end |
| 164 | + |
| 165 | + it 'returns false if a collection has valid members but contains a non-existent dir path' do |
| 166 | + expect(described_class).to receive(:on_windows?).and_return(true) |
| 167 | + expect(File).to receive(:exist?).with(valid_path_a).and_return(true) |
| 168 | + expect(File).to receive(:directory?).with(valid_path_a).and_return(true) |
| 169 | + expect(File).to receive(:exist?).with(non_existent_dir).and_return(false) |
| 170 | + expect(described_class.invalid_directories?("#{valid_path_a};#{non_existent_dir}")).to be false |
| 171 | + end |
140 | 172 | end |
141 | 173 |
|
142 | 174 | describe '.snake_case' do |
|
0 commit comments