|
17 | 17 | # make Puppet::Util::SUIDManager return something deterministic, not the |
18 | 18 | # uid of the user running the tests, except where overridden below. |
19 | 19 | before :each do |
20 | | - Puppet::Util::SUIDManager.stubs(:uid).returns 1234 |
| 20 | + allow(Puppet::Util::SUIDManager).to receive(:uid).and_return 1234 |
21 | 21 | end |
22 | 22 |
|
23 | 23 | describe '#read' do |
24 | 24 | before(:each) do |
25 | | - Puppet::Util.stubs(:uid).with(uid).returns 9000 |
| 25 | + allow(Puppet::Util).to receive(:uid).with(uid).and_return 9000 |
26 | 26 | end |
27 | 27 |
|
28 | 28 | it 'runs crontab -l as the target user' do |
29 | | - Puppet::Util::Execution |
30 | | - .expects(:execute) |
31 | | - .with(['crontab', '-l'], user_options) |
32 | | - .returns(Puppet::Util::Execution::ProcessOutput.new(crontab, 0)) |
33 | | - |
| 29 | + expect(Puppet::Util::Execution).to receive(:execute).with(['crontab', '-l'], user_options).and_return(Puppet::Util::Execution::ProcessOutput.new(crontab, 0)) |
34 | 30 | expect(cron.read).to eq(crontab) |
35 | 31 | end |
36 | 32 |
|
37 | 33 | it 'does not switch user if current user is the target user' do |
38 | | - Puppet::Util.expects(:uid).with(uid).twice.returns 9000 |
39 | | - Puppet::Util::SUIDManager.expects(:uid).returns 9000 |
40 | | - Puppet::Util::Execution |
41 | | - .expects(:execute).with(['crontab', '-l'], options) |
42 | | - .returns(Puppet::Util::Execution::ProcessOutput.new(crontab, 0)) |
| 34 | + expect(Puppet::Util).to receive(:uid).with(uid).twice.and_return 9000 |
| 35 | + expect(Puppet::Util::SUIDManager).to receive(:uid).and_return 9000 |
| 36 | + expect(Puppet::Util::Execution).to receive(:execute).with(['crontab', '-l'], options).and_return(Puppet::Util::Execution::ProcessOutput.new(crontab, 0)) |
43 | 37 | expect(cron.read).to eq(crontab) |
44 | 38 | end |
45 | 39 |
|
46 | 40 | it 'treats an absent crontab as empty' do |
47 | | - Puppet::Util::Execution.expects(:execute).with(['crontab', '-l'], user_options).raises(Puppet::ExecutionFailure, absent_crontab) |
| 41 | + expect(Puppet::Util::Execution).to receive(:execute).with(['crontab', '-l'], user_options).and_raise(Puppet::ExecutionFailure, absent_crontab) |
48 | 42 | expect(cron.read).to eq('') |
49 | 43 | end |
50 | 44 |
|
51 | 45 | it "treats a nonexistent user's crontab as empty" do |
52 | | - Puppet::Util.expects(:uid).with(uid).returns nil |
| 46 | + expect(Puppet::Util).to receive(:uid).with(uid).and_return nil |
53 | 47 |
|
54 | 48 | expect(cron.read).to eq('') |
55 | 49 | end |
56 | 50 |
|
57 | 51 | it 'returns empty if the user is not authorized to use cron' do |
58 | | - Puppet::Util::Execution.expects(:execute).with(['crontab', '-l'], user_options).raises(Puppet::ExecutionFailure, unauthorized_crontab) |
| 52 | + expect(Puppet::Util::Execution).to receive(:execute).with(['crontab', '-l'], user_options).and_raise(Puppet::ExecutionFailure, unauthorized_crontab) |
59 | 53 | expect(cron.read).to eq('') |
60 | 54 | end |
61 | 55 | end |
62 | 56 |
|
63 | 57 | describe '#remove' do |
64 | 58 | it 'runs crontab -r as the target user' do |
65 | | - Puppet::Util::Execution.expects(:execute).with(['crontab', '-r'], user_options) |
| 59 | + expect(Puppet::Util::Execution).to receive(:execute).with(['crontab', '-r'], user_options) |
66 | 60 | cron.remove |
67 | 61 | end |
68 | 62 |
|
69 | 63 | it 'does not switch user if current user is the target user' do |
70 | | - Puppet::Util.expects(:uid).with(uid).returns 9000 |
71 | | - Puppet::Util::SUIDManager.expects(:uid).returns 9000 |
72 | | - Puppet::Util::Execution.expects(:execute).with(['crontab', '-r'], options) |
| 64 | + expect(Puppet::Util).to receive(:uid).with(uid).and_return 9000 |
| 65 | + expect(Puppet::Util::SUIDManager).to receive(:uid).and_return 9000 |
| 66 | + expect(Puppet::Util::Execution).to receive(:execute).with(['crontab', '-r'], options) |
73 | 67 | cron.remove |
74 | 68 | end |
75 | 69 | end |
|
79 | 73 | let!(:tmp_cron_path) { tmp_cron.path } |
80 | 74 |
|
81 | 75 | before :each do |
82 | | - Puppet::Util.stubs(:uid).with(uid).returns 9000 |
83 | | - Tempfile.expects(:new).with("puppet_#{name}", encoding: Encoding.default_external).returns tmp_cron |
| 76 | + allow(Puppet::Util).to receive(:uid).with(uid).and_return 9000 |
| 77 | + allow(Tempfile).to receive(:new).with("puppet_#{name}", encoding: Encoding.default_external).and_return tmp_cron |
84 | 78 | end |
85 | 79 |
|
86 | 80 | after :each do |
87 | | - File.unstub(:chown) |
| 81 | + allow(File).to receive(:chown).and_call_original |
88 | 82 | end |
89 | 83 |
|
90 | 84 | it 'runs crontab as the target user on a temporary file' do |
91 | | - File.expects(:chown).with(9000, nil, tmp_cron_path) |
92 | | - Puppet::Util::Execution.expects(:execute).with(['crontab', tmp_cron_path], user_options) |
| 85 | + expect(File).to receive(:chown).with(9000, nil, tmp_cron_path) |
| 86 | + expect(Puppet::Util::Execution).to receive(:execute).with(['crontab', tmp_cron_path], user_options) |
93 | 87 |
|
94 | | - tmp_cron.expects(:print).with("foo\n") |
| 88 | + expect(tmp_cron).to receive(:print).with("foo\n") |
95 | 89 | cron.write "foo\n" |
96 | 90 |
|
97 | 91 | expect(Puppet::FileSystem).not_to exist(tmp_cron_path) |
98 | 92 | end |
99 | 93 |
|
100 | 94 | it 'does not switch user if current user is the target user' do |
101 | | - Puppet::Util::SUIDManager.expects(:uid).returns 9000 |
102 | | - File.expects(:chown).with(9000, nil, tmp_cron_path) |
103 | | - Puppet::Util::Execution.expects(:execute).with(['crontab', tmp_cron_path], options) |
| 95 | + expect(Puppet::Util::SUIDManager).to receive(:uid).and_return 9000 |
| 96 | + expect(File).to receive(:chown).with(9000, nil, tmp_cron_path) |
| 97 | + expect(Puppet::Util::Execution).to receive(:execute).with(['crontab', tmp_cron_path], options) |
104 | 98 |
|
105 | | - tmp_cron.expects(:print).with("foo\n") |
| 99 | + expect(tmp_cron).to receive(:print).with("foo\n") |
106 | 100 | cron.write "foo\n" |
107 | 101 |
|
108 | 102 | expect(Puppet::FileSystem).not_to exist(tmp_cron_path) |
|
0 commit comments