diff --git a/.rubocop.yml b/.rubocop.yml index 241a8c9d18..20dac8c1d3 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -53,6 +53,12 @@ Naming/VariableNumber: - 'lib/facter/resolvers/windows/ffi/networking_ffi.rb' - 'lib/facter/util/facts/windows_release_finder.rb' +RSpec/MultipleMemoizedHelpers: + Enabled: false + +RSpec/StubbedMock: + Enabled: false + Style/IfUnlessModifier: Enabled: false @@ -67,3 +73,43 @@ Style/GlobalStdStream: - 'lib/facter/framework/logging/logger.rb' - 'spec/framework/core/fact/internal/internal_fact_manager_spec.rb' - 'spec/framework/logging/logger_spec.rb' + +RSpec/DescribedClass: + EnforcedStyle: explicit + +RSpec/ExampleLength: + Enabled: false + +# It is sometimes better to expect().to receive().and_return +# or to receive different messages. +RSpec/MessageSpies: + Enabled: false + +RSpec/MultipleExpectations: + Max: 3 + +RSpec/MultipleMemoizedHelpers: + Enabled: false + +RSpec/NestedGroups: + Enabled: 6 + +RSpec/SubjectStub: + Exclude: + - 'spec/custom_facts/core/aggregate_spec.rb' + - 'spec/custom_facts/core/resolvable_spec.rb' + - 'spec/custom_facts/util/fact_spec.rb' + - 'spec/custom_facts/util/resolution_spec.rb' + +# Prefer instance_double/instance_spy over double/spy because only methods +# defined on the underlying object can be stubbed. FFI and some Windows +# code can't be verified because of the way we fake out those classes. +RSpec/VerifiedDoubles: + Enabled: true + Exclude: + - 'spec/custom_facts/**/*' + - 'spec/facter/resolvers/aix/hardware_spec.rb' + - 'spec/facter/resolvers/*/ffi_helper_spec.rb' + - 'spec/facter/resolvers/windows/*' + - 'spec/facter/util/windows/network_utils_spec.rb' + - 'spec/facter/util/windows/win32ole_spec.rb' diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 3239cc990d..4cc40fa416 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -6,95 +6,12 @@ # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 3 -# This cop supports safe autocorrection (--autocorrect). -Performance/RegexpMatch: - Exclude: - - 'install.rb' - -# Offense count: 1490 -# This cop supports unsafe autocorrection (--autocorrect-all). -# Configuration parameters: SkipBlocks, EnforcedStyle. -# SupportedStyles: described_class, explicit -RSpec/DescribedClass: - Enabled: false - -# Offense count: 192 -# Configuration parameters: CountAsOne. -RSpec/ExampleLength: - Max: 34 - -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: CustomTransform, IgnoredWords, DisallowedExamples. -# DisallowedExamples: works -RSpec/ExampleWording: - Exclude: - - 'spec/custom_facts/core/execution/windows_spec.rb' - # Offense count: 70 # Configuration parameters: Include, CustomTransform, IgnoreMethods, SpecSuffixOnly. # Include: **/*_spec*rb*, **/spec/**/* RSpec/FilePath: Enabled: false -# Offense count: 15 -# Configuration parameters: AssignmentOnly. -RSpec/InstanceVariable: - Exclude: - - 'spec/custom_facts/core/execution/fact_manager_spec.rb' - - 'spec/custom_facts/util/collection_spec.rb' - - 'spec/custom_facts/util/confine_spec.rb' - -# Offense count: 8 -RSpec/LeakyConstantDeclaration: - Exclude: - - 'spec/custom_facts/core/resolvable_spec.rb' - - 'spec/custom_facts/core/suitable_spec.rb' - - 'spec/custom_facts/util/collection_spec.rb' - - 'spec/facter/resolvers/macosx/mountpoints_spec.rb' - - 'spec/facter/util/windows/network_utils_spec.rb' - -# Offense count: 51 -# Configuration parameters: EnforcedStyle. -# SupportedStyles: have_received, receive -RSpec/MessageSpies: - Enabled: false - -# Offense count: 13 -RSpec/MultipleExpectations: - Max: 3 - -# Offense count: 166 -# Configuration parameters: AllowSubject. -RSpec/MultipleMemoizedHelpers: - Max: 16 - -# Offense count: 241 -# Configuration parameters: AllowedGroups. -RSpec/NestedGroups: - Max: 6 - -# Offense count: 3 -RSpec/StubbedMock: - Exclude: - - 'spec/custom_facts/core/execution/fact_manager_spec.rb' - - 'spec/custom_facts/util/confine_spec.rb' - - 'spec/custom_facts/util/parser_spec.rb' - -# Offense count: 6 -RSpec/SubjectStub: - Exclude: - - 'spec/custom_facts/core/aggregate_spec.rb' - - 'spec/custom_facts/core/resolvable_spec.rb' - - 'spec/custom_facts/util/fact_spec.rb' - - 'spec/custom_facts/util/resolution_spec.rb' - -# Offense count: 114 -# Configuration parameters: IgnoreNameless, IgnoreSymbolicNames. -RSpec/VerifiedDoubles: - Enabled: false - # Need to remove logger class variables Style/ClassVars: Exclude: diff --git a/install.rb b/install.rb index 730b17e1b0..12a8878632 100755 --- a/install.rb +++ b/install.rb @@ -40,7 +40,7 @@ class Installer # Returns true if OS is windows (copied from facter/util/config.rb) def windows? - (defined?(RbConfig) ? RbConfig : Config)::CONFIG['host_os'] =~ /mswin|win32|dos|mingw|cygwin/i + (defined?(RbConfig) ? RbConfig : Config)::CONFIG['host_os'].match?(/mswin|win32|dos|mingw|cygwin/i) end def glob(list) @@ -153,7 +153,7 @@ def prepare_installation # /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin # which is not generally where people expect executables to be installed # These settings are appropriate defaults for all OS X versions. - RbConfig::CONFIG['bindir'] = '/usr/bin' if RUBY_PLATFORM =~ /^universal-darwin[\d.]+$/ + RbConfig::CONFIG['bindir'] = '/usr/bin' if RUBY_PLATFORM.match?(/^universal-darwin[\d.]+$/) # if InstallOptions.configdir # configdir = InstallOptions.configdir @@ -173,10 +173,10 @@ def prepare_installation else sitelibdir = RbConfig::CONFIG['sitelibdir'] if sitelibdir.nil? - sitelibdir = $LOAD_PATH.find { |x| x =~ /site_ruby/ } + sitelibdir = $LOAD_PATH.find { |x| x.match?(/site_ruby/) } if sitelibdir.nil? sitelibdir = File.join(libdir, 'site_ruby') - elsif sitelibdir !~ Regexp.quote(version) + elsif !sitelibdir.match?(Regexp.quote(version)) sitelibdir = File.join(sitelibdir, version) end end @@ -232,7 +232,7 @@ def install_binfile(from, op_file, target) File.open(tmp_file.path, 'w') do |op| op.puts "#!#{ruby}" contents = ip.readlines - contents.shift if contents[0] =~ /^#!/ + contents.shift if contents[0].match?(/^#!/) op.write contents.join end end diff --git a/spec/custom_facts/core/execution/fact_manager_spec.rb b/spec/custom_facts/core/execution/fact_manager_spec.rb index 2db211dc5c..1a6ce8f7f6 100644 --- a/spec/custom_facts/core/execution/fact_manager_spec.rb +++ b/spec/custom_facts/core/execution/fact_manager_spec.rb @@ -4,6 +4,8 @@ subject(:executor) { Facter::Core::Execution::Posix.new } describe '#with_env' do + let(:sentinel_var) { :resolution_test_foo.to_s } + it "executes the caller's block with the specified env vars" do test_env = { 'LANG' => 'C', 'LC_ALL' => 'C', 'FOO' => 'BAR' } executor.with_env test_env do @@ -56,23 +58,21 @@ end it "is not affected by a 'return' statement in the yield block" do - @sentinel_var = :resolution_test_foo.to_s - # the intent of this test case is to test a yield block that contains a return statement. However, it's illegal # to use a return statement outside of a method, so we need to create one here to give scope to the 'return' def handy_method - ENV[@sentinel_var] = 'foo' - new_env = { @sentinel_var => 'bar' } + ENV[sentinel_var] = 'foo' + new_env = { sentinel_var => 'bar' } executor.with_env new_env do - ENV[@sentinel_var] = 'bar' + ENV[sentinel_var] = 'bar' return end end handy_method - expect(ENV[@sentinel_var]).to eq 'foo' + expect(ENV[sentinel_var]).to eq 'foo' end end diff --git a/spec/custom_facts/core/execution/windows_spec.rb b/spec/custom_facts/core/execution/windows_spec.rb index 275702b243..13f7d6f04c 100644 --- a/spec/custom_facts/core/execution/windows_spec.rb +++ b/spec/custom_facts/core/execution/windows_spec.rb @@ -82,7 +82,7 @@ expect(executor.which('foo.exe')).to eq 'C:\Windows\foo.exe' end - it "won't check all paths if one is executable" do + it 'does not check all paths if one is executable' do allow(File).to receive(:executable?).with('C:\Windows\system32\foo.exe').and_return false allow(File).to receive(:executable?).with('C:\Windows\foo.exe').and_return true diff --git a/spec/custom_facts/util/collection_spec.rb b/spec/custom_facts/util/collection_spec.rb index 7638a132cc..6ee3e0dab2 100755 --- a/spec/custom_facts/util/collection_spec.rb +++ b/spec/custom_facts/util/collection_spec.rb @@ -125,20 +125,21 @@ def load(collection) end describe 'when retrieving facts' do - before do - @fact = collection.add('YayNess') - end + let(:fact) { collection.add('YayNess') } + + # initialize + before { fact } it 'returns the fact instance specified by the name' do - expect(collection.fact('YayNess')).to equal(@fact) + expect(collection.fact('YayNess')).to equal(fact) end it 'is case-insensitive' do - expect(collection.fact('yayness')).to equal(@fact) + expect(collection.fact('yayness')).to equal(fact) end it 'treats strings and symbols equivalently' do - expect(collection.fact(:yayness)).to equal(@fact) + expect(collection.fact(:yayness)).to equal(fact) end it 'uses its loader to try to load the fact if no fact can be found' do diff --git a/spec/custom_facts/util/confine_spec.rb b/spec/custom_facts/util/confine_spec.rb index a7e80e2c31..0b1bdf628e 100755 --- a/spec/custom_facts/util/confine_spec.rb +++ b/spec/custom_facts/util/confine_spec.rb @@ -27,14 +27,15 @@ end describe 'when evaluating' do + let(:fact) { double 'fact' } + def confined(fact_value, *confines) - allow(@fact).to receive(:value).and_return fact_value + allow(fact).to receive(:value).and_return fact_value LegacyFacter::Util::Confine.new('yay', *confines).true? end before do - @fact = double 'fact' - allow(Facter).to receive(:[]).and_return @fact + allow(Facter).to receive(:[]).and_return fact end it 'returns false if the fact does not exist' do @@ -44,9 +45,9 @@ def confined(fact_value, *confines) end it 'uses the returned fact to get the value' do - allow(Facter).to receive(:[]).with('yay').and_return @fact + allow(Facter).to receive(:[]).with('yay').and_return fact - expect(@fact).to receive(:value).and_return nil + expect(fact).to receive(:value).and_return nil LegacyFacter::Util::Confine.new('yay', 'test').true? end @@ -120,13 +121,13 @@ def confined(fact_value, *confines) end it 'accepts and evaluate a block argument against the fact' do - allow(@fact).to receive(:value).and_return 'foo' + allow(fact).to receive(:value).and_return 'foo' confine = LegacyFacter::Util::Confine.new(:yay) { |f| f == 'foo' } expect(confine.true?).to be true end it 'returns false if the block raises a StandardError when checking a fact' do - allow(@fact).to receive(:value).and_return 'foo' + allow(fact).to receive(:value).and_return 'foo' confine = LegacyFacter::Util::Confine.new(:yay) { |_f| raise StandardError } expect(confine.true?).to be false end diff --git a/spec/facter/facts/macosx/memory/swap/capacity_spec.rb b/spec/facter/facts/macosx/memory/swap/capacity_spec.rb index 2db9dd22a7..724d18ee02 100644 --- a/spec/facter/facts/macosx/memory/swap/capacity_spec.rb +++ b/spec/facter/facts/macosx/memory/swap/capacity_spec.rb @@ -3,7 +3,7 @@ describe Facts::Macosx::Memory::Swap::Capacity do describe '#call_the_resolver' do it 'returns a fact' do - expected_fact = double(Facter::ResolvedFact, name: 'memory.swap.capacity', value: 1024) + expected_fact = instance_double(Facter::ResolvedFact, name: 'memory.swap.capacity', value: 1024) allow(Facter::Resolvers::Macosx::SwapMemory).to receive(:resolve).with(:capacity).and_return(1024) allow(Facter::ResolvedFact).to receive(:new).with('memory.swap.capacity', 1024).and_return(expected_fact) diff --git a/spec/facter/facts/macosx/memory/swap/used_bytes_spec.rb b/spec/facter/facts/macosx/memory/swap/used_bytes_spec.rb index 26578d2a56..5ec94c5cd6 100644 --- a/spec/facter/facts/macosx/memory/swap/used_bytes_spec.rb +++ b/spec/facter/facts/macosx/memory/swap/used_bytes_spec.rb @@ -3,7 +3,7 @@ describe Facts::Macosx::Memory::Swap::UsedBytes do describe '#call_the_resolver' do it 'returns a fact' do - expected_fact = double(Facter::ResolvedFact, name: 'memory.swap.used_bytes', value: 1024) + expected_fact = instance_double(Facter::ResolvedFact, name: 'memory.swap.used_bytes', value: 1024) allow(Facter::Resolvers::Macosx::SwapMemory).to receive(:resolve).with(:used_bytes).and_return(1024) allow(Facter::ResolvedFact).to receive(:new).with('memory.swap.used_bytes', 1024).and_return(expected_fact) diff --git a/spec/facter/facts/macosx/memory/system/capacity_spec.rb b/spec/facter/facts/macosx/memory/system/capacity_spec.rb index 4aeefb370d..ad614e2d08 100644 --- a/spec/facter/facts/macosx/memory/system/capacity_spec.rb +++ b/spec/facter/facts/macosx/memory/system/capacity_spec.rb @@ -3,7 +3,7 @@ describe Facts::Macosx::Memory::System::Capacity do describe '#call_the_resolver' do it 'returns a fact' do - expected_fact = double(Facter::ResolvedFact, name: 'memory.system.capacity', value: '15.53%') + expected_fact = instance_double(Facter::ResolvedFact, name: 'memory.system.capacity', value: '15.53%') allow(Facter::Resolvers::Macosx::SystemMemory).to receive(:resolve).with(:capacity).and_return('15.53%') allow(Facter::ResolvedFact).to receive(:new).with('memory.system.capacity', '15.53%').and_return(expected_fact) diff --git a/spec/facter/facts/macosx/memory/system/used_bytes_spec.rb b/spec/facter/facts/macosx/memory/system/used_bytes_spec.rb index ca6d05682f..a41dbe6928 100644 --- a/spec/facter/facts/macosx/memory/system/used_bytes_spec.rb +++ b/spec/facter/facts/macosx/memory/system/used_bytes_spec.rb @@ -3,7 +3,7 @@ describe Facts::Macosx::Memory::System::UsedBytes do describe '#call_the_resolver' do it 'returns a fact' do - expected_fact = double(Facter::ResolvedFact, name: 'memory.system.used_bytes', value: 1024) + expected_fact = instance_double(Facter::ResolvedFact, name: 'memory.system.used_bytes', value: 1024) allow(Facter::Resolvers::Macosx::SystemMemory).to receive(:resolve).with(:used_bytes).and_return(1024) allow(Facter::ResolvedFact).to receive(:new).with('memory.system.used_bytes', 1024).and_return(expected_fact) diff --git a/spec/facter/facts/windows/dmi/product/serial_number_spec.rb b/spec/facter/facts/windows/dmi/product/serial_number_spec.rb index f713ada40f..00f06ec246 100644 --- a/spec/facter/facts/windows/dmi/product/serial_number_spec.rb +++ b/spec/facter/facts/windows/dmi/product/serial_number_spec.rb @@ -5,8 +5,8 @@ subject(:fact) { Facts::Windows::Dmi::Product::SerialNumber.new } let(:value) { 'VMware-42 1a 0d 03 0a b7 98 28-78 98 5e 85 a0 ad 18 47' } - let(:expected_resolved_fact) { double(Facter::ResolvedFact, name: 'dmi.product.serial_number', value: value) } - let(:resolved_legacy_fact) { double(Facter::ResolvedFact, name: 'serialnumber', value: value, type: :legacy) } + let(:expected_resolved_fact) { instance_double(Facter::ResolvedFact, name: 'dmi.product.serial_number', value: value) } + let(:resolved_legacy_fact) { instance_double(Facter::ResolvedFact, name: 'serialnumber', value: value, type: :legacy) } before do allow(Facter::Resolvers::DMIBios).to receive(:resolve).with(:serial_number).and_return(value) diff --git a/spec/facter/facts/windows/hypervisors/hyperv_spec.rb b/spec/facter/facts/windows/hypervisors/hyperv_spec.rb index ac53f7a813..87a44520fb 100644 --- a/spec/facter/facts/windows/hypervisors/hyperv_spec.rb +++ b/spec/facter/facts/windows/hypervisors/hyperv_spec.rb @@ -4,7 +4,7 @@ describe '#call_the_resolver' do context 'when is not HyperV hypervisor' do it 'returns nil' do - expected_fact = double(Facter::ResolvedFact, name: 'hypervisors.hyperv', value: nil) + expected_fact = instance_double(Facter::ResolvedFact, name: 'hypervisors.hyperv', value: nil) allow(Facter::Resolvers::Windows::Virtualization).to receive(:resolve).with(:virtual).and_return('value') allow(Facter::Resolvers::DMIBios).to receive(:resolve).with(:manufacturer).and_return('value') allow(Facter::ResolvedFact).to receive(:new).with('hypervisors.hyperv', nil).and_return(expected_fact) @@ -16,7 +16,7 @@ context 'when is HyperV hypervisor and CpuidSource resolver returns the required output' do it 'returns a fact' do - expected_fact = double(Facter::ResolvedFact, name: 'hypervisors.hyperv', value: {}) + expected_fact = instance_double(Facter::ResolvedFact, name: 'hypervisors.hyperv', value: {}) allow(Facter::Resolvers::Windows::Virtualization).to receive(:resolve).with(:virtual).and_return('hyperv') allow(Facter::ResolvedFact).to receive(:new).with('hypervisors.hyperv', {}).and_return(expected_fact) @@ -27,7 +27,7 @@ context 'when is HyperV hypervisor and DmiBios resolver returns the required output' do it 'returns a fact' do - expected_fact = double(Facter::ResolvedFact, name: 'hypervisors.hyperv', value: {}) + expected_fact = instance_double(Facter::ResolvedFact, name: 'hypervisors.hyperv', value: {}) allow(Facter::Resolvers::Windows::Virtualization).to receive(:resolve).with(:virtual).and_return('value') allow(Facter::Resolvers::DMIBios).to receive(:resolve).with(:manufacturer).and_return('Microsoft Enterprise') allow(Facter::ResolvedFact).to receive(:new).with('hypervisors.hyperv', {}).and_return(expected_fact) diff --git a/spec/facter/facts/windows/hypervisors/kvm_spec.rb b/spec/facter/facts/windows/hypervisors/kvm_spec.rb index 2cb0ba980e..bf00e23958 100644 --- a/spec/facter/facts/windows/hypervisors/kvm_spec.rb +++ b/spec/facter/facts/windows/hypervisors/kvm_spec.rb @@ -4,7 +4,7 @@ describe '#call_the_resolver' do context 'when is not kvm hypervisor' do it 'returns nil' do - expected_fact = double(Facter::ResolvedFact, name: 'hypervisors.kvm', value: nil) + expected_fact = instance_double(Facter::ResolvedFact, name: 'hypervisors.kvm', value: nil) allow(Facter::Resolvers::Windows::Virtualization).to receive(:resolve).with(:virtual).and_return('value') allow(Facter::Resolvers::NetKVM).to receive(:resolve).with(:kvm).and_return(false) allow(Facter::Resolvers::DMIComputerSystem).to receive(:resolve).with(:name).and_return('value') @@ -17,7 +17,7 @@ context 'when is kvm hypervisor but product name is parallels' do it 'returns a fact' do - expected_fact = double(Facter::ResolvedFact, name: 'hypervisors.kvm', value: nil) + expected_fact = instance_double(Facter::ResolvedFact, name: 'hypervisors.kvm', value: nil) allow(Facter::Resolvers::Windows::Virtualization).to receive(:resolve).with(:virtual).and_return('kvm') allow(Facter::Resolvers::DMIComputerSystem).to receive(:resolve).with(:name).and_return('Parallels') allow(Facter::ResolvedFact).to receive(:new).with('hypervisors.kvm', nil).and_return(expected_fact) @@ -29,7 +29,7 @@ context 'when is kvm hypervisor and openstack' do it 'returns a fact' do - expected_fact = double(Facter::ResolvedFact, name: 'hypervisors.kvm', value: { openstack: true }) + expected_fact = instance_double(Facter::ResolvedFact, name: 'hypervisors.kvm', value: { openstack: true }) allow(Facter::Resolvers::Windows::Virtualization).to receive(:resolve).with(:virtual).and_return('kvm') allow(Facter::Resolvers::DMIComputerSystem).to receive(:resolve).with(:name).and_return('OpenStack') allow(Facter::Resolvers::DMIBios).to receive(:resolve).with(:manufacturer).and_return('value') @@ -44,7 +44,7 @@ context 'when is kvm hypervisor and gce' do it 'returns a fact' do - expected_fact = double(Facter::ResolvedFact, name: 'hypervisors.kvm', value: { google: true }) + expected_fact = instance_double(Facter::ResolvedFact, name: 'hypervisors.kvm', value: { google: true }) allow(Facter::Resolvers::Windows::Virtualization).to receive(:resolve).with(:virtual).and_return('gce') allow(Facter::Resolvers::NetKVM).to receive(:resolve).with(:kvm).and_return(true) allow(Facter::Resolvers::DMIComputerSystem).to receive(:resolve).with(:name).and_return('value') diff --git a/spec/facter/facts/windows/hypervisors/virtualbox_spec.rb b/spec/facter/facts/windows/hypervisors/virtualbox_spec.rb index 23e3968f29..1c3b18cac4 100644 --- a/spec/facter/facts/windows/hypervisors/virtualbox_spec.rb +++ b/spec/facter/facts/windows/hypervisors/virtualbox_spec.rb @@ -4,7 +4,7 @@ describe '#call_the_resolver' do context 'when is not Virtualbox hypervisor' do it 'returns nil' do - expected_fact = double(Facter::ResolvedFact, name: 'hypervisors.virtualbox', value: nil) + expected_fact = instance_double(Facter::ResolvedFact, name: 'hypervisors.virtualbox', value: nil) allow(Facter::Resolvers::Windows::Virtualization).to receive(:resolve).with(:virtual).and_return('value') allow(Facter::Resolvers::DMIComputerSystem).to receive(:resolve).with(:name).and_return('value') allow(Facter::ResolvedFact).to receive(:new).with('hypervisors.virtualbox', nil).and_return(expected_fact) @@ -16,7 +16,7 @@ context 'when is VirtualBox hypervisor and CpuidSource resolver returns the required output' do it 'returns a fact' do - expected_fact = double(Facter::ResolvedFact, name: 'hypervisors.virtualbox', value: + expected_fact = instance_double(Facter::ResolvedFact, name: 'hypervisors.virtualbox', value: { revision: ' 13.4', version: ' 13.4' }) allow(Facter::Resolvers::Windows::Virtualization).to receive(:resolve).with(:virtual).and_return('virtualbox') allow(Facter::Resolvers::Windows::Virtualization) @@ -33,7 +33,7 @@ context 'when is VirtualBox hypervisor and DMIComputerSystem resolver returns the required output' do it 'returns a fact' do - expected_fact = double(Facter::ResolvedFact, name: 'hypervisors.virtualbox', value: + expected_fact = instance_double(Facter::ResolvedFact, name: 'hypervisors.virtualbox', value: { revision: '', version: '' }) allow(Facter::Resolvers::Windows::Virtualization).to receive(:resolve).with(:virtual).and_return('value') allow(Facter::Resolvers::DMIComputerSystem).to receive(:resolve).with(:name).and_return('VirtualBox') diff --git a/spec/facter/facts/windows/hypervisors/vmware_spec.rb b/spec/facter/facts/windows/hypervisors/vmware_spec.rb index 22cfd83915..8409de3777 100644 --- a/spec/facter/facts/windows/hypervisors/vmware_spec.rb +++ b/spec/facter/facts/windows/hypervisors/vmware_spec.rb @@ -4,7 +4,7 @@ describe '#call_the_resolver' do context 'when is not VMware hypervisor' do it 'returns nil' do - expected_fact = double(Facter::ResolvedFact, name: 'hypervisors.vmware', value: nil) + expected_fact = instance_double(Facter::ResolvedFact, name: 'hypervisors.vmware', value: nil) allow(Facter::Resolvers::Windows::Virtualization).to receive(:resolve).with(:virtual).and_return('value') allow(Facter::Resolvers::DMIBios).to receive(:resolve).with(:manufacturer).and_return('value') allow(Facter::ResolvedFact).to receive(:new).with('hypervisors.vmware', nil).and_return(expected_fact) @@ -16,7 +16,7 @@ context 'when is VMware hypervisor and virtualization resolver returns the required output' do it 'returns a fact' do - expected_fact = double(Facter::ResolvedFact, name: 'hypervisors.vmware', value: {}) + expected_fact = instance_double(Facter::ResolvedFact, name: 'hypervisors.vmware', value: {}) allow(Facter::Resolvers::Windows::Virtualization).to receive(:resolve).with(:virtual).and_return('vmware') allow(Facter::ResolvedFact).to receive(:new).with('hypervisors.vmware', {}).and_return(expected_fact) @@ -27,7 +27,7 @@ context 'when is VMware hypervisor and DmiBios resolver returns the required output' do it 'returns a fact' do - expected_fact = double(Facter::ResolvedFact, name: 'hypervisors.vmware', value: {}) + expected_fact = instance_double(Facter::ResolvedFact, name: 'hypervisors.vmware', value: {}) allow(Facter::Resolvers::Windows::Virtualization).to receive(:resolve).with(:virtual).and_return('value') allow(Facter::Resolvers::DMIBios).to receive(:resolve).with(:manufacturer).and_return('VMware, Inc.') allow(Facter::ResolvedFact).to receive(:new).with('hypervisors.vmware', {}).and_return(expected_fact) diff --git a/spec/facter/facts/windows/hypervisors/xen_spec.rb b/spec/facter/facts/windows/hypervisors/xen_spec.rb index 17bdca285c..d28ab25c36 100644 --- a/spec/facter/facts/windows/hypervisors/xen_spec.rb +++ b/spec/facter/facts/windows/hypervisors/xen_spec.rb @@ -4,7 +4,7 @@ describe '#call_the_resolver' do context 'when is not xen hypervisor' do it 'returns nil' do - expected_fact = double(Facter::ResolvedFact, name: 'hypervisors.xen', value: nil) + expected_fact = instance_double(Facter::ResolvedFact, name: 'hypervisors.xen', value: nil) allow(Facter::Resolvers::Windows::Virtualization).to receive(:resolve).with(:virtual).and_return('value') allow(Facter::ResolvedFact).to receive(:new).with('hypervisors.xen', nil).and_return(expected_fact) @@ -15,7 +15,7 @@ context 'when is xen hypervisor and context not hvm' do it 'returns a fact' do - expected_fact = double(Facter::ResolvedFact, name: 'hypervisors.xen', value: { context: 'pv' }) + expected_fact = instance_double(Facter::ResolvedFact, name: 'hypervisors.xen', value: { context: 'pv' }) allow(Facter::Resolvers::Windows::Virtualization).to receive(:resolve).with(:virtual).and_return('xen') allow(Facter::Resolvers::DMIComputerSystem).to receive(:resolve).with(:name).and_return('PV domU') allow(Facter::ResolvedFact).to receive(:new) @@ -28,7 +28,7 @@ context 'when is xen hypervisor and context hvm' do it 'returns a fact' do - expected_fact = double(Facter::ResolvedFact, name: 'hypervisors.xen', value: { context: 'hvm' }) + expected_fact = instance_double(Facter::ResolvedFact, name: 'hypervisors.xen', value: { context: 'hvm' }) allow(Facter::Resolvers::Windows::Virtualization).to receive(:resolve).with(:virtual).and_return('xen') allow(Facter::Resolvers::DMIComputerSystem).to receive(:resolve).with(:name).and_return('HVM domU') allow(Facter::ResolvedFact).to receive(:new) diff --git a/spec/facter/facts/windows/identity/privileged_spec.rb b/spec/facter/facts/windows/identity/privileged_spec.rb index 932d5d60a9..49288c9704 100644 --- a/spec/facter/facts/windows/identity/privileged_spec.rb +++ b/spec/facter/facts/windows/identity/privileged_spec.rb @@ -3,7 +3,7 @@ describe Facts::Windows::Identity::Privileged do describe '#call_the_resolver' do it 'returns a fact' do - expected_fact = double(Facter::ResolvedFact, name: 'identity.privileged', value: 'value') + expected_fact = instance_double(Facter::ResolvedFact, name: 'identity.privileged', value: 'value') allow(Facter::Resolvers::Identity).to receive(:resolve).with(:privileged).and_return('value') allow(Facter::ResolvedFact).to receive(:new).with('identity.privileged', 'value').and_return(expected_fact) diff --git a/spec/facter/facts/windows/memory/system/capacity_spec.rb b/spec/facter/facts/windows/memory/system/capacity_spec.rb index 6656ce2dfd..1904d0095c 100644 --- a/spec/facter/facts/windows/memory/system/capacity_spec.rb +++ b/spec/facter/facts/windows/memory/system/capacity_spec.rb @@ -3,7 +3,7 @@ describe Facts::Windows::Memory::System::Capacity do describe '#call_the_resolver' do it 'returns a fact' do - expected_fact = double(Facter::ResolvedFact, name: 'memory.system.capacity', value: 'value') + expected_fact = instance_double(Facter::ResolvedFact, name: 'memory.system.capacity', value: 'value') allow(Facter::Resolvers::Memory).to receive(:resolve).with(:capacity).and_return('value') allow(Facter::ResolvedFact).to receive(:new).with('memory.system.capacity', 'value').and_return(expected_fact) diff --git a/spec/facter/facts/windows/memory/system/used_bytes_spec.rb b/spec/facter/facts/windows/memory/system/used_bytes_spec.rb index 21194baced..7ac2053bbd 100644 --- a/spec/facter/facts/windows/memory/system/used_bytes_spec.rb +++ b/spec/facter/facts/windows/memory/system/used_bytes_spec.rb @@ -3,7 +3,7 @@ describe Facts::Windows::Memory::System::UsedBytes do describe '#call_the_resolver' do it 'returns a fact' do - expected_fact = double(Facter::ResolvedFact, name: 'memory.system.used_bytes', value: 1024) + expected_fact = instance_double(Facter::ResolvedFact, name: 'memory.system.used_bytes', value: 1024) allow(Facter::Resolvers::Memory).to receive(:resolve).with(:used_bytes).and_return(1024) allow(Facter::ResolvedFact).to receive(:new).with('memory.system.used_bytes', 1024).and_return(expected_fact) diff --git a/spec/facter/facts/windows/networking/interfaces_spec.rb b/spec/facter/facts/windows/networking/interfaces_spec.rb index c0df6ca8e0..e20a39a7d1 100644 --- a/spec/facter/facts/windows/networking/interfaces_spec.rb +++ b/spec/facter/facts/windows/networking/interfaces_spec.rb @@ -3,7 +3,7 @@ describe Facts::Windows::Networking::Interfaces do describe '#call_the_resolver' do it 'returns a fact' do - expected_fact = double(Facter::ResolvedFact, name: 'networking.interfaces', value: 'value') + expected_fact = instance_double(Facter::ResolvedFact, name: 'networking.interfaces', value: 'value') allow(Facter::Resolvers::Windows::Networking).to receive(:resolve).with(:interfaces).and_return('value') allow(Facter::ResolvedFact).to receive(:new).with('networking.interfaces', 'value').and_return(expected_fact) diff --git a/spec/facter/facts/windows/networking/mtu_spec.rb b/spec/facter/facts/windows/networking/mtu_spec.rb index a4616eb3dd..10b9dba2d5 100644 --- a/spec/facter/facts/windows/networking/mtu_spec.rb +++ b/spec/facter/facts/windows/networking/mtu_spec.rb @@ -3,7 +3,7 @@ describe Facts::Windows::Networking::Mtu do describe '#call_the_resolver' do it 'returns a fact' do - expected_fact = double(Facter::ResolvedFact, name: 'networking.mtu', value: 'value') + expected_fact = instance_double(Facter::ResolvedFact, name: 'networking.mtu', value: 'value') allow(Facter::Resolvers::Windows::Networking).to receive(:resolve).with(:mtu).and_return('value') allow(Facter::ResolvedFact).to receive(:new).with('networking.mtu', 'value').and_return(expected_fact) diff --git a/spec/facter/facts/windows/processors/models_spec.rb b/spec/facter/facts/windows/processors/models_spec.rb index 4e69d7df36..1a444e7a97 100644 --- a/spec/facter/facts/windows/processors/models_spec.rb +++ b/spec/facter/facts/windows/processors/models_spec.rb @@ -3,7 +3,7 @@ describe Facts::Windows::Processors::Models do describe '#call_the_resolver' do it 'returns a fact' do - expected_fact = double(Facter::ResolvedFact, name: 'processors.models', value: 'value') + expected_fact = instance_double(Facter::ResolvedFact, name: 'processors.models', value: 'value') allow(Facter::Resolvers::Processors).to receive(:resolve).with(:models).and_return('value') allow(Facter::ResolvedFact).to receive(:new).with('processors.models', 'value').and_return(expected_fact) diff --git a/spec/facter/query_parser_spec.rb b/spec/facter/query_parser_spec.rb index 360a5311b5..d1e3f11f73 100644 --- a/spec/facter/query_parser_spec.rb +++ b/spec/facter/query_parser_spec.rb @@ -8,9 +8,9 @@ os_name_class = 'Facter::Ubuntu::OsName' os_family_class = 'Facter::Ubuntu::OsFamily' - loaded_fact_os_name = double(Facter::LoadedFact, name: 'os.name', klass: os_name_class, type: :core, file: nil) - loaded_fact_os_family = double(Facter::LoadedFact, name: 'os.family', klass: os_family_class, type: :core, - file: nil) + loaded_fact_os_name = instance_double(Facter::LoadedFact, name: 'os.name', klass: os_name_class, type: :core, file: nil) + loaded_fact_os_family = instance_double(Facter::LoadedFact, name: 'os.family', klass: os_family_class, type: :core, + file: nil) loaded_facts = [loaded_fact_os_name, loaded_fact_os_family] matched_facts = Facter::QueryParser.parse(query_list, loaded_facts) @@ -25,10 +25,10 @@ networking_class = 'Facter::Ubuntu::NetworkInterface' os_family_class = 'Facter::Ubuntu::OsFamily' - loaded_fact_networking = double(Facter::LoadedFact, name: 'ipaddress_.*', klass: networking_class, type: :legacy, - file: nil) - loaded_fact_os_family = double(Facter::LoadedFact, name: 'os.family', klass: os_family_class, type: :core, - file: nil) + loaded_fact_networking = instance_double(Facter::LoadedFact, name: 'ipaddress_.*', klass: networking_class, type: :legacy, + file: nil) + loaded_fact_os_family = instance_double(Facter::LoadedFact, name: 'os.family', klass: os_family_class, type: :core, + file: nil) loaded_facts = [loaded_fact_networking, loaded_fact_os_family] matched_facts = Facter::QueryParser.parse(query_list, loaded_facts) @@ -57,8 +57,8 @@ query_list = ['custom_fact'] os_name_class = 'Facter::Ubuntu::OsName' - loaded_fact_os_name = double(Facter::LoadedFact, name: 'os.name', klass: os_name_class, type: :core, file: nil) - loaded_fact_custom_fact = double(Facter::LoadedFact, name: 'custom_fact', klass: nil, type: :custom, file: nil) + loaded_fact_os_name = instance_double(Facter::LoadedFact, name: 'os.name', klass: os_name_class, type: :core, file: nil) + loaded_fact_custom_fact = instance_double(Facter::LoadedFact, name: 'custom_fact', klass: nil, type: :custom, file: nil) loaded_facts = [loaded_fact_os_name, loaded_fact_custom_fact] matched_facts = Facter::QueryParser.parse(query_list, loaded_facts) @@ -70,7 +70,7 @@ it 'queries if param is symbol' do query_list = [:path] path_class = 'Facter::Ubuntu::Path' - loaded_fact_path = double(Facter::LoadedFact, name: 'path', klass: path_class, type: :core, file: nil) + loaded_fact_path = instance_double(Facter::LoadedFact, name: 'path', klass: path_class, type: :core, file: nil) loaded_facts = [loaded_fact_path] matched_facts = Facter::QueryParser.parse(query_list, loaded_facts) @@ -84,9 +84,9 @@ query_list = ['ldom.domainrole.impl'] ldom_class = 'Facter::Solaris::Ldom' - loaded_fact_ldom = double(Facter::LoadedFact, name: 'ldom', klass: ldom_class, type: :core, file: nil) - ldom_fact_ldom_alias = double(Facter::LoadedFact, name: 'ldom_domainrole_impl', klass: ldom_class, - type: :legacy, file: nil) + loaded_fact_ldom = instance_double(Facter::LoadedFact, name: 'ldom', klass: ldom_class, type: :core, file: nil) + ldom_fact_ldom_alias = instance_double(Facter::LoadedFact, name: 'ldom_domainrole_impl', klass: ldom_class, + type: :legacy, file: nil) loaded_facts = [loaded_fact_ldom, ldom_fact_ldom_alias] matched_facts = Facter::QueryParser.parse(query_list, loaded_facts) @@ -112,7 +112,7 @@ context 'when a fact name contains a regex special character' do let(:query_list) { ['regex(string'] } - let(:loaded_facts) { [double(Facter::LoadedFact, name: 'a_loaded_fact', klass: nil, type: :custom, file: nil)] } + let(:loaded_facts) { [instance_double(Facter::LoadedFact, name: 'a_loaded_fact', klass: nil, type: :custom, file: nil)] } it 'is escaped correctly and does not result in an unexpected regex parse error' do matched_facts = Facter::QueryParser.parse(query_list, loaded_facts) diff --git a/spec/facter/resolvers/freebsd/ffi_helper_spec.rb b/spec/facter/resolvers/freebsd/ffi_helper_spec.rb index 17302ae79b..9abc41520e 100644 --- a/spec/facter/resolvers/freebsd/ffi_helper_spec.rb +++ b/spec/facter/resolvers/freebsd/ffi_helper_spec.rb @@ -36,7 +36,7 @@ context 'when expecting an uint32_t' do let(:result) { 42 } - let(:oldlen) { double('Integer') } + let(:oldlen) { instance_double(Integer) } before do allow(FFI::MemoryPointer).to receive(:new) diff --git a/spec/facter/resolvers/macosx/mountpoints_spec.rb b/spec/facter/resolvers/macosx/mountpoints_spec.rb index f729ae92ae..a8def81cdb 100644 --- a/spec/facter/resolvers/macosx/mountpoints_spec.rb +++ b/spec/facter/resolvers/macosx/mountpoints_spec.rb @@ -8,14 +8,14 @@ class Error < StandardError; end describe Facter::Resolvers::Macosx::Mountpoints do let(:mount) do - double(Sys::Filesystem::Mount, mount_type: 'ext4', mount_point: '/proc/a', options: mount_options, - name: '/dev/nvme0n1p2', dump_frequency: 0, pass_number: 0) + instance_double(Sys::Filesystem::Mount, mount_type: 'ext4', mount_point: '/proc/a', + options: mount_options, name: '/dev/nvme0n1p2', dump_frequency: 0, pass_number: 0) end let(:stat) do - double(Sys::Filesystem::Stat, - path: '/proc/a', base_type: nil, fragment_size: 4096, block_size: 4096, blocks: 113_879_332, - blocks_available: 16_596_603, blocks_free: 22_398_776) + instance_double(Sys::Filesystem::Stat, path: '/proc/a', base_type: nil, fragment_size: 4096, + block_size: 4096, blocks: 113_879_332, + blocks_available: 16_596_603, blocks_free: 22_398_776) end let(:fact) do @@ -57,8 +57,8 @@ class Error < StandardError; end let(:fact_options) { %w[rw noatime] } let(:mount) do - double(Sys::Filesystem::Mount, mount_point: '/', mount_type: 'ext4', options: mount_options, - name: '/dev/root') + instance_double(Sys::Filesystem::Mount, mount_point: '/', mount_type: 'ext4', options: mount_options, + name: '/dev/root') end it 'looks up the actual device if /dev/root' do diff --git a/spec/facter/resolvers/mountpoints_spec.rb b/spec/facter/resolvers/mountpoints_spec.rb index 9618a08633..177487b170 100644 --- a/spec/facter/resolvers/mountpoints_spec.rb +++ b/spec/facter/resolvers/mountpoints_spec.rb @@ -2,16 +2,16 @@ describe Facter::Resolvers::Mountpoints do let(:mount) do - double(Sys::Filesystem::Mount, - mount_point: '/', mount_time: nil, - mount_type: 'ext4', options: 'rw,noatime', name: - '/dev/nvme0n1p2', dump_frequency: 0, pass_number: 0) + instance_double(Sys::Filesystem::Mount, + mount_point: '/', mount_time: nil, + mount_type: 'ext4', options: 'rw,noatime', + name: '/dev/nvme0n1p2', dump_frequency: 0, pass_number: 0) end let(:stat) do - double(Sys::Filesystem::Stat, - path: '/', base_type: nil, fragment_size: 4096, block_size: 4096, blocks: 113_879_332, - blocks_available: -16_596_603, blocks_free: 22_398_776) + instance_double(Sys::Filesystem::Stat, + path: '/', base_type: nil, fragment_size: 4096, block_size: 4096, blocks: 113_879_332, + blocks_available: -16_596_603, blocks_free: 22_398_776) end let(:fact) do @@ -29,8 +29,8 @@ end let(:ignored_mounts) do - [double(Sys::Filesystem::Mount, mount_type: 'ext4', mount_point: '/proc/a', name: '/dev/ignore', options: 'rw'), - double(Sys::Filesystem::Mount, mount_type: 'autofs', mount_point: '/mnt/auto', name: '/dev/ignore', options: 'rw')] + [instance_double(Sys::Filesystem::Mount, mount_type: 'ext4', mount_point: '/proc/a', name: '/dev/ignore', options: 'rw'), + instance_double(Sys::Filesystem::Mount, mount_type: 'autofs', mount_point: '/mnt/auto', name: '/dev/ignore', options: 'rw')] end before do @@ -109,7 +109,7 @@ describe '.root_device' do let(:mount) do - double(Sys::Filesystem::Mount, mount_point: '/', mount_type: 'ext4', options: 'rw,noatime', name: '/dev/root') + instance_double(Sys::Filesystem::Mount, mount_point: '/', mount_type: 'ext4', options: 'rw,noatime', name: '/dev/root') end it 'looks up the actual device if /dev/root' do diff --git a/spec/facter/resolvers/solaris/mountpoints_spec.rb b/spec/facter/resolvers/solaris/mountpoints_spec.rb index c5934df05d..4bc4a0c4f5 100644 --- a/spec/facter/resolvers/solaris/mountpoints_spec.rb +++ b/spec/facter/resolvers/solaris/mountpoints_spec.rb @@ -4,39 +4,39 @@ let(:resolver) { Facter::Resolvers::Solaris::Mountpoints } let(:mounts) do [ - object_double(Sys::Filesystem::Mount, - mount_point: '/', mount_time: nil, - mount_type: 'zfs', options: 'dev=4490002', name: - 'rpool/ROOT/solaris', dump_frequency: nil, pass_number: nil), - object_double(Sys::Filesystem::Mount, - mount_point: '/devices', mount_time: nil, - mount_type: 'devfs', options: 'dev=8580000', name: - '/devices', dump_frequency: nil, pass_number: nil), - object_double(Sys::Filesystem::Mount, - mount_point: '/proc', mount_time: nil, - mount_type: 'proc', options: 'dev=8600000', name: - 'proc', dump_frequency: nil, pass_number: nil), - object_double(Sys::Filesystem::Mount, - mount_point: '/net', mount_time: nil, - mount_type: 'autofs', options: 'nosuid,indirect,ignore,nobrowse,dev=8900007', name: - '-hosts', dump_frequency: nil, pass_number: nil), - object_double(Sys::Filesystem::Mount, - mount_point: '/home', mount_time: nil, - mount_type: 'autofs', options: 'indirect,ignore,nobrowse,dev=8900008', name: - 'auto_home', dump_frequency: nil, pass_number: nil), - object_double(Sys::Filesystem::Mount, - mount_point: '/home/user', mount_time: nil, - mount_type: 'zfs', options: 'dev=8900009', name: - 'rpool/user', dump_frequency: nil, pass_number: nil) + instance_double(Sys::Filesystem::Mount, + mount_point: '/', mount_time: nil, + mount_type: 'zfs', options: 'dev=4490002', name: + 'rpool/ROOT/solaris', dump_frequency: nil, pass_number: nil), + instance_double(Sys::Filesystem::Mount, + mount_point: '/devices', mount_time: nil, + mount_type: 'devfs', options: 'dev=8580000', name: + '/devices', dump_frequency: nil, pass_number: nil), + instance_double(Sys::Filesystem::Mount, + mount_point: '/proc', mount_time: nil, + mount_type: 'proc', options: 'dev=8600000', name: + 'proc', dump_frequency: nil, pass_number: nil), + instance_double(Sys::Filesystem::Mount, + mount_point: '/net', mount_time: nil, + mount_type: 'autofs', options: 'nosuid,indirect,ignore,nobrowse,dev=8900007', name: + '-hosts', dump_frequency: nil, pass_number: nil), + instance_double(Sys::Filesystem::Mount, + mount_point: '/home', mount_time: nil, + mount_type: 'autofs', options: 'indirect,ignore,nobrowse,dev=8900008', name: + 'auto_home', dump_frequency: nil, pass_number: nil), + instance_double(Sys::Filesystem::Mount, + mount_point: '/home/user', mount_time: nil, + mount_type: 'zfs', options: 'dev=8900009', name: + 'rpool/user', dump_frequency: nil, pass_number: nil) ] end let(:mount) { mounts.first } let(:stat) do - object_double('Sys::Filesystem::Stat', - path: '/', base_type: 'zfs', fragment_size: 512, block_size: 131_072, blocks: 20_143_706, - blocks_available: 11_731_043, blocks_free: 11_731_043) + instance_double('Sys::Filesystem::Stat', + path: '/', base_type: 'zfs', fragment_size: 512, block_size: 131_072, blocks: 20_143_706, + blocks_available: 11_731_043, blocks_free: 11_731_043) end let(:fact) do diff --git a/spec/framework/core/fact_loaders/external_fact_loader_spec.rb b/spec/framework/core/fact_loaders/external_fact_loader_spec.rb index 84e541b685..5c3e8a47cd 100644 --- a/spec/framework/core/fact_loaders/external_fact_loader_spec.rb +++ b/spec/framework/core/fact_loaders/external_fact_loader_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true describe Facter::ExternalFactLoader do - let(:collection) { double(LegacyFacter::Util::Collection) } + let(:collection) { instance_double(LegacyFacter::Util::Collection) } let(:external_fact) { Facter::Util::Fact.new('external_fact', options: { fact_type: :external }) } let(:custom_fact) { Facter::Util::Fact.new('custom_fact', options: { fact_type: :custom }) } diff --git a/spec/framework/core/session_cache_spec.rb b/spec/framework/core/session_cache_spec.rb index 4b0c9da822..e6a857bbcf 100644 --- a/spec/framework/core/session_cache_spec.rb +++ b/spec/framework/core/session_cache_spec.rb @@ -1,12 +1,12 @@ # frozen_string_literal: true describe Facter::SessionCache do - let(:uname_resolver) { spy(Facter::Resolvers::Uname) } + let(:uname_resolver) { Facter::Resolvers::Uname.new } it 'registers resolver subscription' do - Facter::SessionCache.subscribe(uname_resolver) - Facter::SessionCache.invalidate_all_caches + expect(uname_resolver.class).to receive(:invalidate_cache) - expect(uname_resolver).to have_received(:invalidate_cache) + Facter::SessionCache.subscribe(uname_resolver.class) + Facter::SessionCache.invalidate_all_caches end end diff --git a/spec/framework/formatters/hocon_fact_formatter_spec.rb b/spec/framework/formatters/hocon_fact_formatter_spec.rb index 59d05bc0e3..8d1838a9c2 100644 --- a/spec/framework/formatters/hocon_fact_formatter_spec.rb +++ b/spec/framework/formatters/hocon_fact_formatter_spec.rb @@ -3,14 +3,14 @@ describe Facter::HoconFactFormatter do it 'formats to hocon when no user query' do resolved_fact1 = - double(Facter::ResolvedFact, name: 'os.name', value: 'Darwin', - user_query: '', type: :core) + instance_double(Facter::ResolvedFact, name: 'os.name', value: 'Darwin', + user_query: '', type: :core) resolved_fact2 = - double(Facter::ResolvedFact, name: 'os.family', value: 'Darwin', - user_query: '', type: :core) + instance_double(Facter::ResolvedFact, name: 'os.family', value: 'Darwin', + user_query: '', type: :core) resolved_fact3 = - double(Facter::ResolvedFact, name: 'os.architecture', value: 'x86_64', - user_query: '', type: :core) + instance_double(Facter::ResolvedFact, name: 'os.architecture', value: 'x86_64', + user_query: '', type: :core) resolved_fact_list = [resolved_fact1, resolved_fact2, resolved_fact3] formatted_output = Facter::HoconFactFormatter.new.format(resolved_fact_list) @@ -22,8 +22,8 @@ it 'formats to hocon for a single user query' do resolved_fact = - double(Facter::ResolvedFact, name: 'os.name', value: 'Darwin', - user_query: 'os.name', type: :core) + instance_double(Facter::ResolvedFact, name: 'os.name', value: 'Darwin', + user_query: 'os.name', type: :core) resolved_fact_list = [resolved_fact] formatted_output = Facter::HoconFactFormatter.new.format(resolved_fact_list) @@ -34,11 +34,11 @@ it 'formats to hocon for multiple user queries' do resolved_fact1 = - double(Facter::ResolvedFact, name: 'os.name', value: 'Darwin', - user_query: 'os.name', type: :core) + instance_double(Facter::ResolvedFact, name: 'os.name', value: 'Darwin', + user_query: 'os.name', type: :core) resolved_fact2 = - double(Facter::ResolvedFact, name: 'os.family', value: 'Darwin', - user_query: 'os.family', type: :core) + instance_double(Facter::ResolvedFact, name: 'os.family', value: 'Darwin', + user_query: 'os.family', type: :core) resolved_fact_list = [resolved_fact1, resolved_fact2] formatted_output = Facter::HoconFactFormatter.new.format(resolved_fact_list) @@ -55,8 +55,8 @@ it 'returns empty string when the fact value is nil' do resolved_fact1 = - double(Facter::ResolvedFact, name: 'my_external_fact', value: nil, - user_query: 'my_external_fact', type: :core) + instance_double(Facter::ResolvedFact, name: 'my_external_fact', value: nil, + user_query: 'my_external_fact', type: :core) resolved_fact_list = [resolved_fact1] formatted_output = Facter::HoconFactFormatter.new.format(resolved_fact_list) diff --git a/spec/framework/formatters/json_fact_formatter_spec.rb b/spec/framework/formatters/json_fact_formatter_spec.rb index 13aca0c02d..e9928c03e9 100644 --- a/spec/framework/formatters/json_fact_formatter_spec.rb +++ b/spec/framework/formatters/json_fact_formatter_spec.rb @@ -3,18 +3,16 @@ describe Facter::JsonFactFormatter do it 'formats to json when no user query' do resolved_fact1 = - double(Facter::ResolvedFact, name: 'os.name', value: 'Darwin', - user_query: '', type: :core) + instance_double(Facter::ResolvedFact, name: 'os.name', value: 'Darwin', + user_query: '', type: :core) resolved_fact2 = - double(Facter::ResolvedFact, name: 'os.family', value: 'Darwin', - user_query: '', type: :core) + instance_double(Facter::ResolvedFact, name: 'os.family', value: 'Darwin', + user_query: '', type: :core) resolved_fact3 = - double(Facter::ResolvedFact, name: 'os.architecture', value: 'x86_64', - user_query: '', type: :core) + instance_double(Facter::ResolvedFact, name: 'os.architecture', value: 'x86_64', + user_query: '', type: :core) resolved_fact_list = [resolved_fact1, resolved_fact2, resolved_fact3] - double - formatted_output = Facter::JsonFactFormatter.new.format(resolved_fact_list) expected_output = @@ -25,8 +23,8 @@ it 'formats to json for a single user query' do resolved_fact = - double(Facter::ResolvedFact, name: 'os.name', value: 'Darwin', - user_query: 'os.name', type: :core) + instance_double(Facter::ResolvedFact, name: 'os.name', value: 'Darwin', + user_query: 'os.name', type: :core) resolved_fact_list = [resolved_fact] formatted_output = Facter::JsonFactFormatter.new.format(resolved_fact_list) @@ -37,11 +35,11 @@ it 'formats to json for multiple user queries' do resolved_fact1 = - double(Facter::ResolvedFact, name: 'os.name', value: 'Darwin', - user_query: 'os.name', type: :core) + instance_double(Facter::ResolvedFact, name: 'os.name', value: 'Darwin', + user_query: 'os.name', type: :core) resolved_fact2 = - double(Facter::ResolvedFact, name: 'os.family', value: 'Darwin', - user_query: 'os.family', type: :core) + instance_double(Facter::ResolvedFact, name: 'os.family', value: 'Darwin', + user_query: 'os.family', type: :core) resolved_fact_list = [resolved_fact1, resolved_fact2] formatted_output = Facter::JsonFactFormatter.new.format(resolved_fact_list) diff --git a/spec/mocks/sys_filesystem.rb b/spec/mocks/sys_filesystem.rb index 10fadb3bb0..1aca75d121 100644 --- a/spec/mocks/sys_filesystem.rb +++ b/spec/mocks/sys_filesystem.rb @@ -5,43 +5,92 @@ class Filesystem def self.mounts; end class Mount - def self.mount_point; end + # The name of the mounted resource. + attr_accessor :name - def self.mount_type; end + # The mount point/directory. + attr_accessor :mount_point - def self.options; end + # The type of filesystem mount, e.g. ufs, nfs, etc. + attr_accessor :mount_type - def self.mount_time; end + # A list of comma separated options for the mount, e.g. nosuid, etc. + attr_accessor :options - def self.name; end + # The time the filesystem was mounted. May be nil. + attr_accessor :mount_time - def self.dump_frequency; end + # The dump frequency in days. May be nil. + attr_accessor :dump_frequency - def self.pass_number; end + # The pass number of the filessytem check. May be nil. + attr_accessor :pass_number end class Stat - def self.path; end + # The path of the filesystem. + attr_accessor :path - def self.base_type; end + # The preferred system block size. + attr_accessor :block_size - def self.fragment_size; end + # The fragment size, i.e. fundamental filesystem block size. + attr_accessor :fragment_size - def self.block_size; end + # The total number of +fragment_size+ blocks in the filesystem. + attr_accessor :blocks - def self.blocks; end + # The total number of free blocks in the filesystem. + attr_accessor :blocks_free - def self.blocks_available; end + # The number of free blocks available to unprivileged processes. + attr_accessor :blocks_available - def self.blocks_free; end + # The total number of files/inodes that can be created. + attr_accessor :files - def self.bytes_total; end + # The total number of files/inodes on the filesystem. + attr_accessor :files_free - def self.bytes_available; end + # The number of free files/inodes available to unprivileged processes. + attr_accessor :files_available - def self.bytes_free; end + # The filesystem identifier. + attr_accessor :filesystem_id - def self.bytes_used; end + # A bit mask of flags. + attr_accessor :flags + + # The maximum length of a file name permitted on the filesystem. + attr_accessor :name_max + + # The filesystem type, e.g. UFS. + attr_accessor :base_type + + # Returns the total space on the partition. + def bytes_total + blocks * fragment_size + end + + # Returns the total amount of free space on the partition. + def bytes_free + blocks_free * fragment_size + end + + # Returns the amount of free space available to unprivileged processes. + def bytes_available + blocks_available * fragment_size + end + + # Returns the total amount of used space on the partition. + def bytes_used + bytes_total - bytes_free + end + + # Returns the percentage of the partition that has been used. + def percent_used + 100 - (100.0 * bytes_free.to_f / bytes_total.to_f) + end end end end diff --git a/spec/mocks/util.rb b/spec/mocks/util.rb index bbd5344bff..dd10dd7453 100644 --- a/spec/mocks/util.rb +++ b/spec/mocks/util.rb @@ -27,26 +27,26 @@ def mock_query_parser(user_query, loaded_fact_hash) .with(user_query, loaded_fact_hash) end -private_methods def allow_attr_change(resolved_fact_mock, fact_name, fact_value) +private_methods def allow_attr_change(resolved_fact_mock, fact_value) allow(resolved_fact_mock) .to receive(:value=) .with(fact_value) - allow(resolved_fact_mock) - .to receive(:name=) - .with(fact_name) - allow(resolved_fact_mock) .to receive(:user_query=) end def mock_resolved_fact(fact_name, fact_value, user_query = nil, type = :core) - resolved_fact_mock = double(Facter::ResolvedFact, name: fact_name, value: fact_value, - user_query: user_query, type: type, - legacy?: type == :legacy, core?: type == :core, file: nil, - resolves?: fact_name == user_query) + resolved_fact_mock = instance_double( + Facter::ResolvedFact, name: fact_name, value: fact_value, + user_query: user_query, type: type, + legacy?: type == :legacy, + core?: type == :core, + file: nil, + resolves?: fact_name == user_query + ) - allow_attr_change(resolved_fact_mock, fact_name, fact_value) + allow_attr_change(resolved_fact_mock, fact_value) resolved_fact_mock end