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

Fix rubocop warnings #1326

Merged
merged 2 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
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
17 changes: 11 additions & 6 deletions spec/support/file_based_namespaces.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
end

it 'raises PDK::Config::LoadError' do
expect { subject.parse_file(subject.file) {} }.to raise_error(PDK::Config::LoadError, /error/)
result = subject
expect { result.parse_file(result.file) {} }.to raise_error(PDK::Config::LoadError, /error/)
end
end

Expand All @@ -36,9 +37,10 @@
end

it 'raises PDK::Config::LoadError' do
result = subject
expect do
subject.parse_file(subject.file) {}
end.to raise_error(PDK::Config::LoadError, "Unable to open #{subject.file} for reading")
result.parse_file(result.file) {}
end.to raise_error(PDK::Config::LoadError, "Unable to open #{result.file} for reading")
end
end
end
Expand Down Expand Up @@ -75,7 +77,8 @@
end

it 'yields schema based settings' do
expect { |o| subject.parse_file(subject.file, &o) }.to yield_control
result = subject
expect { |o| result.parse_file(result.file, &o) }.to yield_control
end
end

Expand All @@ -102,7 +105,8 @@
end

it 'raises LoadError' do
expect { subject.parse_file(subject.file) { |i| } }.to raise_error(PDK::Config::LoadError)
result = subject
expect { result.parse_file(result.file) { |i| } }.to raise_error(PDK::Config::LoadError)
end
end
end
Expand Down Expand Up @@ -132,7 +136,8 @@
end

it 'does not yield any results' do
expect { |o| subject.parse_file(subject.file, &o) }.not_to yield_control
result = subject
expect { |o| result.parse_file(result.file, &o) }.not_to yield_control
end
end
end
Expand Down
5 changes: 3 additions & 2 deletions spec/unit/pdk/config/namespace_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,9 @@ def spec_simple_validator
end

it 'raises ArgumentError if key is a mount name' do
config.mount('invalid', PDK::Config::Namespace.new('invalid')) # rubocop:disable RSpec/DescribedClass No.
expect { config['invalid'] = 'baz' }.to raise_error(ArgumentError, /Namespace mounts can not be set a value/)
result = config
result.mount('invalid', PDK::Config::Namespace.new('invalid')) # rubocop:disable RSpec/DescribedClass No.
expect { result['invalid'] = 'baz' }.to raise_error(ArgumentError, /Namespace mounts can not be set a value/)
end

it 'raises ArgumentError if the setting is not valid' do
Expand Down
7 changes: 4 additions & 3 deletions spec/unit/pdk/config/setting_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,10 @@
end

it 'does not set the new value' do
expect(config_setting.value).to be_nil
expect { config_setting.value = new_value }.to raise_error(ArgumentError)
expect(config_setting.value).to be_nil
result = config_setting
expect(result.value).to be_nil
expect { result.value = new_value }.to raise_error(ArgumentError)
expect(result.value).to be_nil
end
end
end
Expand Down
26 changes: 13 additions & 13 deletions spec/unit/pdk/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -450,10 +450,10 @@ def project_config

context 'without forcing the change' do
it 'raises an error' do
result = config
# The old setting should exist
expect(config.get(['user', 'foo', 'bar'])).to eq([])

expect { config.set(setting, value) }.to raise_error(ArgumentError)
expect(result.get(['user', 'foo', 'bar'])).to eq([])
expect { result.set(setting, value) }.to raise_error(ArgumentError)
end
end

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions spec/unit/pdk/report_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions spec/unit/pdk/template/fetcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,25 @@
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

context 'given any other uri' do
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

describe '.with' do
let(:fetcher) { PDK::Template::Fetcher::AbstractFetcher.new(template_uri, fetcher_options) }
let(:fetcher) { described_class::AbstractFetcher.new(template_uri, fetcher_options) }

before do
allow(described_class).to receive(:instance).with(template_uri, fetcher_options).and_return(fetcher)
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/pdk/template/renderer/v1_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions spec/unit/pdk/template/renderer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions spec/unit/pdk/template_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions spec/unit/pdk/util/bundler_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/pdk/util/vendored_file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down
Loading