From 76401a2da9bc64a32a09f95884d361e5bc06a8fa Mon Sep 17 00:00:00 2001 From: Gavin Didrichsen Date: Fri, 1 Mar 2024 18:13:43 +0000 Subject: [PATCH 1/2] Fix RSpec/RepeatedSubjectCall RSpec/RepeatedSubjectCall: This rule is triggered when the subject is called multiple times in the same example. It's recommended to assign the result of the subject call to a variable and use that variable instead. This rule is important because it helps to prevent unnecessary computation and potential confusion. In RSpec, the subject is not memoized within an example, meaning that each call to subject will create a new instance of the object under test. This can lead to unexpected behavior if the object's state changes between calls. By assigning the subject to a variable and reusing that variable, you ensure that you're always working with the same object and avoid any potential confusion or bugs. Signed-off-by: Gavin Didrichsen --- spec/unit/puppet/modulebuilder/builder_spec.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/spec/unit/puppet/modulebuilder/builder_spec.rb b/spec/unit/puppet/modulebuilder/builder_spec.rb index f499b47..dc7bbb2 100644 --- a/spec/unit/puppet/modulebuilder/builder_spec.rb +++ b/spec/unit/puppet/modulebuilder/builder_spec.rb @@ -30,8 +30,9 @@ describe '#initialize' do context 'when the source does not exist' do it do - allow(builder).to receive(:file_directory?).with(module_source).and_return(false) - expect { builder.source }.to raise_error(ArgumentError, /does not exist/) + result = builder + allow(result).to receive(:file_directory?).with(module_source).and_return(false) + expect { result.source }.to raise_error(ArgumentError, /does not exist/) end end From 4a71c88e39044b561bd91e2381ceecddadcc4f2e Mon Sep 17 00:00:00 2001 From: Gavin Didrichsen Date: Fri, 1 Mar 2024 18:14:09 +0000 Subject: [PATCH 2/2] Fix RSpec/DescribedClass. This error appears something like ``RSpec/DescribedClass: Use `described_class` instead of `PDK::Util`.``. This rule is triggered when the class under test is referenced directly instead of using `described_class`. Signed-off-by: Gavin Didrichsen --- spec/unit/puppet/modulebuilder_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/unit/puppet/modulebuilder_spec.rb b/spec/unit/puppet/modulebuilder_spec.rb index f87efb2..947d9ad 100644 --- a/spec/unit/puppet/modulebuilder_spec.rb +++ b/spec/unit/puppet/modulebuilder_spec.rb @@ -2,6 +2,6 @@ RSpec.describe Puppet::Modulebuilder do it 'has a version number' do - expect(Puppet::Modulebuilder::VERSION).not_to be_nil + expect(described_class::VERSION).not_to be_nil end end