Skip to content

Commit 48f8ffa

Browse files
committed
(maint) - Use the correct matches in rspec
Rather than checking the notify/require properties, it uses the matchers that check the dependency graph. That means it can also check transitive requires/notifies. It also uses compile and compile.and_raise_error as a shorter way to check for errors (or the absense of them).
1 parent 6b1d99c commit 48f8ffa

File tree

9 files changed

+44
-75
lines changed

9 files changed

+44
-75
lines changed

spec/classes/apache_spec.rb

Lines changed: 31 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -35,29 +35,26 @@
3535
it {
3636
is_expected.to contain_file('/etc/apache2/sites-enabled').with(
3737
'ensure' => 'directory', 'recurse' => 'true',
38-
'purge' => 'true', 'notify' => 'Class[Apache::Service]',
39-
'require' => 'Package[httpd]'
40-
)
38+
'purge' => 'true'
39+
).that_notifies('Class[Apache::Service]').that_requires('Package[httpd]')
4140
}
4241
it {
4342
is_expected.to contain_file('/etc/apache2/mods-enabled').with(
4443
'ensure' => 'directory', 'recurse' => 'true',
45-
'purge' => 'true', 'notify' => 'Class[Apache::Service]',
46-
'require' => 'Package[httpd]'
47-
)
44+
'purge' => 'true'
45+
).that_notifies('Class[Apache::Service]').that_requires('Package[httpd]')
4846
}
4947
it {
5048
is_expected.to contain_file('/etc/apache2/mods-available').with(
5149
'ensure' => 'directory', 'recurse' => 'true',
52-
'purge' => 'false', 'notify' => 'Class[Apache::Service]',
53-
'require' => 'Package[httpd]'
54-
)
50+
'purge' => 'false'
51+
).that_notifies('Class[Apache::Service]').that_requires('Package[httpd]')
5552
}
5653
it {
5754
is_expected.to contain_concat('/etc/apache2/ports.conf').with(
5855
'owner' => 'root', 'group' => 'root',
59-
'mode' => '0644', 'notify' => 'Class[Apache::Service]'
60-
)
56+
'mode' => '0644'
57+
).that_notifies('Class[Apache::Service]')
6158
}
6259
# Assert that load files are placed and symlinked for these mods, but no conf file.
6360
['auth_basic', 'authn_file', 'authz_default', 'authz_groupfile', 'authz_host', 'authz_user', 'dav', 'env'].each do |modname|
@@ -313,15 +310,14 @@
313310
it {
314311
is_expected.to contain_file('/etc/httpd/conf.d').with(
315312
'ensure' => 'directory', 'recurse' => 'true',
316-
'purge' => 'true', 'notify' => 'Class[Apache::Service]',
317-
'require' => 'Package[httpd]'
318-
)
313+
'purge' => 'true'
314+
).that_notifies('Class[Apache::Service]').that_requires('Package[httpd]')
319315
}
320316
it {
321317
is_expected.to contain_concat('/etc/httpd/conf/ports.conf').with(
322318
'owner' => 'root', 'group' => 'root',
323-
'mode' => '0644', 'notify' => 'Class[Apache::Service]'
324-
)
319+
'mode' => '0644'
320+
).that_notifies('Class[Apache::Service]')
325321
}
326322
describe 'Alternate confd/mod/vhosts directory' do
327323
let :params do
@@ -336,9 +332,8 @@
336332
it {
337333
is_expected.to contain_file("/etc/httpd/#{dir}").with(
338334
'ensure' => 'directory', 'recurse' => 'true',
339-
'purge' => 'true', 'notify' => 'Class[Apache::Service]',
340-
'require' => 'Package[httpd]'
341-
)
335+
'purge' => 'true'
336+
).that_notifies('Class[Apache::Service]').that_requires('Package[httpd]')
342337
}
343338
end
344339

@@ -509,9 +504,7 @@
509504
it {
510505
is_expected.to contain_file('/opt/rh/root/etc/httpd/conf/httpd.conf').with(
511506
'ensure' => 'file',
512-
'notify' => 'Class[Apache::Service]',
513-
'require' => ['Package[httpd]', 'Concat[/etc/httpd/conf/ports.conf]'],
514-
)
507+
).that_notifies('Class[Apache::Service]').that_requires(['Package[httpd]', 'Concat[/etc/httpd/conf/ports.conf]'])
515508
}
516509
end
517510

@@ -523,9 +516,8 @@
523516
it {
524517
is_expected.to contain_file('/etc/httpd/special_conf.d').with(
525518
'ensure' => 'directory', 'recurse' => 'true',
526-
'purge' => 'true', 'notify' => 'Class[Apache::Service]',
527-
'require' => 'Package[httpd]'
528-
)
519+
'purge' => 'true',
520+
).that_notifies('Class[Apache::Service]').that_requires('Package[httpd]')
529521
}
530522
end
531523

@@ -729,22 +721,20 @@
729721
it {
730722
is_expected.to contain_file('/usr/local/etc/apache24/Vhosts').with(
731723
'ensure' => 'directory', 'recurse' => 'true',
732-
'purge' => 'true', 'notify' => 'Class[Apache::Service]',
733-
'require' => 'Package[httpd]'
734-
)
724+
'purge' => 'true'
725+
).that_notifies('Class[Apache::Service]').that_requires('Package[httpd]')
735726
}
736727
it {
737728
is_expected.to contain_file('/usr/local/etc/apache24/Modules').with(
738729
'ensure' => 'directory', 'recurse' => 'true',
739-
'purge' => 'true', 'notify' => 'Class[Apache::Service]',
740-
'require' => 'Package[httpd]'
741-
)
730+
'purge' => 'true'
731+
).that_notifies('Class[Apache::Service]').that_requires('Package[httpd]')
742732
}
743733
it {
744734
is_expected.to contain_concat('/usr/local/etc/apache24/ports.conf').with(
745735
'owner' => 'root', 'group' => 'wheel',
746-
'mode' => '0644', 'notify' => 'Class[Apache::Service]'
747-
)
736+
'mode' => '0644',
737+
).that_notifies('Class[Apache::Service]')
748738
}
749739
# Assert that load files are placed for these mods, but no conf file.
750740
['auth_basic', 'authn_core', 'authn_file', 'authz_groupfile', 'authz_host', 'authz_user', 'dav', 'env'].each do |modname|
@@ -798,22 +788,20 @@
798788
it {
799789
is_expected.to contain_file('/etc/apache2/vhosts.d').with(
800790
'ensure' => 'directory', 'recurse' => 'true',
801-
'purge' => 'true', 'notify' => 'Class[Apache::Service]',
802-
'require' => 'Package[httpd]'
803-
)
791+
'purge' => 'true'
792+
).that_notifies('Class[Apache::Service]').that_requires('Package[httpd]')
804793
}
805794
it {
806795
is_expected.to contain_file('/etc/apache2/modules.d').with(
807796
'ensure' => 'directory', 'recurse' => 'true',
808-
'purge' => 'true', 'notify' => 'Class[Apache::Service]',
809-
'require' => 'Package[httpd]'
810-
)
797+
'purge' => 'true'
798+
).that_notifies('Class[Apache::Service]').that_requires('Package[httpd]')
811799
}
812800
it {
813801
is_expected.to contain_concat('/etc/apache2/ports.conf').with(
814802
'owner' => 'root', 'group' => 'wheel',
815-
'mode' => '0644', 'notify' => 'Class[Apache::Service]'
816-
)
803+
'mode' => '0644',
804+
).that_notifies('Class[Apache::Service]')
817805
}
818806
end
819807
context 'on all OSes' do
@@ -838,10 +826,9 @@
838826

839827
it {
840828
is_expected.to contain_package('httpd').with(
841-
'notify' => 'Class[Apache::Service]',
842829
'ensure' => 'installed',
843830
'name' => 'httpd24-httpd',
844-
)
831+
).that_notifies('Class[Apache::Service]')
845832
}
846833
end
847834
context 'with a custom file_mode parameter' do
@@ -919,10 +906,6 @@
919906
is_pe: false }
920907
end
921908

922-
it do
923-
expect {
924-
catalogue
925-
}.to raise_error(Puppet::Error, %r{Unsupported osfamily})
926-
end
909+
it { is_expected.to compile.and_raise_error(%r{Unsupported osfamily}) }
927910
end
928911
end

spec/classes/mod/authnz_ldap_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
let(:params) { { verify_server_cert: 'wrong' } }
3838

3939
it 'raises an error' do
40-
expect { is_expected.to raise_error Puppet::Error }
40+
is_expected.to compile.and_raise_error(%r{parameter 'verify_server_cert' expects a Boolean value, got String})
4141
end
4242
end
4343
end # Debian
@@ -74,7 +74,7 @@
7474
let(:params) { { verify_server_cert: 'wrong' } }
7575

7676
it 'raises an error' do
77-
expect { is_expected.to raise_error Puppet::Error }
77+
is_expected.to compile.and_raise_error(%r{parameter 'verify_server_cert' expects a Boolean value, got String})
7878
end
7979
end
8080

spec/classes/mod/data_spec.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@
2626
{ apache_version: '2.2' }
2727
end
2828

29-
it 'fails' do
30-
expect { catalogue }.to raise_error(Puppet::Error, %r{mod_data is only available in Apache 2.3 and later})
31-
end
29+
it { is_expected.to compile.and_raise_error(%r{mod_data is only available in Apache 2.3 and later}) }
3230
end
3331
end
3432
end

spec/classes/mod/peruser_spec.rb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,7 @@
2020
}
2121
end
2222

23-
it do
24-
expect {
25-
catalogue
26-
}.to raise_error(Puppet::Error, %r{Unsupported osfamily FreeBSD})
27-
end
23+
it { is_expected.to compile.and_raise_error(%r{Unsupported osfamily FreeBSD}) }
2824
end
2925
context 'on a Gentoo OS' do
3026
let :facts do

spec/classes/mod/php_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@
292292
end
293293

294294
it 'raises an error' do
295-
expect { expect(subject).to contain_apache__mod('php5') }.to raise_error Puppet::Error, %r{mpm_module => 'prefork' or mpm_module => 'itk'}
295+
is_expected.to compile.and_raise_error(%r{mpm_module => 'prefork' or mpm_module => 'itk'})
296296
end
297297
end
298298
end

spec/classes/mod/remoteip_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@
119119
{ apache_version: '2.2' }
120120
end
121121

122-
it { expect { catalogue }.to raise_error(Puppet::Error, %r{mod_remoteip is only available in Apache 2.4}) }
122+
it { is_expected.to compile.and_raise_error(%r{mod_remoteip is only available in Apache 2.4}) }
123123
end
124124
end
125125
end

spec/classes/mod/ssl_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
}
1818
end
1919

20-
it { expect { catalogue }.to raise_error(Puppet::Error, %r{Unsupported osfamily:}) }
20+
it { is_expected.to compile.and_raise_error(%r{Unsupported osfamily:}) }
2121
end
2222

2323
context 'on a RedHat' do

spec/classes/mod/status_spec.rb

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -274,9 +274,7 @@ def status_conf_spec_require(requires, extended_status, status_path)
274274
end
275275

276276
it 'expects to succeed array validation' do
277-
expect {
278-
is_expected.to contain_file('status.conf')
279-
}.not_to raise_error
277+
is_expected.to compile
280278
end
281279
end
282280

@@ -297,9 +295,7 @@ def status_conf_spec_require(requires, extended_status, status_path)
297295
end
298296

299297
it 'expects to fail array validation' do
300-
expect {
301-
is_expected.to contain_file('status.conf')
302-
}.to raise_error(Puppet::Error)
298+
is_expected.to compile.and_raise_error(/allow_from/)
303299
end
304300
end
305301

@@ -323,9 +319,7 @@ def status_conf_spec_require(requires, extended_status, status_path)
323319
end
324320

325321
it 'expects to succeed regular expression validation' do
326-
expect {
327-
is_expected.to contain_file('status.conf')
328-
}.not_to raise_error
322+
is_expected.to compile
329323
end
330324
end
331325
end
@@ -348,9 +342,7 @@ def status_conf_spec_require(requires, extended_status, status_path)
348342
end
349343

350344
it 'expects to fail regular expression validation' do
351-
expect {
352-
is_expected.to contain_file('status.conf')
353-
}.to raise_error(Puppet::Error)
345+
is_expected.to compile.and_raise_error(/extended_status/)
354346
end
355347
end
356348
end

spec/classes/mod/wsgi_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@
128128
}
129129
end
130130

131-
it { expect { catalogue }.to raise_error Puppet::Error, %r{apache::mod::wsgi - both package_name and mod_path must be specified!} }
131+
it { is_expected.to compile.and_raise_error(%r{apache::mod::wsgi - both package_name and mod_path must be specified!}) }
132132
end
133133
describe 'with mod_path but no package_name' do
134134
let :params do
@@ -137,7 +137,7 @@
137137
}
138138
end
139139

140-
it { expect { catalogue }.to raise_error Puppet::Error, %r{apache::mod::wsgi - both package_name and mod_path must be specified!} }
140+
it { is_expected.to compile.and_raise_error(%r{apache::mod::wsgi - both package_name and mod_path must be specified!}) }
141141
end
142142
end
143143
context 'on a FreeBSD OS' do

0 commit comments

Comments
 (0)