|
12 | 12 | end |
13 | 13 |
|
14 | 14 | before do |
15 | | - described_class.stubs(:command).with(:pear).returns '/fake/pear' |
| 15 | + allow(described_class).to receive(:command).with(:pear).and_return '/fake/pear' |
16 | 16 | resource.provider = provider |
17 | 17 | end |
18 | 18 |
|
19 | 19 | describe '.instances' do |
20 | 20 | it 'returns an array of installed packages' do |
21 | | - described_class.expects(:pear). |
| 21 | + allow(described_class).to receive(:pear). |
22 | 22 | with('list', '-a'). |
23 | | - returns File.read(my_fixture('list_a')) |
| 23 | + and_return File.read(my_fixture('list_a')) |
24 | 24 |
|
25 | 25 | expect(described_class.instances.map(&:properties)).to eq [ |
26 | 26 | { name: 'Archive_Tar', vendor: 'pear.php.net', ensure: '1.4.0', provider: :pear }, |
|
33 | 33 | end |
34 | 34 |
|
35 | 35 | it 'ignores malformed lines' do |
36 | | - described_class.expects(:pear). |
| 36 | + allow(described_class).to receive(:pear). |
37 | 37 | with('list', '-a'). |
38 | | - returns 'aaa2.1' |
39 | | - Puppet.expects(:warning).with('Could not match aaa2.1') |
| 38 | + and_return 'aaa2.1' |
| 39 | + allow(Puppet).to receive(:warning).with('Could not match aaa2.1') |
40 | 40 | expect(described_class.instances).to eq [] |
41 | 41 | end |
42 | 42 | end |
43 | 43 |
|
44 | 44 | describe '#install' do |
45 | 45 | it 'installs a package' do |
46 | | - described_class.expects(:pear). |
| 46 | + allow(described_class).to receive(:pear). |
47 | 47 | with('-D', 'auto_discover=1', 'upgrade', '--alldeps', 'dummy') |
48 | 48 | provider.install |
49 | 49 | end |
50 | 50 |
|
51 | 51 | it 'installs a specific version' do |
52 | 52 | resource[:ensure] = '0.2' |
53 | | - described_class.expects(:pear). |
| 53 | + allow(described_class).to receive(:pear). |
54 | 54 | with('-D', 'auto_discover=1', 'upgrade', '--alldeps', '-f', 'dummy-0.2') |
55 | 55 | provider.install |
56 | 56 | end |
57 | 57 |
|
58 | 58 | it 'installs from a specific source' do |
59 | 59 | resource[:source] = 'pear.php.net/dummy' |
60 | | - described_class.expects(:pear). |
| 60 | + allow(described_class).to receive(:pear). |
61 | 61 | with('-D', 'auto_discover=1', 'upgrade', '--alldeps', 'pear.php.net/dummy') |
62 | 62 | provider.install |
63 | 63 | end |
64 | 64 |
|
65 | 65 | it 'installs a specific version from a specific source' do |
66 | 66 | resource[:ensure] = '0.2' |
67 | 67 | resource[:source] = 'pear.php.net/dummy' |
68 | | - described_class.expects(:pear). |
| 68 | + allow(described_class).to receive(:pear). |
69 | 69 | with('-D', 'auto_discover=1', 'upgrade', '--alldeps', '-f', 'pear.php.net/dummy-0.2') |
70 | 70 | provider.install |
71 | 71 | end |
72 | 72 |
|
73 | 73 | it 'uses the specified responsefile' do |
74 | 74 | resource[:responsefile] = '/fake/pearresponse' |
75 | | - Puppet::Util::Execution.expects(:execute). |
| 75 | + allow(Puppet::Util::Execution).to receive(:execute). |
76 | 76 | with( |
77 | 77 | ['/fake/pear', '-D', 'auto_discover=1', 'upgrade', '--alldeps', 'dummy'], |
78 | 78 | stdinfile: resource[:responsefile] |
|
82 | 82 |
|
83 | 83 | it 'accepts install_options' do |
84 | 84 | resource[:install_options] = ['--onlyreqdeps'] |
85 | | - described_class.expects(:pear). |
| 85 | + allow(described_class).to receive(:pear). |
86 | 86 | with('-D', 'auto_discover=1', 'upgrade', '--onlyreqdeps', 'dummy') |
87 | 87 | provider.install |
88 | 88 | end |
89 | 89 | end |
90 | 90 |
|
91 | 91 | describe '#query' do |
92 | 92 | it 'queries information about one package' do |
93 | | - described_class.expects(:pear). |
| 93 | + allow(described_class).to receive(:pear). |
94 | 94 | with('list', '-a'). |
95 | | - returns File.read(my_fixture('list_a')) |
| 95 | + and_return File.read(my_fixture('list_a')) |
96 | 96 |
|
97 | 97 | resource[:name] = 'pear' |
98 | 98 | expect(provider.query).to eq( |
|
103 | 103 |
|
104 | 104 | describe '#latest' do |
105 | 105 | it 'fetches the latest version available' do |
106 | | - described_class.expects(:pear). |
| 106 | + allow(described_class).to receive(:pear). |
107 | 107 | with('remote-info', 'Benchmark'). |
108 | | - returns File.read(my_fixture('remote-info_benchmark')) |
| 108 | + and_return File.read(my_fixture('remote-info_benchmark')) |
109 | 109 |
|
110 | 110 | resource[:name] = 'Benchmark' |
111 | 111 | expect(provider.latest).to eq '1.2.9' |
|
114 | 114 |
|
115 | 115 | describe '#uninstall' do |
116 | 116 | it 'uninstalls a package' do |
117 | | - described_class.expects(:pear). |
| 117 | + allow(described_class).to receive(:pear). |
118 | 118 | with('uninstall', resource[:name]). |
119 | | - returns('uninstall ok') |
| 119 | + and_return('uninstall ok') |
120 | 120 | provider.uninstall |
121 | 121 | end |
122 | 122 |
|
123 | 123 | it 'raises an error otherwise' do |
124 | | - described_class.expects(:pear). |
| 124 | + allow(described_class).to receive(:pear). |
125 | 125 | with('uninstall', resource[:name]). |
126 | | - returns('unexpected output') |
| 126 | + and_return('unexpected output') |
127 | 127 | expect { provider.uninstall }.to raise_error(Puppet::Error) |
128 | 128 | end |
129 | 129 | end |
|
132 | 132 | it 'ignores the resource version' do |
133 | 133 | resource[:ensure] = '2.0' |
134 | 134 |
|
135 | | - described_class.expects(:pear). |
| 135 | + allow(described_class).to receive(:pear). |
136 | 136 | with('-D', 'auto_discover=1', 'upgrade', '--alldeps', 'dummy') |
137 | 137 | provider.update |
138 | 138 | end |
|
0 commit comments