Skip to content

Commit

Permalink
Switch from mocha to rspec mocks
Browse files Browse the repository at this point in the history
  • Loading branch information
silug committed Jun 18, 2024
1 parent c9420c8 commit 80897c8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions spec/unit/facter/ima_log_size_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions spec/unit/facter/ima_security_attr_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -20,18 +20,18 @@
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'
end
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'
Expand Down

0 comments on commit 80897c8

Please sign in to comment.