Skip to content

Commit b74cb00

Browse files
author
Travis Fields
committed
Fixes issues due to serverspec upgrade and usage of obsolete should contain method for files
1 parent be5fc47 commit b74cb00

3 files changed

Lines changed: 86 additions & 76 deletions

File tree

Gemfile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,18 @@ group :development, :unit_tests do
1818
gem 'simplecov', :require => false
1919
gem 'puppet_facts', :require => false
2020
gem 'json', :require => false
21+
gem 'pry', :require => false
2122
end
2223

24+
beaker_version = ENV['BEAKER_VERSION']
2325
beaker_rspec_version = ENV['BEAKER_RSPEC_VERSION']
2426
group :system_tests do
27+
if beaker_version
28+
gem 'beaker', *location_for(beaker_version)
29+
end
2530
if beaker_rspec_version
2631
gem 'beaker-rspec', *location_for(beaker_rspec_version)
27-
else
32+
else
2833
gem 'beaker-rspec', :require => false
2934
end
3035
gem 'serverspec', :require => false

spec/acceptance/ini_setting_spec.rb

Lines changed: 43 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
require 'spec_helper_acceptance'
2+
require 'pry'
23

34
tmpdir = default.tmpdir('tmp')
45

56
describe 'ini_setting resource' do
67
after :all do
7-
shell("rm #{tmpdir}/*.ini", :acceptable_exit_codes => [0,1,2])
8+
shell("rm #{tmpdir}/*.ini", :acceptable_exit_codes => [0, 1, 2])
89
end
910

10-
shared_examples 'has_content' do |path,pp,content|
11+
shared_examples 'has_content' do |path, pp, content|
1112
before :all do
12-
shell("rm #{path}", :acceptable_exit_codes => [0,1,2])
13+
shell("rm #{path}", :acceptable_exit_codes => [0, 1, 2])
1314
end
1415
after :all do
15-
shell("cat #{path}", :acceptable_exit_codes => [0,1,2])
16-
shell("rm #{path}", :acceptable_exit_codes => [0,1,2])
16+
shell("cat #{path}", :acceptable_exit_codes => [0, 1, 2])
17+
shell("rm #{path}", :acceptable_exit_codes => [0, 1, 2])
1718
end
1819

1920
it 'applies the manifest twice' do
@@ -23,20 +24,17 @@
2324

2425
describe file(path) do
2526
it { should be_file }
26-
#XXX Solaris 10 doesn't support multi-line grep
27-
it("should contain #{content}", :unless => fact('osfamily') == 'Solaris') {
28-
should contain(content)
29-
}
27+
its(:content) { should match content }
3028
end
3129
end
3230

33-
shared_examples 'has_error' do |path,pp,error|
31+
shared_examples 'has_error' do |path, pp, error|
3432
before :all do
35-
shell("rm #{path}", :acceptable_exit_codes => [0,1,2])
33+
shell("rm #{path}", :acceptable_exit_codes => [0, 1, 2])
3634
end
3735
after :all do
38-
shell("cat #{path}", :acceptable_exit_codes => [0,1,2])
39-
shell("rm #{path}", :acceptable_exit_codes => [0,1,2])
36+
shell("cat #{path}", :acceptable_exit_codes => [0, 1, 2])
37+
shell("rm #{path}", :acceptable_exit_codes => [0, 1, 2])
4038
end
4139

4240
it 'applies the manifest and gets a failure message' do
@@ -72,13 +70,13 @@
7270
apply_manifest(pp, :catch_changes => true)
7371
end
7472

75-
it_behaves_like 'has_content', "#{tmpdir}/ini_setting.ini", pp, "four = five\n[one]\ntwo = three"
73+
it_behaves_like 'has_content', "#{tmpdir}/ini_setting.ini", pp, /four = five\n\n\[one\]\ntwo = three/
7674
end
7775

7876
context '=> absent for key/value' do
7977
before :all do
8078
if fact('osfamily') == 'Darwin'
81-
shell("echo \"four = five\n[one]\ntwo = three\" > #{tmpdir}/ini_setting.ini")
79+
shell("echo \"four = five[one]\ntwo = three\" > #{tmpdir}/ini_setting.ini")
8280
else
8381
shell("echo -e \"four = five\n[one]\ntwo = three\" > #{tmpdir}/ini_setting.ini")
8482
end
@@ -96,14 +94,16 @@
9694

9795
it 'applies the manifest twice' do
9896
apply_manifest(pp, :catch_failures => true)
99-
apply_manifest(pp, :catch_changes => true)
97+
apply_manifest(pp, :catch_changes => true)
10098
end
10199

102100
describe file("#{tmpdir}/ini_setting.ini") do
103101
it { should be_file }
104-
it { should contain('four = five') }
105-
it { should contain('[one]') }
106-
it { should_not contain('two = three') }
102+
its(:content) {
103+
should match /four = five/
104+
should match /\[one\]/
105+
should_not match /two = three/
106+
}
107107
end
108108
end
109109

@@ -116,8 +116,8 @@
116116
end
117117
end
118118
after :all do
119-
shell("cat #{tmpdir}/ini_setting.ini", :acceptable_exit_codes => [0,1,2])
120-
shell("rm #{tmpdir}/ini_setting.ini", :acceptable_exit_codes => [0,1,2])
119+
shell("cat #{tmpdir}/ini_setting.ini", :acceptable_exit_codes => [0, 1, 2])
120+
shell("rm #{tmpdir}/ini_setting.ini", :acceptable_exit_codes => [0, 1, 2])
121121
end
122122

123123
pp = <<-EOS
@@ -132,23 +132,25 @@
132132

133133
it 'applies the manifest twice' do
134134
apply_manifest(pp, :catch_failures => true)
135-
apply_manifest(pp, :catch_changes => true)
135+
apply_manifest(pp, :catch_changes => true)
136136
end
137137

138138
describe file("#{tmpdir}/ini_setting.ini") do
139139
it { should be_file }
140-
it { should_not contain('four = five') }
141-
it { should contain('[one]') }
142-
it { should contain('two = three') }
140+
its(:content) {
141+
should_not match /four = five/
142+
should match /\[one\]/
143+
should match /two = three/
144+
}
143145
end
144146
end
145147
end
146148

147149
describe 'section, setting, value parameters' do
148150
{
149-
"section => 'test', setting => 'foo', value => 'bar'," => "[test]\nfoo = bar",
150-
"section => 'more', setting => 'baz', value => 'quux'," => "[more]\nbaz = quux",
151-
"section => '', setting => 'top', value => 'level'," => "top = level",
151+
"section => 'test', setting => 'foo', value => 'bar'," => /\[test\]\nfoo = bar/,
152+
"section => 'more', setting => 'baz', value => 'quux'," => /\[more\]\nbaz = quux/,
153+
"section => '', setting => 'top', value => 'level'," => /top = level/,
152154
}.each do |parameter_list, content|
153155
context parameter_list do
154156
pp = <<-EOS
@@ -164,12 +166,12 @@
164166
end
165167

166168
{
167-
"section => 'test'," => /setting is a required.+value is a required/,
168-
"setting => 'foo', value => 'bar'," => /section is a required/,
169-
"section => 'test', setting => 'foo'," => /value is a required/,
170-
"section => 'test', value => 'bar'," => /setting is a required/,
171-
"value => 'bar'," => /section is a required.+setting is a required/,
172-
"setting => 'foo'," => /section is a required.+value is a required/,
169+
"section => 'test'," => /setting is a required.+value is a required/,
170+
"setting => 'foo', value => 'bar'," => /section is a required/,
171+
"section => 'test', setting => 'foo'," => /value is a required/,
172+
"section => 'test', value => 'bar'," => /setting is a required/,
173+
"value => 'bar'," => /section is a required.+setting is a required/,
174+
"setting => 'foo'," => /section is a required.+value is a required/,
173175
}.each do |parameter_list, error|
174176
context parameter_list, :pending => 'no error checking yet' do
175177
pp = <<-EOS
@@ -187,9 +189,9 @@
187189

188190
describe 'path parameter' do
189191
[
190-
"#{tmpdir}/one.ini",
191-
"#{tmpdir}/two.ini",
192-
"#{tmpdir}/three.ini",
192+
"#{tmpdir}/one.ini",
193+
"#{tmpdir}/two.ini",
194+
"#{tmpdir}/three.ini",
193195
].each do |path|
194196
context "path => #{path}" do
195197
pp = <<-EOS
@@ -202,7 +204,7 @@
202204
}
203205
EOS
204206

205-
it_behaves_like 'has_content', path, pp, "[one]\ntwo = three"
207+
it_behaves_like 'has_content', path, pp, /\[one\]\ntwo = three/
206208
end
207209
end
208210

@@ -223,9 +225,9 @@
223225

224226
describe 'key_val_separator parameter' do
225227
{
226-
"" => "two = three",
227-
"key_val_separator => '='," => "two=three",
228-
"key_val_separator => ' = '," => "two = three",
228+
"" => /two = three/,
229+
"key_val_separator => '='," => /two=three/,
230+
"key_val_separator => ' = '," => /two = three/,
229231
}.each do |parameter, content|
230232
context "with \"#{parameter}\" makes \"#{content}\"" do
231233
pp = <<-EOS

spec/acceptance/ini_subsetting_spec.rb

Lines changed: 37 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,38 @@
44

55
describe 'ini_subsetting resource' do
66
after :all do
7-
shell("rm #{tmpdir}/*.ini", :acceptable_exit_codes => [0,1,2])
7+
shell("rm #{tmpdir}/*.ini", :acceptable_exit_codes => [0, 1, 2])
88
end
99

10-
shared_examples 'has_content' do |path,pp,content|
10+
shared_examples 'has_content' do |path, pp, content|
1111
before :all do
12-
shell("rm #{path}", :acceptable_exit_codes => [0,1,2])
12+
shell("rm #{path}", :acceptable_exit_codes => [0, 1, 2])
1313
end
1414
after :all do
15-
shell("cat #{path}", :acceptable_exit_codes => [0,1,2])
16-
shell("rm #{path}", :acceptable_exit_codes => [0,1,2])
15+
shell("cat #{path}", :acceptable_exit_codes => [0, 1, 2])
16+
shell("rm #{path}", :acceptable_exit_codes => [0, 1, 2])
1717
end
1818

1919
it 'applies the manifest twice' do
2020
apply_manifest(pp, :catch_failures => true)
21-
apply_manifest(pp, :catch_changes => true)
21+
apply_manifest(pp, :catch_changes => true)
2222
end
2323

2424
describe file(path) do
2525
it { should be_file }
26-
it { should contain(content) }
26+
its(:content) {
27+
should match content
28+
}
2729
end
2830
end
2931

30-
shared_examples 'has_error' do |path,pp,error|
32+
shared_examples 'has_error' do |path, pp, error|
3133
before :all do
32-
shell("rm #{path}", :acceptable_exit_codes => [0,1,2])
34+
shell("rm #{path}", :acceptable_exit_codes => [0, 1, 2])
3335
end
3436
after :all do
35-
shell("cat #{path}", :acceptable_exit_codes => [0,1,2])
36-
shell("rm #{path}", :acceptable_exit_codes => [0,1,2])
37+
shell("cat #{path}", :acceptable_exit_codes => [0, 1, 2])
38+
shell("rm #{path}", :acceptable_exit_codes => [0, 1, 2])
3739
end
3840

3941
it 'applies the manifest and gets a failure message' do
@@ -68,14 +70,13 @@
6870

6971
it 'applies the manifest twice' do
7072
apply_manifest(pp, :catch_failures => true)
71-
apply_manifest(pp, :catch_changes => true)
73+
apply_manifest(pp, :catch_changes => true)
7274
end
7375

7476
describe file("#{tmpdir}/ini_subsetting.ini") do
7577
it { should be_file }
76-
#XXX Solaris 10 doesn't support multi-line grep
77-
it("should contain [one]\nkey = alphabet betatrons", :unless => fact('osfamily') == 'Solaris') {
78-
should contain("[one]\nkey = alphabet betatrons")
78+
its(:content) {
79+
should match /\[one\]\nkey = alphabet betatrons/
7980
}
8081
end
8182
end
@@ -101,27 +102,27 @@
101102

102103
it 'applies the manifest twice' do
103104
apply_manifest(pp, :catch_failures => true)
104-
apply_manifest(pp, :catch_changes => true)
105+
apply_manifest(pp, :catch_changes => true)
105106
end
106107

107108
describe file("#{tmpdir}/ini_subsetting.ini") do
108109
it { should be_file }
109-
it { should contain('[one]') }
110-
it { should contain('key = betatrons') }
111-
it { should_not contain('alphabet') }
110+
its(:content) {
111+
should match /\[one\]/
112+
should match /key = betatrons/
113+
should_not match /alphabet/
114+
}
112115
end
113116
end
114117
end
115118

116119
describe 'subsetting_separator' do
117120
{
118-
"" => "two = twinethree foobar",
119-
#"subsetting_separator => ''," => "two = twinethreefoobar", # breaks regex
120-
"subsetting_separator => ','," => "two = twinethree,foobar",
121-
"subsetting_separator => ' '," => "two = twinethree foobar",
122-
"subsetting_separator => ' == '," => "two = twinethree == foobar",
123-
"subsetting_separator => '='," => "two = twinethree=foobar",
124-
#"subsetting_separator => '---'," => "two = twinethree---foobar", # breaks regex
121+
"" => /two = twinethree foobar/,
122+
"subsetting_separator => ','," => /two = twinethree,foobar/,
123+
"subsetting_separator => ' '," => /two = twinethree foobar/,
124+
"subsetting_separator => ' == '," => /two = twinethree == foobar/,
125+
"subsetting_separator => '='," => /two = twinethree=foobar/,
125126
}.each do |parameter, content|
126127
context "with \"#{parameter}\" makes \"#{content}\"" do
127128
pp = <<-EOS
@@ -152,10 +153,10 @@
152153

153154
describe 'quote_char' do
154155
{
155-
['-Xmx'] => 'args=""',
156-
['-Xmx', '256m'] => 'args=-Xmx256m',
157-
['-Xmx', '512m'] => 'args="-Xmx512m"',
158-
['-Xms', '256m'] => 'args="-Xmx256m -Xms256m"',
156+
['-Xmx'] => /args=""/,
157+
['-Xmx', '256m'] => /args=-Xmx256m/,
158+
['-Xmx', '512m'] => /args="-Xmx512m"/,
159+
['-Xms', '256m'] => /args="-Xmx256m -Xms256m"/,
159160
}.each do |parameter, content|
160161
context %Q{with '#{parameter.first}' #{parameter.length > 1 ? '=> \'' << parameter[1] << '\'' : 'absent'} makes '#{content}'} do
161162
path = File.join(tmpdir, 'ini_subsetting.ini')
@@ -164,8 +165,8 @@
164165
shell(%Q{echo '[java]\nargs=-Xmx256m' > #{path}})
165166
end
166167
after :all do
167-
shell("cat #{path}", :acceptable_exit_codes => [0,1,2])
168-
shell("rm #{path}", :acceptable_exit_codes => [0,1,2])
168+
shell("cat #{path}", :acceptable_exit_codes => [0, 1, 2])
169+
shell("rm #{path}", :acceptable_exit_codes => [0, 1, 2])
169170
end
170171

171172
pp = <<-EOS
@@ -182,12 +183,14 @@
182183

183184
it 'applies the manifest twice' do
184185
apply_manifest(pp, :catch_failures => true)
185-
apply_manifest(pp, :catch_changes => true)
186+
apply_manifest(pp, :catch_changes => true)
186187
end
187188

188189
describe file("#{tmpdir}/ini_subsetting.ini") do
189190
it { should be_file }
190-
it { should contain(content) }
191+
its(:content) {
192+
should match content
193+
}
191194
end
192195
end
193196
end

0 commit comments

Comments
 (0)