|
1 | 1 | # frozen_string_literal: true |
2 | 2 |
|
3 | 3 | require 'spec_helper' |
4 | | -require_relative '../../../tasks/init' |
| 4 | +# require_relative '../../../tasks/init' |
| 5 | +require File.dirname(__FILE__) + '/../../../tasks/init.rb' |
5 | 6 |
|
6 | 7 | describe Reboot::Task do # rubocop:disable RSpec/FilePath |
7 | 8 | context 'on Windows' do |
8 | | - before(:each) { Facter.stubs(:value).with(:kernel).returns('windows') } |
| 9 | + before(:each) do |
| 10 | + allow(Facter).to receive(:value).with(:kernel).and_return('windows') |
| 11 | + end |
9 | 12 |
|
10 | 13 | context 'when rebooting' do |
11 | 14 | let(:reboot) { described_class.new } |
12 | 15 |
|
13 | 16 | it 'runs the correct command' do |
14 | 17 | command = 'shutdown.exe /r /t 3 /d p:4:1 ' |
15 | | - reboot.expects(:shutdown_executable_windows).returns('shutdown.exe') |
16 | | - reboot.expects(:async_command).with(command).returns(nil) |
| 18 | + expect(reboot).to receive(:shutdown_executable_windows).and_return('shutdown.exe') |
| 19 | + expect(reboot).to receive(:async_command).with(command).and_return(nil) |
17 | 20 | reboot.execute! |
18 | 21 | end |
19 | 22 |
|
|
22 | 25 |
|
23 | 26 | it 'handles the timeout' do |
24 | 27 | command = 'shutdown.exe /r /t 20 /d p:4:1 ' |
25 | | - reboot.expects(:shutdown_executable_windows).returns('shutdown.exe') |
26 | | - reboot.expects(:async_command).with(command).returns(nil) |
| 28 | + expect(reboot).to receive(:shutdown_executable_windows).and_return('shutdown.exe') |
| 29 | + expect(reboot).to receive(:async_command).with(command).and_return(nil) |
27 | 30 | reboot.execute! |
28 | 31 | end |
29 | 32 |
|
30 | 33 | it 'does not allow timeouts < 3' do |
31 | 34 | reboot = described_class.new('timeout' => 0) |
32 | 35 | command = 'shutdown.exe /r /t 3 /d p:4:1 ' |
33 | | - reboot.expects(:shutdown_executable_windows).returns('shutdown.exe') |
34 | | - reboot.expects(:async_command).with(command).returns(nil) |
| 36 | + expect(reboot).to receive(:shutdown_executable_windows).and_return('shutdown.exe') |
| 37 | + expect(reboot).to receive(:async_command).with(command).and_return(nil) |
35 | 38 | reboot.execute! |
36 | 39 | end |
37 | 40 | end |
|
42 | 45 |
|
43 | 46 | it 'runs the correct command' do |
44 | 47 | command = 'shutdown.exe /s /t 3 /d p:4:1 ' |
45 | | - reboot.expects(:shutdown_executable_windows).returns('shutdown.exe') |
46 | | - reboot.expects(:async_command).with(command).returns(nil) |
| 48 | + expect(reboot).to receive(:shutdown_executable_windows).and_return('shutdown.exe') |
| 49 | + expect(reboot).to receive(:async_command).with(command).and_return(nil) |
47 | 50 | reboot.execute! |
48 | 51 | end |
49 | 52 | end |
50 | 53 | end |
51 | 54 |
|
52 | 55 | context 'on Solaris' do |
53 | | - before(:each) { Facter.stubs(:value).with(:kernel).returns('SunOS') } |
| 56 | + before(:each) { allow(Facter).to receive(:value).with(:kernel).and_return('SunOS') } |
54 | 57 |
|
55 | 58 | context 'when rebooting' do |
56 | 59 | let(:reboot) { described_class.new } |
57 | 60 |
|
58 | 61 | it 'runs the correct command' do |
59 | 62 | # Enforces minimum 3s timeout. |
60 | 63 | command = ['shutdown', '-y', '-i', '6', '-g', 3, "''", '</dev/null', '>/dev/null', '2>&1', '&'] |
61 | | - reboot.expects(:async_command).with(command).returns(nil) |
| 64 | + expect(reboot).to receive(:async_command).with(command).and_return(nil) |
62 | 65 | reboot.execute! |
63 | 66 | end |
64 | 67 |
|
|
67 | 70 |
|
68 | 71 | it 'handles the timeout' do |
69 | 72 | command = ['shutdown', '-y', '-i', '6', '-g', 20, "''", '</dev/null', '>/dev/null', '2>&1', '&'] |
70 | | - reboot.expects(:async_command).with(command).returns(nil) |
| 73 | + expect(reboot).to receive(:async_command).with(command).and_return(nil) |
71 | 74 | reboot.execute! |
72 | 75 | end |
73 | 76 | end |
|
79 | 82 | it 'runs the correct command' do |
80 | 83 | # Enforces minimum 3s timeout. |
81 | 84 | command = ['shutdown', '-y', '-i', '5', '-g', 3, "''", '</dev/null', '>/dev/null', '2>&1', '&'] |
82 | | - reboot.expects(:async_command).with(command).returns(nil) |
| 85 | + expect(reboot).to receive(:async_command).with(command).and_return(nil) |
83 | 86 | reboot.execute! |
84 | 87 | end |
85 | 88 | end |
86 | 89 | end |
87 | 90 |
|
88 | 91 | context 'on Linux' do |
89 | | - before(:each) { Facter.stubs(:value).with(:kernel).returns('Linux') } |
| 92 | + before(:each) { allow(Facter).to receive(:value).with(:kernel).and_return('Linux') } |
90 | 93 |
|
91 | 94 | context 'when rebooting' do |
92 | 95 | let(:reboot) { described_class.new } |
93 | 96 |
|
94 | 97 | it 'runs the correct command' do |
95 | 98 | command = ['shutdown', '-r', 'now', "''", '</dev/null', '>/dev/null', '2>&1', '&'] |
96 | 99 | # Enforces minimum 3s timeout. |
97 | | - reboot.expects(:async_command).with(command, 3).returns(nil) |
| 100 | + expect(reboot).to receive(:async_command).with(command, 3).and_return(nil) |
98 | 101 | reboot.execute! |
99 | 102 | end |
100 | 103 |
|
|
103 | 106 |
|
104 | 107 | it 'handles the timeout by sleeping' do |
105 | 108 | command = ['shutdown', '-r', 'now', "''", '</dev/null', '>/dev/null', '2>&1', '&'] |
106 | | - reboot.expects(:async_command).with(command, 20).returns(nil) |
| 109 | + expect(reboot).to receive(:async_command).with(command, 20).and_return(nil) |
107 | 110 | reboot.execute! |
108 | 111 | end |
109 | 112 | end |
|
113 | 116 |
|
114 | 117 | it 'handles the timeout by sleeping' do |
115 | 118 | command = ['shutdown', '-r', '+1', "''", '</dev/null', '>/dev/null', '2>&1', '&'] |
116 | | - reboot.expects(:async_command).with(command, 30).returns(nil) |
| 119 | + expect(reboot).to receive(:async_command).with(command, 30).and_return(nil) |
117 | 120 | reboot.execute! |
118 | 121 | end |
119 | 122 | end |
|
125 | 128 | it 'runs the correct command' do |
126 | 129 | # Enforces minimum 3s timeout. |
127 | 130 | command = ['shutdown', '-P', 'now', "''", '</dev/null', '>/dev/null', '2>&1', '&'] |
128 | | - reboot.expects(:async_command).with(command, 3).returns(nil) |
| 131 | + expect(reboot).to receive(:async_command).with(command, 3).and_return(nil) |
129 | 132 | reboot.execute! |
130 | 133 | end |
131 | 134 | end |
|
0 commit comments