Skip to content

Commit 11b3563

Browse files
committed
Use rspec better for shorter specs
1 parent 2e4610b commit 11b3563

File tree

4 files changed

+55
-264
lines changed

4 files changed

+55
-264
lines changed

spec/defines/custom_config_spec.rb

Lines changed: 21 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,21 @@
2020
end
2121

2222
it {
23-
is_expected.to contain_exec('syntax verification for rspec').with('refreshonly' => 'true',
24-
'subscribe' => 'File[apache_rspec]',
25-
'command' => '/usr/sbin/apachectl -t',
26-
'notify' => 'Class[Apache::Service]',
27-
'before' => 'Exec[remove rspec if invalid]')
23+
is_expected.to contain_exec('syntax verification for rspec')
24+
.with('refreshonly' => 'true', 'command' => '/usr/sbin/apachectl -t')
25+
.that_subscribes_to('File[apache_rspec]')
26+
.that_notifies('Class[Apache::Service]')
27+
.that_comes_before('Exec[remove rspec if invalid]')
2828
}
2929
it {
30-
is_expected.to contain_exec('remove rspec if invalid').with('unless' => '/usr/sbin/apachectl -t',
31-
'subscribe' => 'File[apache_rspec]',
32-
'refreshonly' => 'true')
30+
is_expected.to contain_exec('remove rspec if invalid')
31+
.with('unless' => '/usr/sbin/apachectl -t', 'refreshonly' => 'true')
32+
.that_subscribes_to('File[apache_rspec]')
3333
}
3434
it {
35-
is_expected.to contain_file('apache_rspec').with('ensure' => 'present',
36-
'content' => '# Test',
37-
'require' => 'Package[httpd]')
35+
is_expected.to contain_file('apache_rspec')
36+
.with('ensure' => 'present', 'content' => '# Test')
37+
.that_requires('Package[httpd]')
3838
}
3939
end
4040
context 'set everything with source' do
@@ -55,10 +55,11 @@
5555
'unless' => '/bin/true')
5656
}
5757
it {
58-
is_expected.to contain_file('apache_rspec').with('path' => '/dne/30-rspec.conf',
59-
'ensure' => 'present',
60-
'source' => 'puppet:///modules/apache/test',
61-
'require' => 'Package[httpd]')
58+
is_expected.to contain_file('apache_rspec')
59+
.that_requires('Package[httpd]')
60+
.with('path' => '/dne/30-rspec.conf',
61+
'ensure' => 'present',
62+
'source' => 'puppet:///modules/apache/test')
6263
}
6364
end
6465
context 'verify_config => false' do
@@ -71,9 +72,7 @@
7172

7273
it { is_expected.not_to contain_exec('syntax verification for rspec') }
7374
it { is_expected.not_to contain_exec('remove rspec if invalid') }
74-
it {
75-
is_expected.to contain_file('apache_rspec').with('notify' => 'Class[Apache::Service]')
76-
}
75+
it { is_expected.to contain_file('apache_rspec').that_notifies('Class[Apache::Service]') }
7776
end
7877
context 'ensure => absent' do
7978
let :params do
@@ -84,9 +83,7 @@
8483

8584
it { is_expected.not_to contain_exec('syntax verification for rspec') }
8685
it { is_expected.not_to contain_exec('remove rspec if invalid') }
87-
it {
88-
is_expected.to contain_file('apache_rspec').with('ensure' => 'absent')
89-
}
86+
it { is_expected.to contain_file('apache_rspec').with('ensure' => 'absent') }
9087
end
9188
describe 'validation' do
9289
context 'both content and source' do
@@ -97,18 +94,11 @@
9794
}
9895
end
9996

100-
it do
101-
expect {
102-
catalogue
103-
}.to raise_error(Puppet::Error, %r{Only one of \$content and \$source can be specified\.})
104-
end
97+
it { is_expected.to compile.and_raise_error(%r{Only one of \$content and \$source can be specified\.}) }
10598
end
99+
106100
context 'neither content nor source' do
107-
it do
108-
expect {
109-
catalogue
110-
}.to raise_error(Puppet::Error, %r{One of \$content and \$source must be specified\.})
111-
end
101+
it { is_expected.to compile.and_raise_error(%r{One of \$content and \$source must be specified\.}) }
112102
end
113103
end
114104
end

spec/defines/mod_spec.rb

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77
'include apache'
88
end
99

10+
let :title do
11+
'spec_m'
12+
end
13+
1014
context 'on a RedHat osfamily' do
1115
include_examples 'RedHat 6'
1216

1317
describe 'for non-special modules' do
14-
let :title do
15-
'spec_m'
16-
end
17-
1818
it { is_expected.to contain_class('apache::params') }
1919
it 'manages the module load file' do
2020
is_expected.to contain_file('spec_m.load').with(path: '/etc/httpd/conf.d/spec_m.load',
@@ -29,9 +29,6 @@
2929
let :pre_condition do
3030
"class {'::apache': file_mode => '0640'}"
3131
end
32-
let :title do
33-
'spec_m'
34-
end
3532

3633
it 'manages the module load file' do
3734
is_expected.to contain_file('spec_m.load').with(mode: '0640')
@@ -55,10 +52,6 @@
5552
include_examples 'Debian 8'
5653

5754
describe 'for non-special modules' do
58-
let :title do
59-
'spec_m'
60-
end
61-
6255
it { is_expected.to contain_class('apache::params') }
6356
it 'manages the module load file' do
6457
is_expected.to contain_file('spec_m.load').with(path: '/etc/apache2/mods-available/spec_m.load',
@@ -81,10 +74,6 @@
8174
include_examples 'FreeBSD 9'
8275

8376
describe 'for non-special modules' do
84-
let :title do
85-
'spec_m'
86-
end
87-
8877
it { is_expected.to contain_class('apache::params') }
8978
it 'manages the module load file' do
9079
is_expected.to contain_file('spec_m.load').with(path: '/usr/local/etc/apache24/Modules/spec_m.load',
@@ -100,10 +89,6 @@
10089
include_examples 'Gentoo'
10190

10291
describe 'for non-special modules' do
103-
let :title do
104-
'spec_m'
105-
end
106-
10792
it { is_expected.to contain_class('apache::params') }
10893
it 'manages the module load file' do
10994
is_expected.to contain_file('spec_m.load').with(path: '/etc/apache2/modules.d/spec_m.load',

spec/defines/vhost_custom_spec.rb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
let :title do
77
'rspec.example.com'
88
end
9-
let :default_params do
9+
let(:params) do
1010
{
1111
content: 'foobar',
1212
}
@@ -15,13 +15,11 @@
1515
describe 'os-dependent items' do
1616
context 'on RedHat based systems' do
1717
include_examples 'RedHat 6'
18-
let(:params) { default_params }
1918

2019
it { is_expected.to compile }
2120
end
2221
context 'on Debian based systems' do
2322
include_examples 'Debian 8'
24-
let(:params) { default_params }
2523

2624
it {
2725
is_expected.to contain_file('apache_rspec.example.com').with(
@@ -40,7 +38,6 @@
4038
end
4139
context 'on FreeBSD systems' do
4240
include_examples 'FreeBSD 9'
43-
let(:params) { default_params }
4441

4542
it {
4643
is_expected.to contain_file('apache_rspec.example.com').with(
@@ -52,7 +49,6 @@
5249
end
5350
context 'on Gentoo systems' do
5451
include_examples 'Gentoo'
55-
let(:params) { default_params }
5652

5753
it {
5854
is_expected.to contain_file('apache_rspec.example.com').with(

0 commit comments

Comments
 (0)