diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index 1dcd2beb2..fbc950812 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -12,8 +12,8 @@ jobs: fail-fast: false matrix: ruby_version: - - '2.5' - - '2.7' + - "2.7" + - "3.2" name: "spec (ruby ${{ matrix.ruby_version }})" uses: "puppetlabs/cat-github-actions/.github/workflows/gem_ci.yml@main" secrets: "inherit" @@ -29,8 +29,8 @@ jobs: - "ubuntu-latest" - "windows-2019" ruby_version: - - "2.5" - "2.7" + - "3.2" name: "acceptance (ruby ${{ matrix.ruby_version }} | ${{ matrix.os }})" uses: "puppetlabs/cat-github-actions/.github/workflows/gem_acceptance.yml@main" secrets: "inherit" diff --git a/docs/pdk.ditamap b/docs/pdk.ditamap index b256f357a..6a5d911b4 100644 --- a/docs/pdk.ditamap +++ b/docs/pdk.ditamap @@ -5,7 +5,7 @@ pdk - + diff --git a/lib/pdk/util/changelog_generator.rb b/lib/pdk/util/changelog_generator.rb index 5a885aa85..ee5d3259a 100644 --- a/lib/pdk/util/changelog_generator.rb +++ b/lib/pdk/util/changelog_generator.rb @@ -33,7 +33,7 @@ def self.generate_changelog output = changelog_content - raise PDK::CLI::ExitWithError, format('The generated changelog contains uncategorized Pull Requests. Please label them and try again. See %{changelog_file} for more details', changelog_file: changelog_file) if output.include?('UNCATEGORIZED PRS; GO LABEL THEM') # rubocop:disable Metrics/LineLength + raise PDK::CLI::ExitWithError, format('The generated changelog contains uncategorized Pull Requests. Please label them and try again. See %{changelog_file} for more details', changelog_file: changelog_file) if output.include?('UNCATEGORIZED PRS; GO LABEL THEM') # rubocop:disable Layout/LineLength output end diff --git a/spec/support/packaged_install.rb b/spec/support/packaged_install.rb index 03e233fde..e3dfcfc00 100644 --- a/spec/support/packaged_install.rb +++ b/spec/support/packaged_install.rb @@ -2,12 +2,10 @@ let(:package_cachedir) { '/package/share/cache' } before do - allow(PDK::Util).to receive(:package_install?).and_return(true) + allow(PDK::Util).to receive_messages(package_install?: true, package_cachedir: package_cachedir) allow(PDK::Util::Filesystem).to receive(:file?).with(/PDK_VERSION/).and_return(true) allow(PDK::Util::Filesystem).to receive(:exist?).with(/bundle(\.bat)?$/).and_return(true) - allow(PDK::Util).to receive(:package_cachedir).and_return(package_cachedir) - allow(PDK::Util::RubyVersion).to receive(:versions).and_return('2.4.4' => '2.4.0') - allow(PDK::Util::RubyVersion).to receive(:default_ruby_version).and_return('2.4.4') + allow(PDK::Util::RubyVersion).to receive_messages(versions: { '2.4.4' => '2.4.0' }, default_ruby_version: '2.4.4') end end diff --git a/spec/unit/pdk/cli/build_spec.rb b/spec/unit/pdk/cli/build_spec.rb index 02825ada2..0a1766517 100644 --- a/spec/unit/pdk/cli/build_spec.rb +++ b/spec/unit/pdk/cli/build_spec.rb @@ -62,8 +62,7 @@ context 'and the module contains incomplete metadata' do before do - allow(mock_metadata_obj).to receive(:forge_ready?).and_return(false) - allow(mock_metadata_obj).to receive(:missing_fields).and_return(['operatingsystem_support', 'source']) + allow(mock_metadata_obj).to receive_messages(forge_ready?: false, missing_fields: ['operatingsystem_support', 'source']) allow(PDK::Module::Build).to receive(:new).with(any_args).and_return(mock_builder) end @@ -146,8 +145,7 @@ context 'package already exists in the target dir' do before do - allow(mock_builder).to receive(:package_already_exists?).and_return(true) - allow(mock_builder).to receive(:module_pdk_compatible?).and_return(true) + allow(mock_builder).to receive_messages(package_already_exists?: true, module_pdk_compatible?: true) end context 'user chooses to continue' do @@ -181,8 +179,7 @@ context 'and module is not pdk compatible' do before do - allow(mock_builder).to receive(:package_already_exists?).and_return(false) - allow(mock_builder).to receive(:module_pdk_compatible?).and_return(false) + allow(mock_builder).to receive_messages(package_already_exists?: false, module_pdk_compatible?: false) end context 'user chooses to continue' do diff --git a/spec/unit/pdk/cli/env_spec.rb b/spec/unit/pdk/cli/env_spec.rb index 04c5aba78..390ab9177 100644 --- a/spec/unit/pdk/cli/env_spec.rb +++ b/spec/unit/pdk/cli/env_spec.rb @@ -13,10 +13,8 @@ end before do - allow(PDK::Util::RubyVersion).to receive(:gem_home).and_return('/opt/puppetlabs/pdk/share/cache/ruby/2.4.0') - allow(PDK::Util::RubyVersion).to receive(:gem_path).and_return('/opt/puppetlabs/pdk/private/ruby/2.4.3/lib') - allow(PDK::Util::RubyVersion).to receive(:bin_path).and_return('/opt/puppetlabs/pdk/private/ruby/2.4.3/bin') - allow(PDK::Util::RubyVersion).to receive(:gem_paths_raw).and_return(['/opt/puppetlabs/pdk/private/ruby/2.4.3/lib']) + allow(PDK::Util::RubyVersion).to receive_messages(gem_home: '/opt/puppetlabs/pdk/share/cache/ruby/2.4.0', gem_path: '/opt/puppetlabs/pdk/private/ruby/2.4.3/lib', + bin_path: '/opt/puppetlabs/pdk/private/ruby/2.4.3/bin', gem_paths_raw: ['/opt/puppetlabs/pdk/private/ruby/2.4.3/lib']) allow(PDK::Util::Env).to receive(:[]).and_call_original allow(PDK::Util::Env).to receive(:[]).with('PATH').and_return('/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin') diff --git a/spec/unit/pdk/cli/exec/command_spec.rb b/spec/unit/pdk/cli/exec/command_spec.rb index c1d9f89f0..b6bb3bfd6 100644 --- a/spec/unit/pdk/cli/exec/command_spec.rb +++ b/spec/unit/pdk/cli/exec/command_spec.rb @@ -105,8 +105,7 @@ before do command.context = :system expect(process).to receive(:start).with(no_args) - allow(process).to receive(:exit_code).and_return 0 - allow(process).to receive(:environment).and_return({}) + allow(process).to receive_messages(exit_code: 0, environment: {}) end it { expect { command.execute! }.not_to raise_error } diff --git a/spec/unit/pdk/cli/exec/interactive_command_spec.rb b/spec/unit/pdk/cli/exec/interactive_command_spec.rb index 0ac31aff7..5a6fbce40 100644 --- a/spec/unit/pdk/cli/exec/interactive_command_spec.rb +++ b/spec/unit/pdk/cli/exec/interactive_command_spec.rb @@ -68,9 +68,8 @@ before do # rubocop:disable RSpec/SubjectStub - allow(command).to receive(:resolved_env_for_command).and_return(environment) + allow(command).to receive_messages(resolved_env_for_command: environment, child_status: child_status) allow(command).to receive(:system) # Kernel is a mixed-in module - allow(command).to receive(:child_status).and_return(child_status) # rubocop:enable RSpec/SubjectStub end diff --git a/spec/unit/pdk/cli/release_spec.rb b/spec/unit/pdk/cli/release_spec.rb index 23141d7d2..4c37ebff8 100755 --- a/spec/unit/pdk/cli/release_spec.rb +++ b/spec/unit/pdk/cli/release_spec.rb @@ -84,8 +84,7 @@ context 'With a module that is not forge ready' do before do - allow(mock_metadata_obj).to receive(:forge_ready?).and_return(false) - allow(mock_metadata_obj).to receive(:missing_fields).and_return(['mock_field']) + allow(mock_metadata_obj).to receive_messages(forge_ready?: false, missing_fields: ['mock_field']) end it 'raises a warning' do diff --git a/spec/unit/pdk/cli/update_spec.rb b/spec/unit/pdk/cli/update_spec.rb index 863c1f22c..497c1c2d4 100644 --- a/spec/unit/pdk/cli/update_spec.rb +++ b/spec/unit/pdk/cli/update_spec.rb @@ -101,9 +101,7 @@ before do allow(PDK).to receive(:context).and_return(pdk_context) - allow(PDK::Util).to receive(:module_root).and_return(module_root) - allow(PDK::Util).to receive(:module_pdk_compatible?).and_return(true) - allow(PDK::Util).to receive(:module_pdk_version).and_return(module_pdk_version) + allow(PDK::Util).to receive_messages(module_root: module_root, module_pdk_compatible?: true, module_pdk_version: module_pdk_version) end context 'and provided no flags' do @@ -232,8 +230,7 @@ context 'when run from inside an unconverted module' do before do - allow(PDK::Util).to receive(:module_root).and_return(module_root) - allow(PDK::Util).to receive(:module_pdk_compatible?).and_return(false) + allow(PDK::Util).to receive_messages(module_root: module_root, module_pdk_compatible?: false) end context 'and provided no flags' do diff --git a/spec/unit/pdk/cli/util_spec.rb b/spec/unit/pdk/cli/util_spec.rb index b1adc55c1..c9c9175da 100644 --- a/spec/unit/pdk/cli/util_spec.rb +++ b/spec/unit/pdk/cli/util_spec.rb @@ -201,8 +201,7 @@ end before do - allow(PDK::Util::PuppetVersion).to receive(:puppet_dev_path).and_return(puppet_version) - allow(PDK::Util::PuppetVersion).to receive(:puppet_dev_env).and_return(version_result) + allow(PDK::Util::PuppetVersion).to receive_messages(puppet_dev_path: puppet_version, puppet_dev_env: version_result) allow(PDK::Util::PuppetVersion).to receive(:fetch_puppet_dev) end @@ -222,8 +221,7 @@ end before do - allow(PDK::Util::PuppetVersion).to receive(:puppet_dev_path).and_return(puppet_version) - allow(PDK::Util::PuppetVersion).to receive(:puppet_dev_env).and_return(version_result) + allow(PDK::Util::PuppetVersion).to receive_messages(puppet_dev_path: puppet_version, puppet_dev_env: version_result) allow(PDK::Util::Env).to receive(:[]).with('PDK_PUPPET_DEV').and_return('true') allow(PDK::Util::PuppetVersion).to receive(:fetch_puppet_dev) end @@ -283,8 +281,7 @@ let(:puppet_version) { '8.1.0' } before do - allow(PDK::Util::PuppetVersion).to receive(:from_module_metadata).and_return(nil) - allow(PDK::Util::PuppetVersion).to receive(:latest_available).and_return(version_result) + allow(PDK::Util::PuppetVersion).to receive_messages(from_module_metadata: nil, latest_available: version_result) end it_behaves_like 'it returns a puppet environment' diff --git a/spec/unit/pdk/generate/module_spec.rb b/spec/unit/pdk/generate/module_spec.rb index 5129d8258..029a51cb8 100644 --- a/spec/unit/pdk/generate/module_spec.rb +++ b/spec/unit/pdk/generate/module_spec.rb @@ -24,8 +24,7 @@ allow(renderer).to receive(:render).and_yield(*yielded_file) allow(test_template_path).to receive(:+).with(anything).and_return(test_template_path) - allow(test_template_path).to receive(:dirname).and_return(test_template_path) - allow(test_template_path).to receive(:relative?).and_return(true) + allow(test_template_path).to receive_messages(dirname: test_template_path, relative?: true) # TODO: This is overkill. e.g. this breaks using 'require 'pry'; binding.pry'. allow(Pathname).to receive(:new).with(anything).and_return(test_template_path) allow(PDK::Util::Filesystem).to receive(:write_file) @@ -88,8 +87,7 @@ allow(described_class).to receive(:prepare_module_directory).with(temp_target_dir) allow(PDK::Util::Filesystem).to receive(:write_file).with(/pdk-test-writable/, anything) { raise Errno::EACCES unless target_parent_writeable } allow(PDK::Util::Filesystem).to receive(:rm_f).with(/pdk-test-writable/) - allow(PDK::Util).to receive(:module_root).and_return(nil) - allow(PDK::Util).to receive(:package_install?).and_return(false) + allow(PDK::Util).to receive_messages(module_root: nil, package_install?: false) end context 'when the parent directory of the target is not writable' do @@ -256,8 +254,7 @@ context 'and no template-url answer exists' do context 'and pdk is installed from packages' do before do - allow(PDK::Util).to receive(:package_install?).and_return(true) - allow(PDK::Util).to receive(:package_cachedir).and_return('/tmp/package/cache') + allow(PDK::Util).to receive_messages(package_install?: true, package_cachedir: '/tmp/package/cache') end it 'uses the vendored template url' do diff --git a/spec/unit/pdk/generate/puppet_object_spec.rb b/spec/unit/pdk/generate/puppet_object_spec.rb index 952c83b51..c92cc7e3b 100644 --- a/spec/unit/pdk/generate/puppet_object_spec.rb +++ b/spec/unit/pdk/generate/puppet_object_spec.rb @@ -25,8 +25,7 @@ before do stub_const('PDK::Generate::PuppetObject::OBJECT_TYPE', object_type) - allow(PDK::Util).to receive(:package_install?).and_return(false) - allow(PDK::Util).to receive(:module_root).and_return(module_dir) + allow(PDK::Util).to receive_messages(package_install?: false, module_root: module_dir) end describe '#spec_only?' do @@ -133,9 +132,7 @@ before do # Mock required PuppetObject methods - allow(templated_object).to receive(:friendly_name).and_return('spec_object') - allow(templated_object).to receive(:template_files).and_return('source' => 'target') - allow(templated_object).to receive(:templates).and_return(templates) + allow(templated_object).to receive_messages(friendly_name: 'spec_object', template_files: { 'source' => 'target' }, templates: templates) allow(PDK::Template).to receive(:with) # An unknown uri will not yield allow(PDK::Template).to receive(:with).with(uri_of('expected1'), pdk_context).and_yield(expected1_template_dir) @@ -213,12 +210,9 @@ before do # Mock required PuppetObject methods - allow(templated_object).to receive(:template_files).and_return(template_files) - allow(templated_object).to receive(:template_data).and_return({}) - allow(templated_object).to receive(:friendly_name).and_return('spec_object') - allow(templated_object).to receive(:non_template_files).and_return(non_template_files) + allow(templated_object).to receive_messages(template_files: template_files, template_data: {}, friendly_name: 'spec_object', non_template_files: non_template_files, + update_manager_instance: update_manager) # Mock external objects - allow(templated_object).to receive(:update_manager_instance).and_return(update_manager) allow(templated_object).to receive(:with_templates).and_yield(template_dir) # Mock rendering of the template file allow(template_dir).to receive(:render_single_item).and_return('mock response') diff --git a/spec/unit/pdk/module/convert_spec.rb b/spec/unit/pdk/module/convert_spec.rb index 075593cbe..0352647c1 100644 --- a/spec/unit/pdk/module/convert_spec.rb +++ b/spec/unit/pdk/module/convert_spec.rb @@ -630,8 +630,7 @@ def module_path(relative_path) before do allow(PDK::Util::PuppetStrings).to receive(:all_objects).and_return(objects) - allow(PDK::Util).to receive(:module_root).and_return(module_root) - allow(PDK::Util).to receive(:module_metadata).and_return(metadata) + allow(PDK::Util).to receive_messages(module_root: module_root, module_metadata: metadata) end let(:metadata) { { 'name' => 'myuser-mymodule' } } @@ -674,8 +673,7 @@ def module_path(relative_path) before do allow(PDK::Util::PuppetStrings).to receive(:all_objects).and_return(objects) - allow(PDK::Util).to receive(:module_root).and_return(module_root) - allow(PDK::Util).to receive(:module_metadata).and_return(metadata) + allow(PDK::Util).to receive_messages(module_root: module_root, module_metadata: metadata) allow(PDK).to receive(:context).and_return(pdk_context) end diff --git a/spec/unit/pdk/module/release_spec.rb b/spec/unit/pdk/module/release_spec.rb index 023894b1c..964cb46dc 100644 --- a/spec/unit/pdk/module/release_spec.rb +++ b/spec/unit/pdk/module/release_spec.rb @@ -24,8 +24,7 @@ before do # Mimic PDK being run in the root of a module in current working directory - allow(PDK::Util).to receive(:find_upwards).and_return(nil) - allow(PDK::Util).to receive(:in_module_root?).and_return(true) + allow(PDK::Util).to receive_messages(find_upwards: nil, in_module_root?: true) allow(Dir).to receive(:pwd).and_return(module_root) allow(PDK::Util::ChangelogGenerator).to receive(:changelog_content).and_return('This is a changelog') @@ -170,9 +169,7 @@ context 'when skipping the build' do before do - allow(instance).to receive(:skip_build?).and_return(true) - allow(instance).to receive(:forge_upload_url).and_return('https://localhost') - allow(instance).to receive(:forge_token).and_return('abc123') + allow(instance).to receive_messages(skip_build?: true, forge_upload_url: 'https://localhost', forge_token: 'abc123') end it 'uses the default package filename when a file is not specified to publish' do @@ -190,9 +187,7 @@ context 'when running the build helper' do before do - allow(instance).to receive(:skip_build?).and_return(false) - allow(instance).to receive(:forge_upload_url).and_return('https://localhost') - allow(instance).to receive(:forge_token).and_return('abc123') + allow(instance).to receive_messages(skip_build?: false, forge_upload_url: 'https://localhost', forge_token: 'abc123') end it 'uses the built tarball to publish' do @@ -238,9 +233,7 @@ # under test really needs to be refactored before do - allow(PDK::CLI::Util).to receive(:validate_puppet_version_opts).and_return(nil) - allow(PDK::CLI::Util).to receive(:module_version_check).and_return(nil) - allow(PDK::CLI::Util).to receive(:puppet_from_opts_or_env).and_return(gemset: {}, ruby_version: '1.2.3') + allow(PDK::CLI::Util).to receive_messages(validate_puppet_version_opts: nil, module_version_check: nil, puppet_from_opts_or_env: { gemset: {}, ruby_version: '1.2.3' }) allow(PDK::Util::PuppetVersion).to receive(:fetch_puppet_dev).and_return(nil) allow(PDK::Util::RubyVersion).to receive(:use).and_return(nil) allow(PDK::Util::Bundler).to receive(:ensure_bundle!).and_return(nil) @@ -321,8 +314,7 @@ # under test really needs to be refactored before do - allow(instance).to receive(:forge_token).and_return('abc123') - allow(instance).to receive(:forge_upload_url).and_return('https://badapi.puppetlabs.com/v3/releases') + allow(instance).to receive_messages(forge_token: 'abc123', forge_upload_url: 'https://badapi.puppetlabs.com/v3/releases') allow(PDK::Util::Filesystem).to receive(:file?).with(tarball_path).and_return(true) allow(PDK::Util::Filesystem).to receive(:read_file).with(tarball_path, Hash).and_return('tarball_contents') allow(Net::HTTP).to receive(:start).and_return(http_response) @@ -358,21 +350,17 @@ end it 'raises when missing the forge upload url' do - allow(instance).to receive(:forge_upload_url).and_return(nil) - allow(instance).to receive(:forge_token).and_return('abc123') + allow(instance).to receive_messages(forge_upload_url: nil, forge_token: 'abc123') expect { instance.validate_publish_options! }.to raise_error(PDK::CLI::ExitWithError) end it 'raises when missing the forge token' do - allow(instance).to receive(:forge_upload_url).and_return('https://localhost') - allow(instance).to receive(:forge_token).and_return(nil) + allow(instance).to receive_messages(forge_upload_url: 'https://localhost', forge_token: nil) expect { instance.validate_publish_options! }.to raise_error(PDK::CLI::ExitWithError) end it 'does not raise when publishing is skipped' do - allow(instance).to receive(:skip_publish?).and_return(true) - allow(instance).to receive(:forge_upload_url).and_return(nil) - allow(instance).to receive(:forge_token).and_return(nil) + allow(instance).to receive_messages(skip_publish?: true, forge_upload_url: nil, forge_token: nil) expect { instance.validate_publish_options! }.not_to raise_error end end diff --git a/spec/unit/pdk/module/update_spec.rb b/spec/unit/pdk/module/update_spec.rb index 584aa13b7..833f4b0dc 100644 --- a/spec/unit/pdk/module/update_spec.rb +++ b/spec/unit/pdk/module/update_spec.rb @@ -398,9 +398,8 @@ def module_path(relative_path) context 'and PDK is running from a package install' do before do - allow(PDK::Util).to receive(:package_install?).and_return(true) + allow(PDK::Util).to receive_messages(package_install?: true, package_cachedir: File.join('package', 'cachedir')) allow(PDK::Util::Version).to receive(:git_ref).and_return('1234acb') - allow(PDK::Util).to receive(:package_cachedir).and_return(File.join('package', 'cachedir')) end it 'returns the default ref' do diff --git a/spec/unit/pdk/util/bundler_spec.rb b/spec/unit/pdk/util/bundler_spec.rb index 9a8f3b081..a2ce0e235 100644 --- a/spec/unit/pdk/util/bundler_spec.rb +++ b/spec/unit/pdk/util/bundler_spec.rb @@ -60,8 +60,7 @@ context 'when there is an existing Gemfile.lock' do before do - allow(bundle_helper).to receive(:locked?).and_return(true) - allow(bundle_helper).to receive(:installed?).and_return(true) + allow(bundle_helper).to receive_messages(locked?: true, installed?: true) end it 'updates Gemfile.lock using default sources' do @@ -83,8 +82,7 @@ context 'when there is no Gemfile.lock' do before do - allow(bundle_helper).to receive(:locked?).and_return(false) - allow(bundle_helper).to receive(:installed?).and_return(true) + allow(bundle_helper).to receive_messages(locked?: false, installed?: true) allow(bundle_helper).to receive(:update_lock!).with(any_args) end @@ -97,10 +95,8 @@ context 'when there are missing gems' do before do - allow(bundle_helper).to receive(:locked?).and_return(true) + allow(bundle_helper).to receive_messages(locked?: true, installed?: false) allow(bundle_helper).to receive(:update_lock!) - - allow(bundle_helper).to receive(:installed?).and_return(false) end it 'installs missing gems' do @@ -112,10 +108,8 @@ context 'when there are no missing gems' do before do - allow(bundle_helper).to receive(:locked?).and_return(true) + allow(bundle_helper).to receive_messages(locked?: true, installed?: true) allow(bundle_helper).to receive(:update_lock!) - - allow(bundle_helper).to receive(:installed?).and_return(true) end it 'does not try to install missing gems' do @@ -127,9 +121,8 @@ context 'when everything goes well' do before do - allow(bundle_helper).to receive(:locked?).and_return(true) + allow(bundle_helper).to receive_messages(locked?: true, installed?: true) allow(bundle_helper).to receive(:update_lock!) - allow(bundle_helper).to receive(:installed?).and_return(true) end it 'marks gemfile as bundled' do diff --git a/spec/unit/pdk/util/git_spec.rb b/spec/unit/pdk/util/git_spec.rb index e62bc64c3..e9cf3eb6a 100644 --- a/spec/unit/pdk/util/git_spec.rb +++ b/spec/unit/pdk/util/git_spec.rb @@ -84,8 +84,7 @@ context 'when maybe_repo has neither a working tree or a bare repository' do before do - allow(described_class).to receive(:bare_repo?).and_return(false) - allow(described_class).to receive(:work_tree?).and_return(false) + allow(described_class).to receive_messages(bare_repo?: false, work_tree?: false) end it { is_expected.to be_falsey } diff --git a/spec/unit/pdk/util/ruby_version_spec.rb b/spec/unit/pdk/util/ruby_version_spec.rb index f72aed592..a3e75b97b 100644 --- a/spec/unit/pdk/util/ruby_version_spec.rb +++ b/spec/unit/pdk/util/ruby_version_spec.rb @@ -21,9 +21,7 @@ end before do - allow(PDK::Util).to receive(:package_install?).and_return(true) - allow(PDK::Util).to receive(:pdk_package_basedir).and_return(pdk_package_basedir) - allow(PDK::Util).to receive(:package_cachedir).and_return(package_cachedir) + allow(PDK::Util).to receive_messages(package_install?: true, pdk_package_basedir: pdk_package_basedir, package_cachedir: package_cachedir) allow(described_class).to receive(:scan_for_packaged_rubies).and_return(packaged_rubies) end end @@ -69,8 +67,7 @@ include_context 'is a package install' before do - allow(described_class).to receive(:versions).and_return(packaged_rubies) - allow(described_class).to receive(:default_ruby_version).and_return('2.4.4') + allow(described_class).to receive_messages(versions: packaged_rubies, default_ruby_version: '2.4.4') end it 'includes the path to the packaged ruby cachedir' do @@ -170,9 +167,8 @@ end before do - allow(instance).to receive(:gem_path).and_return(gem_path) + allow(instance).to receive_messages(gem_path: gem_path, gem_home: gem_home) allow(PDK::Util::Filesystem).to receive(:glob).with(gem_path_pattern).and_return(gem_path_results.keys) - allow(instance).to receive(:gem_home).and_return(gem_home) allow(PDK::Util::Filesystem).to receive(:glob).with(gem_home_pattern).and_return(gem_home_results.keys) gem_path_results.merge(gem_home_results).each do |spec_path, spec_definition| diff --git a/spec/unit/pdk/util/template_uri_spec.rb b/spec/unit/pdk/util/template_uri_spec.rb index 80e11f57b..95ddc31f3 100644 --- a/spec/unit/pdk/util/template_uri_spec.rb +++ b/spec/unit/pdk/util/template_uri_spec.rb @@ -11,8 +11,7 @@ before do PDK.config.set(['user', 'module_defaults', 'template-url'], nil) - allow(PDK::Util).to receive(:module_root).and_return(nil) - allow(PDK::Util).to receive(:package_install?).and_return(false) + allow(PDK::Util).to receive_messages(module_root: nil, package_install?: false) end describe '.new' do @@ -99,8 +98,7 @@ before do allow(PDK::Util::Git).to receive(:repo?).with(anything).and_return(true) - allow(PDK::Util).to receive(:module_root).and_return(module_root) - allow(PDK::Util).to receive(:development_mode?).and_return(false) + allow(PDK::Util).to receive_messages(module_root: module_root, development_mode?: false) end context 'when passed no options' do @@ -495,8 +493,7 @@ end before do - allow(PDK::Util).to receive(:module_root).and_return('/path/to/module') - allow(PDK::Util).to receive(:development_mode?).and_return(false) + allow(PDK::Util).to receive_messages(module_root: '/path/to/module', development_mode?: false) allow(PDK::Module::Metadata).to receive(:from_file).with('/path/to/module/metadata.json').and_return(mock_metadata) allow(PDK::Util::Filesystem).to receive(:file?).with('/path/to/module/metadata.json').and_return(true) allow(PDK::Util::Filesystem).to receive(:file?).with(/PDK_VERSION/).and_return(true) @@ -653,8 +650,7 @@ def allow_template_dir(root, valid) context 'when running PDK from a package' do before do - allow(PDK::Util).to receive(:package_install?).and_return(true) - allow(PDK::Util).to receive(:pdk_package_basedir).and_return('/opt/puppetlabs/pdk') + allow(PDK::Util).to receive_messages(package_install?: true, pdk_package_basedir: '/opt/puppetlabs/pdk') end context 'and using the packaged windows template' do diff --git a/spec/unit/pdk/util/vendored_file_spec.rb b/spec/unit/pdk/util/vendored_file_spec.rb index 9e8ab7456..3ed65d14f 100644 --- a/spec/unit/pdk/util/vendored_file_spec.rb +++ b/spec/unit/pdk/util/vendored_file_spec.rb @@ -18,8 +18,7 @@ let(:gem_vendored_content) { 'gem file content' } before do - allow(PDK::Util).to receive(:package_cachedir).and_return(package_cachedir) - allow(PDK::Util).to receive(:cachedir).and_return(cachedir) + allow(PDK::Util).to receive_messages(package_cachedir: package_cachedir, cachedir: cachedir) allow(PDK::Util::Filesystem).to receive(:read_file).with(package_vendored_path).and_return(package_vendored_content) allow(PDK::Util::Filesystem).to receive(:read_file).with(gem_vendored_path).and_return(gem_vendored_content) end @@ -66,8 +65,7 @@ context 'and the download succeeded' do before do allow(mock_http).to receive(:request).with(mock_request).and_return(mock_response) - allow(mock_response).to receive(:code).and_return('200') - allow(mock_response).to receive(:body).and_return(gem_vendored_content) + allow(mock_response).to receive_messages(code: '200', body: gem_vendored_content) allow(PDK::Util::Filesystem).to receive(:mkdir_p).with(File.dirname(gem_vendored_path)) allow(PDK::Util::Filesystem).to receive(:write_file).with(any_args) end @@ -87,8 +85,7 @@ context 'and the download failed' do before do allow(mock_http).to receive(:request).with(anything).and_return(mock_response) - allow(mock_response).to receive(:code).and_return('404') - allow(mock_response).to receive(:message).and_return('file not found') + allow(mock_response).to receive_messages(code: '404', message: 'file not found') end it 'raises a DownloadError' do diff --git a/spec/unit/pdk/validate/external_command_validator_spec.rb b/spec/unit/pdk/validate/external_command_validator_spec.rb index 2d9cc3d98..74e0f24d4 100644 --- a/spec/unit/pdk/validate/external_command_validator_spec.rb +++ b/spec/unit/pdk/validate/external_command_validator_spec.rb @@ -12,8 +12,7 @@ let(:report) { PDK::Report.new } before do - allow(validator).to receive(:name).and_return('mock_name') - allow(validator).to receive(:parse_targets).and_return(parsed_targets) + allow(validator).to receive_messages(name: 'mock_name', parse_targets: parsed_targets) end describe '.spinner' do @@ -249,10 +248,9 @@ before do # Disable the spinners - allow(validator).to receive(:spinners_enabled?).and_return(false) + allow(validator).to receive_messages(spinners_enabled?: false, invoke_style: :per_target) allow(PDK::Util::Bundler).to receive(:ensure_binstubs!).and_return(nil) # Force a command per target to test the execution grouping - allow(validator).to receive(:invoke_style).and_return(:per_target) allow(PDK::CLI::Exec::Command).to receive(:new).and_return(success_command, fail_command2, fail_command1) end diff --git a/spec/unit/pdk/validate/internal_ruby_validator_spec.rb b/spec/unit/pdk/validate/internal_ruby_validator_spec.rb index 2d68c4283..61b54d059 100644 --- a/spec/unit/pdk/validate/internal_ruby_validator_spec.rb +++ b/spec/unit/pdk/validate/internal_ruby_validator_spec.rb @@ -12,8 +12,7 @@ let(:report) { PDK::Report.new } before do - allow(validator).to receive(:name).and_return('mock_name') - allow(validator).to receive(:parse_targets).and_return(parsed_targets) + allow(validator).to receive_messages(name: 'mock_name', parse_targets: parsed_targets) end describe '.prepare_invoke!' do diff --git a/spec/unit/pdk/validate/validator_group_spec.rb b/spec/unit/pdk/validate/validator_group_spec.rb index 2ccd8c65b..628a05b0d 100644 --- a/spec/unit/pdk/validate/validator_group_spec.rb +++ b/spec/unit/pdk/validate/validator_group_spec.rb @@ -15,8 +15,7 @@ describe '.spinner' do context 'when spinners are enabled' do before do - allow(validator_group).to receive(:spinners_enabled?).and_return(true) - allow(validator_group).to receive(:validators).and_return([MockSuccessValidator]) + allow(validator_group).to receive_messages(spinners_enabled?: true, validators: [MockSuccessValidator]) end it 'returns a TTY Multi Spinner with spinner text' do