Skip to content

Commit c407756

Browse files
authored
Merge pull request #93 from ekohl/simplify-specs
Use Dir.glob with base parameter in acceptance tests
2 parents f4d83c7 + bd88a93 commit c407756

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

Diff for: spec/acceptance/puppet/modulebuilder/builder_spec.rb

+18-18
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

54-
RSpec::Matchers.define :be_identical_as_soource do
55+
RSpec::Matchers.define :be_identical_as_source 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_source
99+
expect('templates/*').to be_identical_as_source
100+
expect('lib/*').to be_identical_as_source
101101
end
102102
end
103103
end

0 commit comments

Comments
 (0)