From f6c90313fe20c49dbc25f74dfa7e746b1837c6cd Mon Sep 17 00:00:00 2001 From: Steven Pritchard Date: Tue, 18 Jun 2024 16:10:00 -0500 Subject: [PATCH] Switch from mocha to rspec mocks (#52) --- spec/spec_helper.rb | 2 +- spec/unit/facter/ima_log_size_spec.rb | 6 +++--- spec/unit/facter/ima_security_attr_spec.rb | 12 ++++++------ 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 0669e1d..e233a58 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -89,7 +89,7 @@ def set_hieradata(hieradata) } c.mock_framework = :rspec - c.mock_with :mocha + c.mock_with :rspec c.module_path = File.join(fixture_path, 'modules') c.manifest_dir = File.join(fixture_path, 'manifests') if c.respond_to?(:manifest_dir) diff --git a/spec/unit/facter/ima_log_size_spec.rb b/spec/unit/facter/ima_log_size_spec.rb index 77b16ba..cc97e76 100644 --- a/spec/unit/facter/ima_log_size_spec.rb +++ b/spec/unit/facter/ima_log_size_spec.rb @@ -9,15 +9,15 @@ context 'the required file is not present' do it 'should return nil' do - File.stubs(:exists?).with('/sys/kernel/security/ima/ascii_runtime_measurements').returns false + allow(File).to receive(:exists?).with('/sys/kernel/security/ima/ascii_runtime_measurements').and_return false expect(Facter.fact(:ima_log_size).value).to eq nil end end context 'the required file is present' do it 'should read the contents of the file as an integer' do - File.stubs(:exists?).with('/sys/kernel/security/ima/ascii_runtime_measurements').returns true - Facter::Core::Execution.stubs(:execute).with('wc -c /sys/kernel/security/ima/ascii_runtime_measurements').returns '1337' + allow(File).to receive(:exists?).with('/sys/kernel/security/ima/ascii_runtime_measurements').and_return true + allow(Facter::Core::Execution).to receive(:execute).with('wc -c /sys/kernel/security/ima/ascii_runtime_measurements').and_return '1337' expect(Facter.fact(:ima_log_size).value).to eq 1337 end diff --git a/spec/unit/facter/ima_security_attr_spec.rb b/spec/unit/facter/ima_security_attr_spec.rb index b074883..0a0ca06 100644 --- a/spec/unit/facter/ima_security_attr_spec.rb +++ b/spec/unit/facter/ima_security_attr_spec.rb @@ -5,13 +5,13 @@ before :each do Facter.clear Facter.clear_messages - Facter.stubs(:value).with(:cmdline).returns({'ima_appraise_tcb' => "", 'foo' => 'bar' }) - Facter.stubs(:value).with(:puppet_vardir).returns('/tmp') + allow(Facter).to receive(:value).with(:cmdline).and_return({'ima_appraise_tcb' => "", 'foo' => 'bar' }) + allow(Facter).to receive(:value).with(:puppet_vardir).and_return('/tmp') end context 'The script is running' do before :each do - Facter::Core::Execution.stubs(:execute).with('ps -ef').returns 'All kinds of junk and ima_security_attr_update.sh' + allow(Facter::Core::Execution).to receive(:execute).with('ps -ef').and_return 'All kinds of junk and ima_security_attr_update.sh' end it 'should return updating' do @@ -20,10 +20,10 @@ end context 'The script is not running' do - before(:each) { Facter::Core::Execution.stubs(:execute).with('ps -ef').returns 'All kinds of junki\nAnd more junk\nbut not that which shall not be named'} + before(:each) { allow(Facter::Core::Execution).to receive(:execute).with('ps -ef').and_return 'All kinds of junki\nAnd more junk\nbut not that which shall not be named'} context 'The relabel file is not present' do - before(:each) { File.stubs(:exists?).with('/tmp/simp/.ima_relabel').returns(false) } + before(:each) { allow(File).to receive(:exists?).with('/tmp/simp/.ima_relabel').and_return(false) } it 'should return inactive' do expect(Facter.fact(:ima_security_attr).value).to eq 'inactive' @@ -31,7 +31,7 @@ end context 'The relabel file is present' do - before(:each) { File.stubs(:exists?).with('/tmp/simp/.ima_relabel').returns(true) } + before(:each) { allow(File).to receive(:exists?).with('/tmp/simp/.ima_relabel').and_return(true) } it 'should return inactive' do expect(Facter.fact(:ima_security_attr).value).to eq 'need_relabel'