serverspec 0.6.12 → 0.6.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -60,16 +60,16 @@ module Serverspec
60
60
  check_zero(meth, *args)
61
61
  end
62
62
 
63
- def check_running(process)
64
- ret = run_command(commands.check_running(process))
63
+ def check_running(process, level)
64
+ ret = run_command(commands.check_running(process, level))
65
65
  if ret[:exit_status] == 1 || ret[:stdout] =~ /stopped/
66
66
  ret = run_command(commands.check_process(process))
67
67
  end
68
68
  ret[:exit_status] == 0
69
69
  end
70
70
 
71
- def check_running_under_supervisor(process)
72
- ret = run_command(commands.check_running_under_supervisor(process))
71
+ def check_running_under_supervisor(process, level)
72
+ ret = run_command(commands.check_running_under_supervisor(process, level))
73
73
  ret[:exit_status] == 0 && ret[:stdout] =~ /RUNNING/
74
74
  end
75
75
 
@@ -9,7 +9,7 @@ module Serverspec
9
9
  Shellwords.shellescape(target.to_s())
10
10
  end
11
11
 
12
- def check_enabled(service)
12
+ def check_enabled(service, level=3)
13
13
  raise NotImplementedError.new
14
14
  end
15
15
 
@@ -77,11 +77,11 @@ module Serverspec
77
77
  "netstat -tunl | grep -- #{escape(regexp)}"
78
78
  end
79
79
 
80
- def check_running(service)
80
+ def check_running(service, level=3)
81
81
  "service #{escape(service)} status"
82
82
  end
83
83
 
84
- def check_running_under_supervisor(service)
84
+ def check_running_under_supervisor(service, level=3)
85
85
  "supervisorctl status #{escape(service)}"
86
86
  end
87
87
 
@@ -1,9 +1,9 @@
1
1
  module Serverspec
2
2
  module Commands
3
3
  class Debian < Linux
4
- def check_enabled(service)
4
+ def check_enabled(service, level=3)
5
5
  # Until everything uses Upstart, this needs an OR.
6
- "ls /etc/rc3.d/ | grep -- #{escape(service)} || grep 'start on' /etc/init/#{escape(service)}.conf"
6
+ "ls /etc/rc#{level}.d/ | grep -- #{escape(service)} || grep 'start on' /etc/init/#{escape(service)}.conf"
7
7
  end
8
8
 
9
9
  def check_installed(package, version=nil)
@@ -11,7 +11,7 @@ module Serverspec
11
11
  "dpkg -s #{escaped_package} && ! dpkg -s #{escaped_package} | grep -E '^Status: .+ not-installed$'"
12
12
  end
13
13
 
14
- def check_running(service)
14
+ def check_running(service, level=3)
15
15
  # This is compatible with Debian >Jaunty and Ubuntu derivatives
16
16
  "service #{escape(service)} status | grep 'running'"
17
17
  end
@@ -10,7 +10,7 @@ module Serverspec
10
10
  "eix #{escape(package)} --installed"
11
11
  end
12
12
 
13
- def check_running(service)
13
+ def check_running(service, level=3)
14
14
  "/etc/init.d/#{escape(service)} status"
15
15
  end
16
16
  end
@@ -6,8 +6,8 @@ module Serverspec
6
6
  "runuser -c \"test -#{access} #{file}\" #{user}"
7
7
  end
8
8
 
9
- def check_enabled(service)
10
- "chkconfig --list #{escape(service)} | grep 3:on"
9
+ def check_enabled(service, level=3)
10
+ "chkconfig --list #{escape(service)} | grep #{level}:on"
11
11
  end
12
12
 
13
13
  def check_yumrepo(repository)
@@ -1,7 +1,7 @@
1
1
  module Serverspec
2
2
  module Commands
3
3
  class Solaris < Base
4
- def check_enabled(service)
4
+ def check_enabled(service, level=3)
5
5
  "svcs -l #{escape(service)} 2> /dev/null | grep 'enabled true'"
6
6
  end
7
7
 
@@ -18,7 +18,7 @@ module Serverspec
18
18
  "netstat -an 2> /dev/null | egrep 'LISTEN|Idle' | grep -- #{escape(regexp)}"
19
19
  end
20
20
 
21
- def check_running(service)
21
+ def check_running(service, level=3)
22
22
  "svcs -l #{escape(service)} status 2> /dev/null |grep 'state online'"
23
23
  end
24
24
 
@@ -1,7 +1,7 @@
1
1
  module Serverspec
2
2
  module Configuration
3
3
  class << self
4
- VALID_OPTIONS_KEYS = [:path, :pre_command].freeze
4
+ VALID_OPTIONS_KEYS = [:path, :pre_command, :stdout, :stderr].freeze
5
5
  attr_accessor(*VALID_OPTIONS_KEYS)
6
6
 
7
7
  def defaults
@@ -1,9 +1,13 @@
1
1
  RSpec::Matchers.define :be_running do
2
2
  match do |process|
3
- process.running?(@under)
3
+ process.running?(@under, @level)
4
4
  end
5
5
 
6
6
  chain :under do |under|
7
7
  @under = under
8
8
  end
9
+
10
+ chain :with_level do |level|
11
+ @level = level
12
+ end
9
13
  end
@@ -5,7 +5,7 @@ module Serverspec
5
5
  backend.check_enabled(@name)
6
6
  end
7
7
 
8
- def running?(under)
8
+ def running?(under, level=3)
9
9
  if under
10
10
  check_method = "check_running_under_#{under}".to_sym
11
11
 
@@ -13,9 +13,9 @@ module Serverspec
13
13
  raise ArgumentError.new("`be_running` matcher doesn't support #{@under}")
14
14
  end
15
15
 
16
- backend.send(check_method, @name)
16
+ backend.send(check_method, @name, level)
17
17
  else
18
- backend.check_running(@name)
18
+ backend.check_running(@name, level)
19
19
  end
20
20
  end
21
21
 
@@ -1,3 +1,3 @@
1
1
  module Serverspec
2
- VERSION = "0.6.12"
2
+ VERSION = "0.6.13"
3
3
  end
@@ -70,6 +70,11 @@ describe 'check_enabled' do
70
70
  it { should eq "ls /etc/rc3.d/ | grep -- httpd || grep 'start on' /etc/init/httpd.conf" }
71
71
  end
72
72
 
73
+ describe 'check_enabled with run level 5' do
74
+ subject { commands.check_enabled('httpd', 5) }
75
+ it { should eq "ls /etc/rc5.d/ | grep -- httpd || grep 'start on' /etc/init/httpd.conf" }
76
+ end
77
+
73
78
  describe 'check_installed' do
74
79
  subject { commands.check_installed('httpd') }
75
80
  it { should eq "dpkg -s httpd && ! dpkg -s httpd | grep -E '^Status: .+ not-installed$'" }
@@ -6,21 +6,22 @@ PROJECT_ROOT = (Pathname.new(File.dirname(__FILE__)) + '..').expand_path
6
6
 
7
7
  Dir[PROJECT_ROOT.join("spec/support/**/*.rb")].each { |file| require(file) }
8
8
 
9
+
9
10
  module Serverspec
10
11
  module Backend
11
12
  class Exec
12
13
  def run_command(cmd)
13
14
  if cmd =~ /invalid/
14
15
  {
15
- :stdout => ::RSpec.configuration.stdout,
16
- :stderr => ::RSpec.configuration.stderr,
16
+ :stdout => ::Serverspec.configuration.stdout,
17
+ :stderr => ::Serverspec.configuration.stderr,
17
18
  :exit_status => 1,
18
19
  :exit_signal => nil
19
20
  }
20
21
  else
21
22
  {
22
- :stdout => ::RSpec.configuration.stdout,
23
- :stderr => ::RSpec.configuration.stderr,
23
+ :stdout => ::Serverspec.configuration.stdout,
24
+ :stderr => ::Serverspec.configuration.stderr,
24
25
  :exit_status => 0,
25
26
  :exit_signal => nil
26
27
  }
@@ -38,8 +39,3 @@ module Serverspec
38
39
  end
39
40
  end
40
41
  end
41
-
42
- RSpec.configure do |c|
43
- c.add_setting :stdout, :default => ''
44
- c.add_setting :stderr, :default => ''
45
- end
@@ -1,25 +1,18 @@
1
1
  shared_examples_for 'support command return_stdout matcher' do |name, content|
2
2
  describe 'return_stdout' do
3
3
  describe command(name) do
4
- before :all do
5
- RSpec.configure do |c|
6
- c.stdout = "#{content}\r\n"
7
- end
8
- end
4
+ let(:stdout) { "#{content}\r\n" }
9
5
  it { should return_stdout(content) }
10
6
  end
11
7
 
12
8
  describe command(name) do
13
- before :all do
14
- RSpec.configure do |c|
15
- c.stdout = "foo#{content}bar\r\n"
16
- end
17
- end
9
+ let(:stdout) { "foo#{content}bar\r\n" }
18
10
  it { should_not return_stdout(content) }
19
11
  end
20
12
 
21
13
 
22
14
  describe command('invalid-command') do
15
+ let(:stdout) { "foo bar\r\n" }
23
16
  it { should_not return_stdout(content) }
24
17
  end
25
18
  end
@@ -28,20 +21,12 @@ end
28
21
  shared_examples_for 'support command return_stdout matcher with regexp' do |name, content|
29
22
  describe 'return_stdout' do
30
23
  describe command(name) do
31
- before :all do
32
- RSpec.configure do |c|
33
- c.stdout = "foo#{content}bar\r\n"
34
- end
35
- end
24
+ let(:stdout) { "foo#{content}bar\r\n" }
36
25
  it { should return_stdout(content) }
37
26
  end
38
27
 
39
28
  describe command(name) do
40
- before :all do
41
- RSpec.configure do |c|
42
- c.stdout = "foobar\r\n"
43
- end
44
- end
29
+ let(:stdout) { "foobar\r\n" }
45
30
  it { should_not return_stdout(content) }
46
31
  end
47
32
 
@@ -54,20 +39,12 @@ end
54
39
  shared_examples_for 'support command return_stderr matcher' do |name, content|
55
40
  describe 'return_stderr' do
56
41
  describe command(name) do
57
- before :all do
58
- RSpec.configure do |c|
59
- c.stdout = "#{content}\r\n"
60
- end
61
- end
42
+ let(:stdout) { "#{content}\r\n" }
62
43
  it { should return_stderr(content) }
63
44
  end
64
45
 
65
46
  describe command(name) do
66
- before :all do
67
- RSpec.configure do |c|
68
- c.stdout = "No such file or directory\r\n"
69
- end
70
- end
47
+ let(:stdout) { "No such file or directory\r\n" }
71
48
  it { should_not return_stderr(content) }
72
49
  end
73
50
  end
@@ -76,20 +53,12 @@ end
76
53
  shared_examples_for 'support command return_stderr matcher with regexp' do |name, content|
77
54
  describe 'return_stderr' do
78
55
  describe command(name) do
79
- before :all do
80
- RSpec.configure do |c|
81
- c.stdout = "cat: /foo: No such file or directory\r\n"
82
- end
83
- end
56
+ let(:stdout) { "cat: /foo: No such file or directory\r\n" }
84
57
  it { should return_stdout(content) }
85
58
  end
86
59
 
87
60
  describe command(name) do
88
- before :all do
89
- RSpec.configure do |c|
90
- c.stdout = "foobar\r\n"
91
- end
92
- end
61
+ let(:stdout) { "foobar\r\n" }
93
62
  it { should_not return_stdout(content) }
94
63
  end
95
64
  end
@@ -104,7 +104,15 @@ shared_examples_for 'support command check_file_md5checksum' do |file, md5sum|
104
104
  end
105
105
 
106
106
  shared_examples_for 'support command check_running_under_supervisor' do |service|
107
- subject { commands.check_running_under_supervisor(service) }
107
+ subject { commands.check_running_under_supervisor(service, 3) }
108
+ it { should eq "supervisorctl status #{service}" }
109
+ end
110
+
111
+ shared_examples_for 'support command check_running_under_supervisor_with_level' do |service|
112
+ subject { commands.check_running_under_supervisor(service, 3) }
113
+ it { should eq "supervisorctl status #{service}" }
114
+
115
+ subject { commands.check_running_under_supervisor(service, 3) }
108
116
  it { should eq "supervisorctl status #{service}" }
109
117
  end
110
118
 
@@ -1,10 +1,6 @@
1
1
  shared_examples_for 'support default gateway matcher' do
2
2
  describe 'default_gateway' do
3
- before :all do
4
- RSpec.configure do |c|
5
- c.stdout = "default via 192.168.1.1 dev eth1 \r\n"
6
- end
7
- end
3
+ let(:stdout) { "default via 192.168.1.1 dev eth1 \r\n" }
8
4
 
9
5
  describe default_gateway do
10
6
  its(:ipaddress) { should eq '192.168.1.1' }
@@ -169,20 +169,14 @@ end
169
169
  shared_examples_for 'support file be_readable matcher' do |name|
170
170
  describe 'be_readable' do
171
171
  describe file(name) do
172
- before :all do
173
- RSpec.configure do |c|
174
- c.stdout = "755\r\n"
175
- end
176
- end
172
+ let(:stdout) { "755\r\n" }
173
+
177
174
  it { should be_readable }
178
175
  end
179
176
 
180
177
  describe file(name) do
181
- before :all do
182
- RSpec.configure do |c|
183
- c.stdout = "333\r\n"
184
- end
185
- end
178
+ let(:stdout) { "333\r\n" }
179
+
186
180
  it { should_not be_readable }
187
181
  end
188
182
  end
@@ -191,20 +185,12 @@ end
191
185
  shared_examples_for 'support file be_readable by owner matcher' do |name|
192
186
  describe 'be_readable by owner' do
193
187
  describe file(name) do
194
- before :all do
195
- RSpec.configure do |c|
196
- c.stdout = "400\r\n"
197
- end
198
- end
188
+ let(:stdout) { "400\r\n" }
199
189
  it { should be_readable.by('owner') }
200
190
  end
201
191
 
202
192
  describe file(name) do
203
- before :all do
204
- RSpec.configure do |c|
205
- c.stdout = "044\r\n"
206
- end
207
- end
193
+ let(:stdout) { "044\r\n" }
208
194
  it { should_not be_readable.by('owner') }
209
195
  end
210
196
  end
@@ -213,20 +199,12 @@ end
213
199
  shared_examples_for 'support file be_readable by group matcher' do |name|
214
200
  describe 'be_readable by group' do
215
201
  describe file(name) do
216
- before :all do
217
- RSpec.configure do |c|
218
- c.stdout = "040\r\n"
219
- end
220
- end
202
+ let(:stdout) { "040\r\n" }
221
203
  it { should be_readable.by('group') }
222
204
  end
223
205
 
224
206
  describe file(name) do
225
- before :all do
226
- RSpec.configure do |c|
227
- c.stdout = "404\r\n"
228
- end
229
- end
207
+ let(:stdout) { "404\r\n" }
230
208
  it { should_not be_readable.by('group') }
231
209
  end
232
210
  end
@@ -235,20 +213,12 @@ end
235
213
  shared_examples_for 'support file be_readable by others matcher' do |name|
236
214
  describe 'be_readable by others' do
237
215
  describe file(name) do
238
- before :all do
239
- RSpec.configure do |c|
240
- c.stdout = "044\r\n"
241
- end
242
- end
216
+ let(:stdout) { "044\r\n" }
243
217
  it { should be_readable.by('others') }
244
218
  end
245
219
 
246
220
  describe file(name) do
247
- before :all do
248
- RSpec.configure do |c|
249
- c.stdout = "443\r\n"
250
- end
251
- end
221
+ let(:stdout) { "443\r\n" }
252
222
  it { should_not be_readable.by('others') }
253
223
  end
254
224
  end
@@ -268,20 +238,12 @@ end
268
238
  shared_examples_for 'support file be_writable matcher' do |name|
269
239
  describe 'be_writable' do
270
240
  describe file(name) do
271
- before :all do
272
- RSpec.configure do |c|
273
- c.stdout = "755\r\n"
274
- end
275
- end
241
+ let(:stdout) { "755\r\n" }
276
242
  it { should be_writable }
277
243
  end
278
244
 
279
245
  describe file(name) do
280
- before :all do
281
- RSpec.configure do |c|
282
- c.stdout = "555\r\n"
283
- end
284
- end
246
+ let(:stdout) { "555\r\n" }
285
247
  it { should_not be_writable }
286
248
  end
287
249
  end
@@ -290,20 +252,12 @@ end
290
252
  shared_examples_for 'support file be_writable by owner matcher' do |name|
291
253
  describe 'be_writable_by_owner' do
292
254
  describe file(name) do
293
- before :all do
294
- RSpec.configure do |c|
295
- c.stdout = "200\r\n"
296
- end
297
- end
255
+ let(:stdout) { "200\r\n" }
298
256
  it { should be_writable.by('owner') }
299
257
  end
300
258
 
301
259
  describe file(name) do
302
- before :all do
303
- RSpec.configure do |c|
304
- c.stdout = "555\r\n"
305
- end
306
- end
260
+ let(:stdout) { "555\r\n" }
307
261
  it { should_not be_writable.by('owner') }
308
262
  end
309
263
  end
@@ -312,20 +266,12 @@ end
312
266
  shared_examples_for 'support file be_writable by group matcher' do |name|
313
267
  describe 'be_writable_by_group' do
314
268
  describe file(name) do
315
- before :all do
316
- RSpec.configure do |c|
317
- c.stdout = "030\r\n"
318
- end
319
- end
269
+ let(:stdout) { "030\r\n" }
320
270
  it { should be_writable.by('group') }
321
271
  end
322
272
 
323
273
  describe file(name) do
324
- before :all do
325
- RSpec.configure do |c|
326
- c.stdout = "555\r\n"
327
- end
328
- end
274
+ let(:stdout) { "555\r\n" }
329
275
  it { should_not be_writable.by('group') }
330
276
  end
331
277
  end
@@ -334,20 +280,12 @@ end
334
280
  shared_examples_for 'support file be_writable by others matcher' do |name|
335
281
  describe 'be_writable_by_others' do
336
282
  describe file(name) do
337
- before :all do
338
- RSpec.configure do |c|
339
- c.stdout = "666\r\n"
340
- end
341
- end
283
+ let(:stdout) { "666\r\n" }
342
284
  it { should be_writable.by('others') }
343
285
  end
344
286
 
345
287
  describe file(name) do
346
- before :all do
347
- RSpec.configure do |c|
348
- c.stdout = "555\r\n"
349
- end
350
- end
288
+ let(:stdout) { "555\r\n" }
351
289
  it { should_not be_writable.by('others') }
352
290
  end
353
291
  end
@@ -367,20 +305,12 @@ end
367
305
  shared_examples_for 'support file be_executable matcher' do |name|
368
306
  describe 'be_executable' do
369
307
  describe file(name) do
370
- before :all do
371
- RSpec.configure do |c|
372
- c.stdout = "755\r\n"
373
- end
374
- end
308
+ let(:stdout) { "755\r\n" }
375
309
  it { should be_executable }
376
310
  end
377
311
 
378
312
  describe file(name) do
379
- before :all do
380
- RSpec.configure do |c|
381
- c.stdout = "666\r\n"
382
- end
383
- end
313
+ let(:stdout) { "666\r\n" }
384
314
  it { should_not be_executable }
385
315
  end
386
316
  end
@@ -389,20 +319,12 @@ end
389
319
  shared_examples_for 'support file be_executable by owner matcher' do |name|
390
320
  describe 'be_executable by owner' do
391
321
  describe file(name) do
392
- before :all do
393
- RSpec.configure do |c|
394
- c.stdout = "100\r\n"
395
- end
396
- end
322
+ let(:stdout) { "100\r\n" }
397
323
  it { should be_executable.by('owner') }
398
324
  end
399
325
 
400
326
  describe file(name) do
401
- before :all do
402
- RSpec.configure do |c|
403
- c.stdout = "666\r\n"
404
- end
405
- end
327
+ let(:stdout) { "666\r\n" }
406
328
  it { should_not be_executable.by('owner') }
407
329
  end
408
330
  end
@@ -411,20 +333,12 @@ end
411
333
  shared_examples_for 'support file be_executable by group matcher' do |name|
412
334
  describe 'be_executable by group' do
413
335
  describe file(name) do
414
- before :all do
415
- RSpec.configure do |c|
416
- c.stdout = "070\r\n"
417
- end
418
- end
336
+ let(:stdout) { "070\r\n" }
419
337
  it { should be_executable.by('group') }
420
338
  end
421
339
 
422
340
  describe file(name) do
423
- before :all do
424
- RSpec.configure do |c|
425
- c.stdout = "666\r\n"
426
- end
427
- end
341
+ let(:stdout) { "666\r\n" }
428
342
  it { should_not be_executable.by('group') }
429
343
  end
430
344
  end
@@ -433,20 +347,12 @@ end
433
347
  shared_examples_for 'support file be_executable by others matcher' do |name|
434
348
  describe 'be_executable by others' do
435
349
  describe file(name) do
436
- before :all do
437
- RSpec.configure do |c|
438
- c.stdout = "001\r\n"
439
- end
440
- end
350
+ let(:stdout) { "001\r\n" }
441
351
  it { should be_executable.by('others') }
442
352
  end
443
353
 
444
354
  describe file(name) do
445
- before :all do
446
- RSpec.configure do |c|
447
- c.stdout = "666\r\n"
448
- end
449
- end
355
+ let(:stdout) { "666\r\n" }
450
356
  it { should_not be_executable.by('others') }
451
357
  end
452
358
  end
@@ -477,11 +383,7 @@ end
477
383
 
478
384
  shared_examples_for 'support file be_mounted with matcher' do |name|
479
385
  describe 'be_mounted.with' do
480
- before :all do
481
- RSpec.configure do |c|
482
- c.stdout = "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n"
483
- end
484
- end
386
+ let(:stdout) { "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n" }
485
387
 
486
388
  describe file(name) do
487
389
  it { should be_mounted.with( :type => 'ext4' ) }
@@ -528,11 +430,7 @@ end
528
430
 
529
431
  shared_examples_for 'support file be_mounted only with matcher' do |name|
530
432
  describe 'be_mounted.with' do
531
- before :all do
532
- RSpec.configure do |c|
533
- c.stdout = "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n"
534
- end
535
- end
433
+ let(:stdout) { "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n" }
536
434
 
537
435
  describe file(name) do
538
436
  it do
@@ -1,11 +1,6 @@
1
1
  shared_examples_for 'support interface matcher' do |name|
2
2
  describe 'interface' do
3
- before :all do
4
- RSpec.configure do |c|
5
- c.stdout = "1000"
6
- end
7
- end
8
-
3
+ let(:stdout) { '1000' }
9
4
  describe interface(name) do
10
5
  its(:speed) { should eq 1000 }
11
6
  end
@@ -1,10 +1,6 @@
1
1
  shared_examples_for 'support explicit linux kernel parameter checking with integer' do |param, value|
2
2
  describe 'linux kernel parameter' do
3
- before :all do
4
- RSpec.configure do |c|
5
- c.stdout = "#{value}\n"
6
- end
7
- end
3
+ let(:stdout) { "#{value}\n" }
8
4
 
9
5
  context linux_kernel_parameter(param) do
10
6
  its(:value) { should eq value }
@@ -18,11 +14,7 @@ end
18
14
 
19
15
  shared_examples_for 'support explicit linux kernel parameter checking with string' do |param, value|
20
16
  describe 'linux kernel parameter' do
21
- before :all do
22
- RSpec.configure do |c|
23
- c.stdout = "#{value}\n"
24
- end
25
- end
17
+ let(:stdout) { "#{value}\n" }
26
18
 
27
19
  context linux_kernel_parameter(param) do
28
20
  its(:value) { should eq value }
@@ -36,11 +28,7 @@ end
36
28
 
37
29
  shared_examples_for 'support explicit linux kernel parameter checking with regexp' do |param, regexp|
38
30
  describe 'linux kernel parameter' do
39
- before :all do
40
- RSpec.configure do |c|
41
- c.stdout = "4096 16384 4194304\n"
42
- end
43
- end
31
+ let(:stdout) { "4096 16384 4194304\n" }
44
32
 
45
33
  context linux_kernel_parameter(param) do
46
34
  its(:value) { should match regexp }
@@ -1,10 +1,6 @@
1
1
  shared_examples_for 'support routing table have_entry matcher' do
2
2
  describe 'routing table have_entry pattern #1' do
3
- before :all do
4
- RSpec.configure do |c|
5
- c.stdout = "192.168.100.0/24 dev eth1 proto kernel scope link src 192.168.100.10 \r\ndefault via 192.168.100.1 dev eth0 \r\n"
6
- end
7
- end
3
+ let(:stdout) { "192.168.100.0/24 dev eth1 proto kernel scope link src 192.168.100.10 \r\ndefault via 192.168.100.1 dev eth0 \r\n" }
8
4
 
9
5
  context routing_table do
10
6
  it { should have_entry( :destination => '192.168.100.0/24' ) }
@@ -43,11 +39,7 @@ shared_examples_for 'support routing table have_entry matcher' do
43
39
  end
44
40
 
45
41
  describe 'routing table have_entry pattern #2' do
46
- before :all do
47
- RSpec.configure do |c|
48
- c.stdout = "192.168.200.0/24 via 192.168.200.1 dev eth0 \r\ndefault via 192.168.100.1 dev eth0 \r\n"
49
- end
50
- end
42
+ let(:stdout) { "192.168.200.0/24 via 192.168.200.1 dev eth0 \r\ndefault via 192.168.100.1 dev eth0 \r\n" }
51
43
 
52
44
  context routing_table do
53
45
  it { should have_entry( :destination => '192.168.200.0/24' ) }
@@ -86,11 +78,7 @@ shared_examples_for 'support routing table have_entry matcher' do
86
78
  end
87
79
 
88
80
  describe 'routing table have_entry #3' do
89
- before :all do
90
- RSpec.configure do |c|
91
- c.stdout = "default via 10.0.2.2 dev eth0 \r\n"
92
- end
93
- end
81
+ let(:stdout) { "default via 10.0.2.2 dev eth0 \r\n" }
94
82
 
95
83
  context routing_table do
96
84
  it { should have_entry( :destination => 'default' ) }
@@ -21,11 +21,7 @@ shared_examples_for 'support service running matcher' do |valid_service|
21
21
  end
22
22
 
23
23
  describe service(valid_service) do
24
- before :all do
25
- RSpec.configure do |c|
26
- c.stdout = "#{valid_service} is stopped\r\n"
27
- end
28
- end
24
+ let(:stdout) { "#{valid_service} is stopped\r\n" }
29
25
  it { should be_running }
30
26
  end
31
27
  end
@@ -33,6 +29,36 @@ end
33
29
 
34
30
  shared_examples_for 'support service running under supervisor matcher' do |valid_service|
35
31
  describe 'be_running.under("supervisor")' do
32
+ describe service(valid_service) do
33
+ let(:stdout) { "#{valid_service} RUNNING\r\n" }
34
+ it { should be_running.under('supervisor') }
35
+ end
36
+
37
+ describe service(valid_service) do
38
+ let(:stdout) { "#{valid_service} STOPPED\r\n" }
39
+ it { should_not be_running.under('supervisor') }
40
+ end
41
+
42
+ describe service('invalid-daemon') do
43
+ it { should_not be_running.under('supervisor') }
44
+ end
45
+ end
46
+ end
47
+
48
+ shared_examples_for 'support service running under unimplemented matcher' do |valid_service|
49
+ describe 'be_running.under("not implemented")' do
50
+ describe service(valid_service) do
51
+ it {
52
+ expect {
53
+ should be_running.under('not implemented')
54
+ }.to raise_error(ArgumentError, %r/\A`be_running` matcher doesn\'t support/)
55
+ }
56
+ end
57
+ end
58
+ end
59
+
60
+ shared_examples_for 'support service running with runlevel' do |valid_service|
61
+ describe 'be_running.with_level(3)' do
36
62
  describe service(valid_service) do
37
63
  before :all do
38
64
  RSpec.configure do |c|
@@ -40,7 +66,8 @@ shared_examples_for 'support service running under supervisor matcher' do |valid
40
66
  end
41
67
  end
42
68
 
43
- it { should be_running.under('supervisor') }
69
+ it { should be_running.with_level(3) }
70
+ it { should_not be_running.with_level(5) }
44
71
  end
45
72
 
46
73
  describe service(valid_service) do
@@ -50,23 +77,27 @@ shared_examples_for 'support service running under supervisor matcher' do |valid
50
77
  end
51
78
  end
52
79
 
53
- it { should_not be_running.under('supervisor') }
80
+ it { should_not be_running.with_level(3) }
54
81
  end
55
82
 
56
83
  describe service('invalid-daemon') do
57
- it { should_not be_running.under('supervisor') }
84
+ it { should_not be_running.with_level(3) }
58
85
  end
59
86
  end
60
87
  end
61
88
 
62
- shared_examples_for 'support service running under unimplemented matcher' do |valid_service|
63
- describe 'be_running.under("not implemented")' do
89
+ shared_examples_for 'support service running under supervisor matcher with runlevel' do |valid_service|
90
+ describe 'be_running.under("supervisor").with_level(3)' do
64
91
  describe service(valid_service) do
65
- it {
66
- expect {
67
- should be_running.under('not implemented')
68
- }.to raise_error(ArgumentError, %r/\A`be_running` matcher doesn\'t support/)
69
- }
92
+ before :all do
93
+ RSpec.configure do |c|
94
+ c.stdout = "#{valid_service} RUNNING\r\n"
95
+ end
96
+ end
97
+
98
+ it { should be_running.under('supervisor').with_level(3) }
99
+ it { should_not be_running.under('supervisor').with_level(5) }
70
100
  end
101
+
71
102
  end
72
103
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: serverspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.12
4
+ version: 0.6.13
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-28 00:00:00.000000000 Z
12
+ date: 2013-06-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: net-ssh
@@ -329,7 +329,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
329
329
  version: '0'
330
330
  requirements: []
331
331
  rubyforge_project:
332
- rubygems_version: 1.8.23
332
+ rubygems_version: 1.8.25
333
333
  signing_key:
334
334
  specification_version: 3
335
335
  summary: RSpec tests for your servers configured by Puppet, Chef or anything else