Skip to content
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

Use Dir.glob with base parameter in acceptance tests #93

Merged
merged 2 commits into from
Jun 25, 2024
Merged
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
36 changes: 18 additions & 18 deletions spec/acceptance/puppet/modulebuilder/builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,23 @@

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

RSpec::Matchers.define :be_an_empty_glob do
match do |actual|
Dir.glob(extracted_module_path + actual).empty?
@extracted = Dir.glob(actual, base: extracted_module_path)
@extracted.empty?
end

failure_message do |actual|
"expected that #{actual} would be empty but got #{Dir.glob(extracted_module_path + actual)}"
"expected that #{actual} would be empty but got #{@extracted}"
end
end

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

@source == @extracted
end
Expand Down Expand Up @@ -83,21 +83,21 @@

it 'expands the expected paths' do # This is expected
# No development directories
expect('/spec/*').to be_an_empty_glob
expect('/.vscode/*').to be_an_empty_glob
expect('/tmp/*').to be_an_empty_glob
expect('spec/*').to be_an_empty_glob
expect('.vscode/*').to be_an_empty_glob
expect('tmp/*').to be_an_empty_glob
# No development files
expect('/.fixtures').to be_an_empty_glob
expect('/.gitignore').to be_an_empty_glob
expect('/Rakefile').to be_an_empty_glob
expect('.fixtures').to be_an_empty_glob
expect('.gitignore').to be_an_empty_glob
expect('Rakefile').to be_an_empty_glob
# No CI files
expect('/.travis.yml').to be_an_empty_glob
expect('/appveyor.yml').to be_an_empty_glob
expect('.travis.yml').to be_an_empty_glob
expect('appveyor.yml').to be_an_empty_glob

# Important Extracted files
expect('/manifests/*').to be_identical_as_soource
expect('/templates/*').to be_identical_as_soource
expect('/lib/*').to be_identical_as_soource
expect('manifests/*').to be_identical_as_source
expect('templates/*').to be_identical_as_source
expect('lib/*').to be_identical_as_source
end
end
end
Expand Down
Loading