|
5 | 5 | describe 'cvmfspartsize' do |
6 | 6 | before do |
7 | 7 | Facter.clear |
8 | | - Facter::Util::Resolution.stubs(:which).with('df').returns('/usr/bin/df') |
9 | | - File.stubs(:exist?).with('/etc/cvmfs/cvmfsfacts.yaml').returns(true) |
10 | | - File.stubs(:open).with('/etc/cvmfs/cvmfsfacts.yaml').returns("---\ncvmfs_cache_base: /foo/bar\n") |
11 | | - Facter::Core::Execution.stubs(:execute).with('/usr/bin/df -m -P /foo/bar').returns(cvmfs_df_result) |
| 8 | + allow(Facter::Util::Resolution).to receive(:which).with('df').and_return('/usr/bin/df') |
| 9 | + allow(File).to receive(:exist?).with('/etc/cvmfs/cvmfsfacts.yaml').and_return(true) |
| 10 | + allow(File).to receive(:open).with('/etc/cvmfs/cvmfsfacts.yaml').and_return("---\ncvmfs_cache_base: /foo/bar\n") |
| 11 | + allow(Facter::Core::Execution).to receive(:execute).with('/usr/bin/df -m -P /foo/bar').and_return(cvmfs_df_result) |
12 | 12 | end |
13 | 13 |
|
14 | 14 | context 'working case' do |
15 | 15 | before do |
16 | | - File.stubs(:exist?).with('/foo/bar').returns(true) |
| 16 | + allow(File).to receive(:exist?).with('/foo/bar').and_return(true) |
17 | 17 | end |
18 | 18 |
|
19 | 19 | let(:cvmfs_df_result) { "/dev/nvme0n1p5 976 251 659 28% /foo/bar\n" } |
|
27 | 27 | let(:cvmfs_df_result) { :failed } |
28 | 28 |
|
29 | 29 | it 'does not return a fact' do |
30 | | - File.stubs(:exist?).with('/etc/cvmfs/cvmfsfacts.yaml').returns(false) |
| 30 | + allow(File).to receive(:exist?).with('/etc/cvmfs/cvmfsfacts.yaml').and_return(false) |
31 | 31 | expect(Facter.fact('cvmfspartsize').value).to be_nil |
32 | 32 | end |
33 | 33 | end |
34 | 34 |
|
35 | 35 | context 'df fails' do |
36 | 36 | before do |
37 | | - File.stubs(:exist?).with('/foo/bar').returns(false) |
| 37 | + allow(File).to receive(:exist?).with('/foo/bar').and_return(false) |
38 | 38 | end |
39 | 39 |
|
40 | 40 | let(:cvmfs_df_result) { :failed } |
41 | 41 |
|
42 | 42 | it 'does not return a fact' do |
43 | | - Facter::Core::Execution.stubs(:execute).with('/usr/bin/df -m -P /foo/bar').returns(:failed) |
| 43 | + allow(Facter::Core::Execution).to receive(:execute).with('/usr/bin/df -m -P /foo/bar').and_return(:failed) |
44 | 44 | expect(Facter.fact('cvmfspartsize').value).to be_nil |
45 | 45 | end |
46 | 46 | end |
|
0 commit comments