diff --git a/spec/unit/pdk/config_spec.rb b/spec/unit/pdk/config_spec.rb index d927cca42..063ae1076 100644 --- a/spec/unit/pdk/config_spec.rb +++ b/spec/unit/pdk/config_spec.rb @@ -24,19 +24,19 @@ def mock_file(path, content) describe '.system_config' do it 'returns a PDK::Config::Namespace' do - expect(config.system_config).to be_a(PDK::Config::Namespace) + expect(config.system_config).to be_a(described_class::Namespace) end end describe '.user_config' do it 'returns a PDK::Config::Namespace' do - expect(config.user_config).to be_a(PDK::Config::Namespace) + expect(config.user_config).to be_a(described_class::Namespace) end end describe '.project_config' do it 'returns a PDK::Config::Namespace' do - expect(config.project_config).to be_a(PDK::Config::Namespace) + expect(config.project_config).to be_a(described_class::Namespace) end context 'Given a Control Repo context' do @@ -115,7 +115,7 @@ def mock_file(path, content) end it 'traverses root names' do - expect(config.get('user')).to be_a(PDK::Config::Namespace) + expect(config.get('user')).to be_a(described_class::Namespace) end it 'traverses namespaces' do @@ -565,10 +565,10 @@ def project_config context 'and the bolt configuration is unparsable' do before do - allow(PDK::Config::YAML).to receive(:new).and_call_original - allow(PDK::Config::YAML).to receive(:new) + allow(described_class::YAML).to receive(:new).and_call_original + allow(described_class::YAML).to receive(:new) .with(file: PDK::Util::Filesystem.expand_path(bolt_analytics_path)) - .and_raise(PDK::Config::LoadError) + .and_raise(described_class::LoadError) end it 'returns true' do @@ -633,10 +633,10 @@ def uuid_regex(uuid) context 'and the bolt configuration is unparsable' do before do - allow(PDK::Config::YAML).to receive(:new).and_call_original - allow(PDK::Config::YAML).to receive(:new) + allow(described_class::YAML).to receive(:new).and_call_original + allow(described_class::YAML).to receive(:new) .with(file: PDK::Util::Filesystem.expand_path(bolt_analytics_path)) - .and_raise(PDK::Config::LoadError) + .and_raise(described_class::LoadError) end it 'generates a new UUID' do diff --git a/spec/unit/pdk/report_spec.rb b/spec/unit/pdk/report_spec.rb index d3e6f8fdf..78b519aa5 100644 --- a/spec/unit/pdk/report_spec.rb +++ b/spec/unit/pdk/report_spec.rb @@ -38,8 +38,8 @@ it 'stores the events in the report by source' do expect(report).to have_attributes( events: { - 'puppet-lint' => [instance_of(PDK::Report::Event)], - 'rubocop' => [instance_of(PDK::Report::Event)] + 'puppet-lint' => [instance_of(described_class::Event)], + 'rubocop' => [instance_of(described_class::Event)] } ) end diff --git a/spec/unit/pdk/template/fetcher_spec.rb b/spec/unit/pdk/template/fetcher_spec.rb index 85ea2fbde..5b91b0230 100644 --- a/spec/unit/pdk/template/fetcher_spec.rb +++ b/spec/unit/pdk/template/fetcher_spec.rb @@ -12,7 +12,7 @@ let(:template_uri) { PDK::Util::TemplateURI.new('https://github.com/puppetlabs/pdk-templates') } it 'creates a Git Fetcher object' do - expect(instance).to be_a(PDK::Template::Fetcher::Git) + expect(instance).to be_a(described_class::Git) end end @@ -20,11 +20,11 @@ let(:template_uri) { PDK::Util::TemplateURI.new('/some/path') } before do - allow(PDK::Template::Fetcher::Git).to receive(:fetchable?).and_return(false) + allow(described_class::Git).to receive(:fetchable?).and_return(false) end it 'creates a Local Fetcher object' do - expect(instance).to be_a(PDK::Template::Fetcher::Local) + expect(instance).to be_a(described_class::Local) end end end diff --git a/spec/unit/pdk/template/renderer/v1_spec.rb b/spec/unit/pdk/template/renderer/v1_spec.rb index 927410c38..0450fd9df 100644 --- a/spec/unit/pdk/template/renderer/v1_spec.rb +++ b/spec/unit/pdk/template/renderer/v1_spec.rb @@ -34,7 +34,7 @@ describe '.instance' do it 'creates a PDK::Template::Renderer::V1::Renderer object' do - expect(described_class.instance(template_root, template_uri, pdk_context)).to be_a(PDK::Template::Renderer::V1::Renderer) + expect(described_class.instance(template_root, template_uri, pdk_context)).to be_a(described_class::Renderer) end end end diff --git a/spec/unit/pdk/template/renderer_spec.rb b/spec/unit/pdk/template/renderer_spec.rb index 19e973de9..37bef45cd 100644 --- a/spec/unit/pdk/template/renderer_spec.rb +++ b/spec/unit/pdk/template/renderer_spec.rb @@ -11,17 +11,17 @@ context 'given an original template directory' do before do - allow(PDK::Template::Renderer::V1).to receive(:compatible?).and_return(true) + allow(described_class::V1).to receive(:compatible?).and_return(true) end it 'creates a version 1 renderer' do - expect(instance).to be_a(PDK::Template::Renderer::V1::Renderer) + expect(instance).to be_a(described_class::V1::Renderer) end end context 'given a template that has no appropriate renderer' do before do - allow(PDK::Template::Renderer::V1).to receive(:compatible?).and_return(false) + allow(described_class::V1).to receive(:compatible?).and_return(false) end it 'creates a Local Fetcher object' do diff --git a/spec/unit/pdk/template_spec.rb b/spec/unit/pdk/template_spec.rb index 0cb1ddc11..bba801741 100644 --- a/spec/unit/pdk/template_spec.rb +++ b/spec/unit/pdk/template_spec.rb @@ -25,19 +25,19 @@ end context 'when initialized correctly' do - let(:fetcher) { PDK::Template::Fetcher::AbstractFetcher.new(template_uri, {}) } + let(:fetcher) { described_class::Fetcher::AbstractFetcher.new(template_uri, {}) } let(:template_dir) do - PDK::Template::TemplateDir.new( + described_class::TemplateDir.new( template_uri, nil, pdk_context, - instance_double(PDK::Template::Renderer::AbstractRenderer) + instance_double(described_class::Renderer::AbstractRenderer) ) end before do - expect(PDK::Template::Fetcher).to receive(:with).with(template_uri).and_yield(fetcher) - allow(PDK::Template::TemplateDir).to receive(:instance).with(template_uri, anything, pdk_context).and_return(template_dir) + expect(described_class::Fetcher).to receive(:with).with(template_uri).and_yield(fetcher) + allow(described_class::TemplateDir).to receive(:instance).with(template_uri, anything, pdk_context).and_return(template_dir) end it 'fetches remote templates' do diff --git a/spec/unit/pdk/util/bundler_spec.rb b/spec/unit/pdk/util/bundler_spec.rb index a2ce0e235..ce1103744 100644 --- a/spec/unit/pdk/util/bundler_spec.rb +++ b/spec/unit/pdk/util/bundler_spec.rb @@ -9,12 +9,12 @@ let(:gemfile) { '/Gemfile' } let(:gemfile_lock) { "#{gemfile}.lock" } let(:bundle_helper) do - instance_double(PDK::Util::Bundler::BundleHelper, gemfile: gemfile, gemfile?: true, gemfile_lock: gemfile_lock) + instance_double(described_class::BundleHelper, gemfile: gemfile, gemfile?: true, gemfile_lock: gemfile_lock) end before do # Allow us to mock/stub/expect calls to the internal bundle helper. - allow(PDK::Util::Bundler::BundleHelper).to receive(:new).and_return(bundle_helper) + allow(described_class::BundleHelper).to receive(:new).and_return(bundle_helper) allow(PDK::Util::Filesystem).to receive(:mv).with(gemfile_lock, anything) allow(PDK::Util::Filesystem).to receive(:mv).with(anything, gemfile_lock, force: true) end diff --git a/spec/unit/pdk/util/vendored_file_spec.rb b/spec/unit/pdk/util/vendored_file_spec.rb index 3ed65d14f..04aa8d0b8 100644 --- a/spec/unit/pdk/util/vendored_file_spec.rb +++ b/spec/unit/pdk/util/vendored_file_spec.rb @@ -57,7 +57,7 @@ allow(mock_http).to receive(:verify_mode=).with(anything) end - let(:download_error) { PDK::Util::VendoredFile::DownloadError } + let(:download_error) { described_class::DownloadError } let(:mock_http) { instance_double(Net::HTTP) } let(:mock_request) { instance_double(Net::HTTP::Get) } let(:mock_response) { instance_double(Net::HTTPResponse) } diff --git a/spec/unit/pdk/util_spec.rb b/spec/unit/pdk/util_spec.rb index a6934ce27..c12ae7038 100644 --- a/spec/unit/pdk/util_spec.rb +++ b/spec/unit/pdk/util_spec.rb @@ -20,13 +20,13 @@ let(:version_file) { File.join('path', 'to', 'the', 'version', 'file') } before do - allow(PDK::Util::Version).to receive(:version_file).and_return(version_file) + allow(described_class::Version).to receive(:version_file).and_return(version_file) end end shared_context 'without version file', version_file: false do before do - allow(PDK::Util::Version).to receive(:version_file).and_return(nil) + allow(described_class::Version).to receive(:version_file).and_return(nil) end end @@ -38,24 +38,24 @@ let(:actual_start_dir) { '/path/to/something/deep/in/a/module' } before do - allow(PDK::Util::Filesystem).to receive(:directory?).with('/path/to/something/deep/in/a/module').and_return(true) - allow(PDK::Util::Filesystem).to receive(:expand_path).with('..', '/path/to/something/deep/in/a/module').and_return('/path/to/something/deep/in/a') - allow(PDK::Util::Filesystem).to receive(:directory?).with('/path/to/something/deep/in/a').and_return(true) - allow(PDK::Util::Filesystem).to receive(:expand_path).with('..', '/path/to/something/deep/in/a').and_return('/path/to/something/deep/in') - allow(PDK::Util::Filesystem).to receive(:directory?).with('/path/to/something/deep/in').and_return(true) - allow(PDK::Util::Filesystem).to receive(:expand_path).with('..', '/path/to/something/deep/in').and_return('/path/to/something/deep') - allow(PDK::Util::Filesystem).to receive(:directory?).with('/path/to/something/deep').and_return(true) - allow(PDK::Util::Filesystem).to receive(:expand_path).with('..', '/path/to/something/deep').and_return('/path/to/something') - allow(PDK::Util::Filesystem).to receive(:directory?).with('/path/to/something').and_return(true) - allow(PDK::Util::Filesystem).to receive(:expand_path).with('..', '/path/to/something').and_return('/path/to') - allow(PDK::Util::Filesystem).to receive(:directory?).with('/path/to').and_return(true) - allow(PDK::Util::Filesystem).to receive(:expand_path).with('..', '/path/to').and_return('/path') - allow(PDK::Util::Filesystem).to receive(:directory?).with('/path').and_return(true) - allow(PDK::Util::Filesystem).to receive(:expand_path).with('..', '/path').and_return('/') - allow(PDK::Util::Filesystem).to receive(:directory?).with('/').and_return(true) - allow(PDK::Util::Filesystem).to receive(:expand_path).with('..', '/').and_return('/') - allow(PDK::Util::Filesystem).to receive(:expand_path).with(actual_start_dir).and_return(actual_start_dir) - allow(PDK::Util::Filesystem).to receive(:file?).with(a_string_matching(/metadata\.json\Z/)).and_return(false) + allow(described_class::Filesystem).to receive(:directory?).with('/path/to/something/deep/in/a/module').and_return(true) + allow(described_class::Filesystem).to receive(:expand_path).with('..', '/path/to/something/deep/in/a/module').and_return('/path/to/something/deep/in/a') + allow(described_class::Filesystem).to receive(:directory?).with('/path/to/something/deep/in/a').and_return(true) + allow(described_class::Filesystem).to receive(:expand_path).with('..', '/path/to/something/deep/in/a').and_return('/path/to/something/deep/in') + allow(described_class::Filesystem).to receive(:directory?).with('/path/to/something/deep/in').and_return(true) + allow(described_class::Filesystem).to receive(:expand_path).with('..', '/path/to/something/deep/in').and_return('/path/to/something/deep') + allow(described_class::Filesystem).to receive(:directory?).with('/path/to/something/deep').and_return(true) + allow(described_class::Filesystem).to receive(:expand_path).with('..', '/path/to/something/deep').and_return('/path/to/something') + allow(described_class::Filesystem).to receive(:directory?).with('/path/to/something').and_return(true) + allow(described_class::Filesystem).to receive(:expand_path).with('..', '/path/to/something').and_return('/path/to') + allow(described_class::Filesystem).to receive(:directory?).with('/path/to').and_return(true) + allow(described_class::Filesystem).to receive(:expand_path).with('..', '/path/to').and_return('/path') + allow(described_class::Filesystem).to receive(:directory?).with('/path').and_return(true) + allow(described_class::Filesystem).to receive(:expand_path).with('..', '/path').and_return('/') + allow(described_class::Filesystem).to receive(:directory?).with('/').and_return(true) + allow(described_class::Filesystem).to receive(:expand_path).with('..', '/').and_return('/') + allow(described_class::Filesystem).to receive(:expand_path).with(actual_start_dir).and_return(actual_start_dir) + allow(described_class::Filesystem).to receive(:file?).with(a_string_matching(/metadata\.json\Z/)).and_return(false) end context 'when start_dir is nil' do @@ -65,7 +65,7 @@ context 'and the target file exists' do before do - allow(PDK::Util::Filesystem).to receive(:file?).with('/path/to/something/metadata.json').and_return(true) + allow(described_class::Filesystem).to receive(:file?).with('/path/to/something/metadata.json').and_return(true) end it { is_expected.to eq('/path/to/something/metadata.json') } @@ -81,7 +81,7 @@ context 'and the target file exists' do before do - allow(PDK::Util::Filesystem).to receive(:file?).with('/path/to/something/metadata.json').and_return(true) + allow(described_class::Filesystem).to receive(:file?).with('/path/to/something/metadata.json').and_return(true) end it { is_expected.to eq('/path/to/something/metadata.json') } @@ -111,7 +111,7 @@ context 'and the path does not exist' do before do - allow(PDK::Util::Filesystem).to receive(:exist?).with(path).and_return(false) + allow(described_class::Filesystem).to receive(:exist?).with(path).and_return(false) end it 'raises a FatalError' do @@ -123,11 +123,11 @@ context 'and the path exists' do before do - allow(PDK::Util::Filesystem).to receive(:exist?).with(path).and_return(true) + allow(described_class::Filesystem).to receive(:exist?).with(path).and_return(true) end it 'calls Puppet::Util::Windows::File.get_long_pathname to resolve the absolute path' do - expect(PDK::Util::Windows::File).to receive(:get_long_pathname).with(path) + expect(described_class::Windows::File).to receive(:get_long_pathname).with(path) described_class.canonical_path(path) end @@ -140,7 +140,7 @@ end it 'calls File.expath_path to resolve the absolute path' do - expect(PDK::Util::Filesystem).to receive(:expand_path).with(path) + expect(described_class::Filesystem).to receive(:expand_path).with(path) described_class.canonical_path(path) end @@ -164,7 +164,7 @@ context 'when running from a release' do before do - allow(PDK::Util::Version).to receive(:git_ref).and_return(nil) + allow(described_class::Version).to receive(:git_ref).and_return(nil) stub_const('PDK::VERSION', '1.3.0') end @@ -173,7 +173,7 @@ context 'when running from a pre-release' do before do - allow(PDK::Util::Version).to receive(:git_ref).and_return(nil) + allow(described_class::Version).to receive(:git_ref).and_return(nil) stub_const('PDK::VERSION', '1.3.0.pre') end @@ -182,7 +182,7 @@ context 'when running from git' do before do - allow(PDK::Util::Version).to receive(:git_ref).and_return('abc') + allow(described_class::Version).to receive(:git_ref).and_return('abc') end it { is_expected.to be true } @@ -255,7 +255,7 @@ context 'when running on Windows' do before do allow(Gem).to receive(:win_platform?).and_return(true) - allow(PDK::Util::Env).to receive(:[]).with('LOCALAPPDATA').and_return('C:/Users/test') + allow(described_class::Env).to receive(:[]).with('LOCALAPPDATA').and_return('C:/Users/test') end it 'returns a path in the %LOCALAPPDATA% folder' do @@ -281,7 +281,7 @@ context 'when running on Windows' do before do allow(Gem).to receive(:win_platform?).and_return(true) - allow(PDK::Util::Env).to receive(:[]).with('LOCALAPPDATA').and_return('C:/Users/test') + allow(described_class::Env).to receive(:[]).with('LOCALAPPDATA').and_return('C:/Users/test') end it 'returns a path in the %LOCALAPPDATA% folder' do @@ -293,7 +293,7 @@ before do allow(Gem).to receive(:win_platform?).and_return(false) allow(Dir).to receive(:home).with(any_args).and_return('/home/test') - allow(PDK::Util::Env).to receive(:fetch) + allow(described_class::Env).to receive(:fetch) .with('XDG_CONFIG_HOME', '/home/test/.config') .and_return('/xdg_home/test/.config') end @@ -323,8 +323,8 @@ context 'when ProgramData environment variable exists' do before do # ProgramData was added in Windows Vista - allow(PDK::Util::Env).to receive(:[]).with('ProgramData').and_return(program_data) - allow(PDK::Util::Env).to receive(:[]).with('AllUsersProfile').and_return(nil) + allow(described_class::Env).to receive(:[]).with('ProgramData').and_return(program_data) + allow(described_class::Env).to receive(:[]).with('AllUsersProfile').and_return(nil) end it 'returns a path in the Program Data directory' do @@ -335,8 +335,8 @@ context 'when AllUsersProfile environment variable exists' do before do # AllUsersProfile was added in Windows 2000 - allow(PDK::Util::Env).to receive(:[]).with('ProgramData').and_return(nil) - allow(PDK::Util::Env).to receive(:[]).with('AllUsersProfile').and_return(program_data) + allow(described_class::Env).to receive(:[]).with('ProgramData').and_return(nil) + allow(described_class::Env).to receive(:[]).with('AllUsersProfile').and_return(program_data) end it 'returns a path in the Program Data directory' do @@ -423,13 +423,13 @@ let(:test_path) { '\x00path/test' } before do - allow(PDK::Util::Filesystem).to receive(:directory?).and_call_original + allow(described_class::Filesystem).to receive(:directory?).and_call_original end # Directories which indicate a module root ['manifests', 'lib/puppet', 'lib/puppet_x', 'lib/facter', 'tasks', 'facts.d', 'functions', 'types'].each do |testcase| it "detects #{testcase} as being in the root of a module" do - allow(PDK::Util::Filesystem).to receive(:directory?).with(File.join(test_path, testcase)).and_return(true) + allow(described_class::Filesystem).to receive(:directory?).with(File.join(test_path, testcase)).and_return(true) expect(described_class.in_module_root?(test_path)).to be(true) end end @@ -437,18 +437,18 @@ # Directories which do not indicate a module root ['lib', 'Boltdir', 'puppet'].each do |testcase| it "detects #{testcase} as not being in the root of a module" do - allow(PDK::Util::Filesystem).to receive(:directory?).with(File.join(test_path, testcase)).and_return(true) + allow(described_class::Filesystem).to receive(:directory?).with(File.join(test_path, testcase)).and_return(true) expect(described_class.in_module_root?(test_path)).to be(false) end end it 'detects metadata.json within the folder and determines that it is the root of a module' do - allow(PDK::Util::Filesystem).to receive(:file?).with(File.join(test_path, 'metadata.json')).and_return(true) + allow(described_class::Filesystem).to receive(:file?).with(File.join(test_path, 'metadata.json')).and_return(true) expect(described_class.in_module_root?(test_path)).to be(true) end it 'uses the current directory if a directory is not specified' do - expect(PDK::Util::Filesystem).to receive(:directory?) { |path| expect(path).to start_with(Dir.pwd) }.at_least(:once) + expect(described_class::Filesystem).to receive(:directory?) { |path| expect(path).to start_with(Dir.pwd) }.at_least(:once) described_class.in_module_root? end end diff --git a/spec/unit/pdk/validate_spec.rb b/spec/unit/pdk/validate_spec.rb index c66833567..237ca968c 100644 --- a/spec/unit/pdk/validate_spec.rb +++ b/spec/unit/pdk/validate_spec.rb @@ -13,7 +13,7 @@ end it 'all validator instances inherit from PDK::Validate::Validator' do - expect(described_class.validators.map(&:new)).to all(be_a(PDK::Validate::Validator)) + expect(described_class.validators.map(&:new)).to all(be_a(described_class::Validator)) end end diff --git a/spec/unit/pdk_spec.rb b/spec/unit/pdk_spec.rb index f030bc867..06e3fcaa6 100644 --- a/spec/unit/pdk_spec.rb +++ b/spec/unit/pdk_spec.rb @@ -5,13 +5,13 @@ describe '.logger', use_stubbed_logger: false do subject { described_class.logger } - it { is_expected.to be_an_instance_of(PDK::Logger) } + it { is_expected.to be_an_instance_of(described_class::Logger) } end describe '.config' do subject(:config) { described_class.config } - it { is_expected.to be_an_instance_of(PDK::Config) } + it { is_expected.to be_an_instance_of(described_class::Config) } it 'is memoised' do object1 = PDK.config # rubocop:disable RSpec/DescribedClass have to use the explicit form due to rspec caching @@ -23,7 +23,7 @@ describe '.context' do subject(:context) { described_class.context } - it { is_expected.to be_a(PDK::Context::AbstractContext) } + it { is_expected.to be_a(described_class::Context::AbstractContext) } it 'is memoised' do object1 = PDK.context # rubocop:disable RSpec/DescribedClass have to use the explicit form due to rspec caching