Skip to content

Commit 6295c99

Browse files
committed
Rewrite tests to use rspec-mocks
1 parent 5be3832 commit 6295c99

2 files changed

Lines changed: 32 additions & 32 deletions

File tree

spec/unit/provider/package/pear_spec.rb

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@
1212
end
1313

1414
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'
1616
resource.provider = provider
1717
end
1818

1919
describe '.instances' do
2020
it 'returns an array of installed packages' do
21-
described_class.expects(:pear).
21+
allow(described_class).to receive(:pear).
2222
with('list', '-a').
23-
returns File.read(my_fixture('list_a'))
23+
and_return File.read(my_fixture('list_a'))
2424

2525
expect(described_class.instances.map(&:properties)).to eq [
2626
{ name: 'Archive_Tar', vendor: 'pear.php.net', ensure: '1.4.0', provider: :pear },
@@ -33,46 +33,46 @@
3333
end
3434

3535
it 'ignores malformed lines' do
36-
described_class.expects(:pear).
36+
allow(described_class).to receive(:pear).
3737
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')
4040
expect(described_class.instances).to eq []
4141
end
4242
end
4343

4444
describe '#install' do
4545
it 'installs a package' do
46-
described_class.expects(:pear).
46+
allow(described_class).to receive(:pear).
4747
with('-D', 'auto_discover=1', 'upgrade', '--alldeps', 'dummy')
4848
provider.install
4949
end
5050

5151
it 'installs a specific version' do
5252
resource[:ensure] = '0.2'
53-
described_class.expects(:pear).
53+
allow(described_class).to receive(:pear).
5454
with('-D', 'auto_discover=1', 'upgrade', '--alldeps', '-f', 'dummy-0.2')
5555
provider.install
5656
end
5757

5858
it 'installs from a specific source' do
5959
resource[:source] = 'pear.php.net/dummy'
60-
described_class.expects(:pear).
60+
allow(described_class).to receive(:pear).
6161
with('-D', 'auto_discover=1', 'upgrade', '--alldeps', 'pear.php.net/dummy')
6262
provider.install
6363
end
6464

6565
it 'installs a specific version from a specific source' do
6666
resource[:ensure] = '0.2'
6767
resource[:source] = 'pear.php.net/dummy'
68-
described_class.expects(:pear).
68+
allow(described_class).to receive(:pear).
6969
with('-D', 'auto_discover=1', 'upgrade', '--alldeps', '-f', 'pear.php.net/dummy-0.2')
7070
provider.install
7171
end
7272

7373
it 'uses the specified responsefile' do
7474
resource[:responsefile] = '/fake/pearresponse'
75-
Puppet::Util::Execution.expects(:execute).
75+
allow(Puppet::Util::Execution).to receive(:execute).
7676
with(
7777
['/fake/pear', '-D', 'auto_discover=1', 'upgrade', '--alldeps', 'dummy'],
7878
stdinfile: resource[:responsefile]
@@ -82,17 +82,17 @@
8282

8383
it 'accepts install_options' do
8484
resource[:install_options] = ['--onlyreqdeps']
85-
described_class.expects(:pear).
85+
allow(described_class).to receive(:pear).
8686
with('-D', 'auto_discover=1', 'upgrade', '--onlyreqdeps', 'dummy')
8787
provider.install
8888
end
8989
end
9090

9191
describe '#query' do
9292
it 'queries information about one package' do
93-
described_class.expects(:pear).
93+
allow(described_class).to receive(:pear).
9494
with('list', '-a').
95-
returns File.read(my_fixture('list_a'))
95+
and_return File.read(my_fixture('list_a'))
9696

9797
resource[:name] = 'pear'
9898
expect(provider.query).to eq(
@@ -103,9 +103,9 @@
103103

104104
describe '#latest' do
105105
it 'fetches the latest version available' do
106-
described_class.expects(:pear).
106+
allow(described_class).to receive(:pear).
107107
with('remote-info', 'Benchmark').
108-
returns File.read(my_fixture('remote-info_benchmark'))
108+
and_return File.read(my_fixture('remote-info_benchmark'))
109109

110110
resource[:name] = 'Benchmark'
111111
expect(provider.latest).to eq '1.2.9'
@@ -114,16 +114,16 @@
114114

115115
describe '#uninstall' do
116116
it 'uninstalls a package' do
117-
described_class.expects(:pear).
117+
allow(described_class).to receive(:pear).
118118
with('uninstall', resource[:name]).
119-
returns('uninstall ok')
119+
and_return('uninstall ok')
120120
provider.uninstall
121121
end
122122

123123
it 'raises an error otherwise' do
124-
described_class.expects(:pear).
124+
allow(described_class).to receive(:pear).
125125
with('uninstall', resource[:name]).
126-
returns('unexpected output')
126+
and_return('unexpected output')
127127
expect { provider.uninstall }.to raise_error(Puppet::Error)
128128
end
129129
end
@@ -132,7 +132,7 @@
132132
it 'ignores the resource version' do
133133
resource[:ensure] = '2.0'
134134

135-
described_class.expects(:pear).
135+
allow(described_class).to receive(:pear).
136136
with('-D', 'auto_discover=1', 'upgrade', '--alldeps', 'dummy')
137137
provider.update
138138
end

spec/unit/provider/package/pecl_spec.rb

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@
1414
end
1515

1616
before do
17-
parent_class.stubs(:command).with(:pear).returns '/fake/pear'
17+
allow(parent_class).to receive(:command).with(:pear).and_return '/fake/pear'
1818
end
1919

2020
describe '.instances' do
2121
it 'returns pecl installed packages via pear' do
22-
parent_class.expects(:pear).
22+
allow(parent_class).to receive(:pear).
2323
with('list', '-a').
24-
returns File.read(fixtures('unit/provider/package/pear/list_a'))
24+
and_return File.read(fixtures('unit/provider/package/pear/list_a'))
2525

2626
expect(described_class.instances.map(&:properties)).to eq [
2727
{ ensure: '1.13.5', name: 'zip', vendor: 'pecl.php.net', provider: :pecl }
@@ -31,16 +31,16 @@
3131

3232
describe '#install' do
3333
it 'installs with pear' do
34-
parent_class.expects(:pear)
34+
allow(parent_class).to receive(:pear)
3535
provider.install
3636
end
3737
end
3838

3939
describe '#query' do
4040
it 'queries pecl package info via pear' do
41-
parent_class.expects(:pear).
41+
allow(parent_class).to receive(:pear).
4242
with('list', '-a').
43-
returns File.read(fixtures('unit/provider/package/pear/list_a'))
43+
and_return File.read(fixtures('unit/provider/package/pear/list_a'))
4444

4545
resource[:name] = 'zip'
4646
expect(provider.query).to eq(ensure: '1.13.5', name: 'zip', vendor: 'pecl.php.net', provider: :pecl)
@@ -49,9 +49,9 @@
4949

5050
describe '#latest' do
5151
it 'fetches the latest version available via pear' do
52-
parent_class.expects(:pear).
52+
allow(parent_class).to receive(:pear).
5353
with('remote-info', 'pecl.php.net/zip').
54-
returns File.read(fixtures('unit/provider/package/pear/remote-info_zip'))
54+
and_return File.read(fixtures('unit/provider/package/pear/remote-info_zip'))
5555

5656
resource[:name] = 'zip'
5757
expect(provider.latest).to eq '1.13.5'
@@ -60,8 +60,8 @@
6060

6161
describe '#uninstall' do
6262
it 'uninstalls a package via pear' do
63-
parent_class.expects(:pear).
64-
returns('uninstall ok')
63+
allow(parent_class).to receive(:pear).
64+
and_return('uninstall ok')
6565
provider.uninstall
6666
end
6767
end
@@ -70,7 +70,7 @@
7070
it 'updates to latest version via pear' do
7171
resource[:ensure] = '2.0'
7272

73-
parent_class.expects(:pear)
73+
allow(parent_class).to receive(:pear)
7474
provider.update
7575
end
7676
end

0 commit comments

Comments
 (0)