From e78ecf8948988656bcb83aff2587f1641099416d Mon Sep 17 00:00:00 2001 From: Bobosila Victor Date: Sat, 25 Sep 2021 12:55:25 +0300 Subject: (MODULES-11197) Update the pdk template to 2.2.0 --- spec/spec_helper.rb | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'spec') diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 29615cd..9b1fa6f 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,3 +1,9 @@ +# frozen_string_literal: true + +RSpec.configure do |c| + c.mock_with :rspec +end + require 'puppetlabs_spec_helper/module_spec_helper' require 'rspec-puppet-facts' @@ -31,16 +37,28 @@ default_facts.each do |fact, value| end RSpec.configure do |c| - c.mock_with :rspec c.default_facts = default_facts c.before :each do # set to strictest setting for testing # by default Puppet runs at warning level Puppet.settings[:strict] = :warning + Puppet.settings[:strict_variables] = true end c.filter_run_excluding(bolt: true) unless ENV['GEM_BOLT'] c.after(:suite) do end + + # Filter backtrace noise + backtrace_exclusion_patterns = [ + %r{spec_helper}, + %r{gems}, + ] + + if c.respond_to?(:backtrace_exclusion_patterns) + c.backtrace_exclusion_patterns = backtrace_exclusion_patterns + elsif c.respond_to?(:backtrace_clean_patterns) + c.backtrace_clean_patterns = backtrace_exclusion_patterns + end end # Ensures that a module is defined -- cgit v1.2.3 From 36a46c84de29e127dee95ebd5caa992ac39046b6 Mon Sep 17 00:00:00 2001 From: Bobosila Victor Date: Sat, 25 Sep 2021 13:15:58 +0300 Subject: (MODULES-11197) Rubocop fixes --- .rubocop.yml | 2 +- lib/puppet/type/host.rb | 6 +++--- spec/acceptance/tests/create_spec.rb | 4 ++-- spec/acceptance/tests/modify_spec.rb | 4 ++-- spec/shared_behaviours/all_parsedfile_providers.rb | 2 +- spec/unit/type/host_spec.rb | 8 ++++---- 6 files changed, 13 insertions(+), 13 deletions(-) (limited to 'spec') diff --git a/.rubocop.yml b/.rubocop.yml index 4416e78..de02624 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -121,7 +121,7 @@ Performance/SortReverse: Performance/Squeeze: Enabled: true Performance/StringInclude: - Enabled: true + Enabled: false Performance/Sum: Enabled: true Style/CollectionMethods: diff --git a/lib/puppet/type/host.rb b/lib/puppet/type/host.rb index 03059b9..0510180 100644 --- a/lib/puppet/type/host.rb +++ b/lib/puppet/type/host.rb @@ -46,8 +46,8 @@ Puppet::Type.newtype(:host) do validate do |value| # This regex already includes newline check. - raise Puppet::Error, _('Host aliases cannot include whitespace') if value =~ %r{\s} - raise Puppet::Error, _('Host aliases cannot be an empty string. Use an empty array to delete all host_aliases ') if value =~ %r{^\s*$} + raise Puppet::Error, _('Host aliases cannot include whitespace') if %r{\s}.match?(value) + raise Puppet::Error, _('Host aliases cannot be an empty string. Use an empty array to delete all host_aliases ') if %r{^\s*$}.match?(value) end end @@ -80,7 +80,7 @@ Puppet::Type.newtype(:host) do validate do |value| value.split('.').each do |hostpart| - if hostpart !~ %r{^([\w]+|[\w][\w\-]+[\w])$} + unless %r{^([\w]+|[\w][\w\-]+[\w])$}.match?(hostpart) raise Puppet::Error, _('Invalid host name') end end diff --git a/spec/acceptance/tests/create_spec.rb b/spec/acceptance/tests/create_spec.rb index 40267fd..f79452d 100644 --- a/spec/acceptance/tests/create_spec.rb +++ b/spec/acceptance/tests/create_spec.rb @@ -13,7 +13,7 @@ RSpec.context 'when creating host files' do on(agent, puppet_resource('host', 'test', 'ensure=present', 'ip=127.0.0.1', "target=#{target}")) on(agent, "cat #{target}") do |result| - fail_test 'record was not present' if result.stdout !~ %r{^127\.0\.0\.1[[:space:]]+test} + fail_test 'record was not present' unless %r{^127\.0\.0\.1[[:space:]]+test}.match?(result.stdout) end end @@ -23,7 +23,7 @@ RSpec.context 'when creating host files' do on(agent, "cat #{target}") do |result| fail_test 'alias was missing' unless - result.stdout =~ %r{^127\.0\.0\.7[[:space:]]+test[[:space:]]alias} + %r{^127\.0\.0\.7[[:space:]]+test[[:space:]]alias}.match?(result.stdout) end end diff --git a/spec/acceptance/tests/modify_spec.rb b/spec/acceptance/tests/modify_spec.rb index 6498ee0..d07bb23 100644 --- a/spec/acceptance/tests/modify_spec.rb +++ b/spec/acceptance/tests/modify_spec.rb @@ -16,7 +16,7 @@ RSpec.context 'when modifying host files' do on(agent, "cat #{target}") do |result| fail_test 'the address was not updated' unless - result.stdout =~ %r{^127\.0\.0\.10[[:space:]]+test[[:space:]]+alias[[:space:]]*$} + %r{^127\.0\.0\.10[[:space:]]+test[[:space:]]+alias[[:space:]]*$}.match?(result.stdout) end end @@ -27,7 +27,7 @@ RSpec.context 'when modifying host files' do on(agent, "cat #{target}") do |result| fail_test 'the alias was not updated' unless - result.stdout =~ %r{^127\.0\.0\.8[[:space:]]+test[[:space:]]+banzai[[:space:]]*$} + %r{^127\.0\.0\.8[[:space:]]+test[[:space:]]+banzai[[:space:]]*$}.match?(result.stdout) end end end diff --git a/spec/shared_behaviours/all_parsedfile_providers.rb b/spec/shared_behaviours/all_parsedfile_providers.rb index 1701fe3..321cd86 100644 --- a/spec/shared_behaviours/all_parsedfile_providers.rb +++ b/spec/shared_behaviours/all_parsedfile_providers.rb @@ -4,7 +4,7 @@ shared_examples_for 'all parsedfile providers' do |provider, *files| end files.flatten.each do |file| - it "should rewrite #{file} reasonably unchanged" do + it "rewrites #{file} reasonably unchanged" do allow(provider).to receive(:default_target).and_return(file) provider.prefetch diff --git a/spec/unit/type/host_spec.rb b/spec/unit/type/host_spec.rb index 54d9b75..3fa5985 100644 --- a/spec/unit/type/host_spec.rb +++ b/spec/unit/type/host_spec.rb @@ -12,13 +12,13 @@ describe Puppet::Type.type(:host) do describe 'when validating attributes' do [:name, :provider].each do |param| - it "should have a #{param} parameter" do + it "has a #{param} parameter" do expect(described_class.attrtype(param)).to eq(:param) end end [:ip, :target, :host_aliases, :comment, :ensure].each do |property| - it "should have a #{property} property" do + it "has a #{property} property" do expect(described_class.attrtype(property)).to eq(:property) end end @@ -256,7 +256,7 @@ describe Puppet::Type.type(:host) do '0:a:b:c:d:e:f::', '::0:a:b:c:d:e:f', # syntactically correct, but bad form (::0:... could be combined) 'a:b:c:d:e:f:0::'].each do |ip| - it "should accept #{ip.inspect} as an IPv6 address" do + it "accepts #{ip.inspect} as an IPv6 address" do expect { described_class.new(name: 'foo', ip: ip) }.not_to raise_error end end @@ -587,7 +587,7 @@ describe Puppet::Type.type(:host) do '1111::3333:4444:5555:6666:7777:8888:', '::3333:4444:5555:6666:7777:8888:', '::2222:3333:4444:5555:6666:7777:8888:'].each do |ip| - it "should reject #{ip.inspect} as an IPv6 address" do + it "rejects #{ip.inspect} as an IPv6 address" do expect { described_class.new(name: 'foo', ip: ip) }.to raise_error(Puppet::ResourceError, %r{Parameter ip failed}) end end -- cgit v1.2.3