Skip to content

Commit 312c119

Browse files
committed
Use Dir.glob with base parameter in acceptance tests
This didn't work because using absolute paths doesn't work. By using relative paths in expect it can use the base parameter. It also enhances the be_an_empty_glob matcher to avoid a double glob because it avoids any potential race condition.
1 parent f4d83c7 commit 312c119

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

spec/acceptance/puppet/modulebuilder/builder_spec.rb

+17-17
Original file line numberDiff line numberDiff line change
@@ -39,23 +39,23 @@
3939

4040
context 'which is installed via Puppet' do
4141
let(:extract_path) { Dir.mktmpdir }
42-
let(:extracted_module_path) { File.join(extract_path, Dir.entries(extract_path).reject { |p| %w[. ..].include?(p) }.first) }
42+
let(:extracted_module_path) { Dir[File.join(extract_path, '*')].first }
4343

4444
RSpec::Matchers.define :be_an_empty_glob do
4545
match do |actual|
46-
Dir.glob(extracted_module_path + actual).empty?
46+
@extracted = Dir.glob(actual, base: extracted_module_path)
47+
@extracted.empty?
4748
end
4849

4950
failure_message do |actual|
50-
"expected that #{actual} would be empty but got #{Dir.glob(extracted_module_path + actual)}"
51+
"expected that #{actual} would be empty but got #{@extracted}"
5152
end
5253
end
5354

5455
RSpec::Matchers.define :be_identical_as_soource do
5556
match do |actual|
56-
# Dir.glob(..., base: xxx) does not work, so need to use a crude method to get the relative directory path
57-
@source = Dir.glob(module_source + actual).map { |p| p.slice(module_source.length..-1) }
58-
@extracted = Dir.glob(extracted_module_path + actual).map { |p| p.slice(extracted_module_path.length..-1) }
57+
@source = Dir.glob(actual, base: module_source)
58+
@extracted = Dir.glob(actual, base: extracted_module_path)
5959

6060
@source == @extracted
6161
end
@@ -83,21 +83,21 @@
8383

8484
it 'expands the expected paths' do # This is expected
8585
# No development directories
86-
expect('/spec/*').to be_an_empty_glob
87-
expect('/.vscode/*').to be_an_empty_glob
88-
expect('/tmp/*').to be_an_empty_glob
86+
expect('spec/*').to be_an_empty_glob
87+
expect('.vscode/*').to be_an_empty_glob
88+
expect('tmp/*').to be_an_empty_glob
8989
# No development files
90-
expect('/.fixtures').to be_an_empty_glob
91-
expect('/.gitignore').to be_an_empty_glob
92-
expect('/Rakefile').to be_an_empty_glob
90+
expect('.fixtures').to be_an_empty_glob
91+
expect('.gitignore').to be_an_empty_glob
92+
expect('Rakefile').to be_an_empty_glob
9393
# No CI files
94-
expect('/.travis.yml').to be_an_empty_glob
95-
expect('/appveyor.yml').to be_an_empty_glob
94+
expect('.travis.yml').to be_an_empty_glob
95+
expect('appveyor.yml').to be_an_empty_glob
9696

9797
# Important Extracted files
98-
expect('/manifests/*').to be_identical_as_soource
99-
expect('/templates/*').to be_identical_as_soource
100-
expect('/lib/*').to be_identical_as_soource
98+
expect('manifests/*').to be_identical_as_soource
99+
expect('templates/*').to be_identical_as_soource
100+
expect('lib/*').to be_identical_as_soource
101101
end
102102
end
103103
end

0 commit comments

Comments
 (0)