spex 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +30 -12
- data/VERSION +1 -1
- data/examples/chgrp.rb +1 -1
- data/examples/chmod.rb +1 -1
- data/examples/chown.rb +1 -1
- data/examples/postfix.rb +4 -4
- data/examples/puppet.rb +1 -1
- data/examples/touch.rb +1 -1
- data/examples/writing.rb +1 -1
- data/lib/spex.rb +2 -2
- data/lib/spex/{assertion.rb → check.rb} +4 -4
- data/lib/spex/{assertions/changed_group_assertion.rb → checks/changed_group_check.rb} +7 -7
- data/lib/spex/{assertions/changed_mode_assertion.rb → checks/changed_mode_check.rb} +5 -5
- data/lib/spex/{assertions/changed_owner_assertion.rb → checks/changed_owner_check.rb} +7 -7
- data/lib/spex/{assertions/created_assertion.rb → checks/created_check.rb} +5 -5
- data/lib/spex/{assertions/file_assertion.rb → checks/file_check.rb} +1 -1
- data/lib/spex/{assertions/modified_assertion.rb → checks/modified_check.rb} +7 -7
- data/lib/spex/{assertions/process_assertion.rb → checks/process_check.rb} +1 -1
- data/lib/spex/{assertions/removed_assertion.rb → checks/removed_check.rb} +5 -5
- data/lib/spex/{assertions/restarted_assertion.rb → checks/restarted_check.rb} +3 -3
- data/lib/spex/{assertions/started_assertion.rb → checks/started_check.rb} +3 -3
- data/lib/spex/{assertions/stopped_assertion.rb → checks/stopped_check.rb} +3 -3
- data/lib/spex/cli.rb +7 -7
- data/lib/spex/execution.rb +8 -8
- data/lib/spex/runner.rb +13 -13
- data/test/helper.rb +13 -13
- data/test/{test_assertion.rb → test_check.rb} +7 -7
- data/test/{test_modified_assertion.rb → test_modified_check.rb} +23 -23
- data/test/{test_restarted_assertion.rb → test_restarted_check.rb} +14 -14
- data/test/test_script.rb +9 -9
- data/test/{test_started_assertion.rb → test_started_check.rb} +12 -12
- data/test/{test_stopped_assertion.rb → test_stopped_check.rb} +12 -12
- metadata +25 -25
data/README.md
CHANGED
@@ -1,9 +1,17 @@
|
|
1
1
|
Spex
|
2
2
|
====
|
3
3
|
|
4
|
-
A quick and dirty
|
4
|
+
A quick and dirty harness for running system state checks before and after
|
5
5
|
an executable is run.
|
6
6
|
|
7
|
+
It can be used:
|
8
|
+
* When developing an executable/configuration, to check real-world
|
9
|
+
results.
|
10
|
+
* In production, to ensure the system is in a known state before an
|
11
|
+
executable is run.
|
12
|
+
* In production, to provide independent logging/reporting of
|
13
|
+
executable status.
|
14
|
+
|
7
15
|
Synopsis
|
8
16
|
--------
|
9
17
|
|
@@ -16,7 +24,7 @@ be used to verify running `touch /tmp/foo` will create a new file:
|
|
16
24
|
|
17
25
|
scenario "Creates a file" do
|
18
26
|
executing 'touch /tmp/foo' do
|
19
|
-
|
27
|
+
check '/tmp/foo', :created => true
|
20
28
|
end
|
21
29
|
end
|
22
30
|
|
@@ -25,7 +33,7 @@ If this was in `run_touch.rb`, you could run this with spex:
|
|
25
33
|
$ spex run_touch.rb
|
26
34
|
|
27
35
|
You'll notice that this should pass the first time and fail on
|
28
|
-
subsequent invocations -- because the
|
36
|
+
subsequent invocations -- because the check added by `:created => true` fails in the
|
29
37
|
event a file exists *before* the command is run.
|
30
38
|
|
31
39
|
If you want to see what command and scenarios are defined in a file,
|
@@ -45,20 +53,30 @@ Examples
|
|
45
53
|
|
46
54
|
See the `examples/` directory.
|
47
55
|
|
48
|
-
|
49
|
-
|
56
|
+
Checks
|
57
|
+
------
|
58
|
+
|
59
|
+
You can see the checks that are available with the following command:
|
50
60
|
|
51
|
-
|
52
|
-
for the list of supported assertions.
|
61
|
+
$ spex --checks
|
53
62
|
|
54
|
-
To add an
|
55
|
-
`Spex::
|
56
|
-
`Spex::
|
63
|
+
To add an check, create a class that inherits from
|
64
|
+
`Spex::Check` and implements all the neccessary methods. See
|
65
|
+
`Spex::Check` and the currently defined checks for
|
57
66
|
examples.
|
58
67
|
|
59
|
-
Note: If you put your
|
68
|
+
Note: If you put your checks in `~/.spex/checks/*.rb`,
|
60
69
|
they'll automatically be loaded. If you create any interesting
|
61
|
-
|
70
|
+
checks, add them to the
|
71
|
+
[wiki](http://wiki.github.com/bruce/spex/community-checks)!
|
72
|
+
|
73
|
+
Other Resources
|
74
|
+
---------------
|
75
|
+
|
76
|
+
For more information, see the
|
77
|
+
[wiki](http://wiki.github.com/bruce/spex).
|
78
|
+
|
79
|
+
You can file bugs and features using the [issue tracker](http://github.com/bruce/spex/issues).
|
62
80
|
|
63
81
|
Copyright
|
64
82
|
---------
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.7.0
|
data/examples/chgrp.rb
CHANGED
data/examples/chmod.rb
CHANGED
data/examples/chown.rb
CHANGED
data/examples/postfix.rb
CHANGED
@@ -2,15 +2,15 @@
|
|
2
2
|
# we don't confused with spex running this file (postfix.rb)
|
3
3
|
scenario "Postfix process management" do
|
4
4
|
executing "sudo postfix start" do
|
5
|
-
|
5
|
+
check 'postfix/master', :started => true
|
6
6
|
end
|
7
7
|
executing "sudo postfix stop" do
|
8
|
-
|
8
|
+
check 'postfix/master', :stopped => true
|
9
9
|
end
|
10
10
|
executing "sudo postfix start" do
|
11
|
-
|
11
|
+
check 'postfix/master', :started => true
|
12
12
|
end
|
13
13
|
executing "sudo postfix stop && sudo postfix start" do
|
14
|
-
|
14
|
+
check 'postfix/master', :restarted => true
|
15
15
|
end
|
16
16
|
end
|
data/examples/puppet.rb
CHANGED
data/examples/touch.rb
CHANGED
data/examples/writing.rb
CHANGED
data/lib/spex.rb
CHANGED
@@ -5,10 +5,10 @@ rescue LoadError
|
|
5
5
|
end
|
6
6
|
|
7
7
|
module Spex
|
8
|
-
autoload :
|
8
|
+
autoload :Check, 'spex/check'
|
9
9
|
autoload :CLI, 'spex/cli'
|
10
10
|
autoload :Execution, 'spex/execution'
|
11
|
-
autoload :
|
11
|
+
autoload :FileCheck, 'spex/checks/file_check'
|
12
12
|
autoload :Runner, 'spex/runner'
|
13
13
|
autoload :Scenario, 'spex/scenario'
|
14
14
|
autoload :Script, 'spex/script'
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'test/unit/assertions'
|
2
2
|
|
3
3
|
module Spex
|
4
|
-
class
|
4
|
+
class Check
|
5
5
|
include Test::Unit::Assertions
|
6
6
|
extend Enumerable
|
7
7
|
|
@@ -22,7 +22,7 @@ module Spex
|
|
22
22
|
def self.as(name, description)
|
23
23
|
self.name = name
|
24
24
|
self.description = description
|
25
|
-
|
25
|
+
Check.registry[name.to_sym] = self
|
26
26
|
end
|
27
27
|
|
28
28
|
def self.example(description, text)
|
@@ -92,10 +92,10 @@ module Spex
|
|
92
92
|
end
|
93
93
|
end
|
94
94
|
|
95
|
-
Dir.glob(File.join(File.dirname(__FILE__), '
|
95
|
+
Dir.glob(File.join(File.dirname(__FILE__), 'checks', '**/*.rb')) do |path|
|
96
96
|
require path
|
97
97
|
end
|
98
98
|
|
99
|
-
Dir.glob(File.join(ENV['HOME'], '.spex', '
|
99
|
+
Dir.glob(File.join(ENV['HOME'], '.spex', 'checks', '**/*.rb')) do |path|
|
100
100
|
require path
|
101
101
|
end
|
@@ -1,17 +1,17 @@
|
|
1
1
|
require 'etc'
|
2
2
|
|
3
3
|
module Spex
|
4
|
-
class
|
4
|
+
class ChangedGroupCheck < FileCheck
|
5
5
|
as :changed_group, 'file group change'
|
6
6
|
option :to, "To group name or gid"
|
7
7
|
option :from, "From group name or gid"
|
8
8
|
|
9
|
-
example "Changed the file group", "
|
10
|
-
example "Did not change the file group", "
|
11
|
-
example "Changed the file group from 'wheel' to 'www-users'", "
|
12
|
-
example "Changed the file group from gid 210 to gid 288", "
|
13
|
-
example "Changed the file group to 'users'", "
|
14
|
-
example "Changed the file group to gid 203", "
|
9
|
+
example "Changed the file group", "check '/tmp/foo', :changed_group => true"
|
10
|
+
example "Did not change the file group", "check '/tmp/foo', :changed_group => false"
|
11
|
+
example "Changed the file group from 'wheel' to 'www-users'", "check '/tmp/foo', :changed_group => {:from => 'wheel', :to => 'www-users'}"
|
12
|
+
example "Changed the file group from gid 210 to gid 288", "check '/tmp/foo', :changed_group => {:from => 210, :to => 288}"
|
13
|
+
example "Changed the file group to 'users'", "check '/tmp/foo', :changed_group => {:to => 'users'}"
|
14
|
+
example "Changed the file group to gid 203", "check '/tmp/foo', :changed_group => {:to => 203}"
|
15
15
|
|
16
16
|
def before
|
17
17
|
assert File.exist?(target), "File does not exist at #{target}"
|
@@ -1,13 +1,13 @@
|
|
1
1
|
module Spex
|
2
|
-
class
|
2
|
+
class ChangedModeCheck < FileCheck
|
3
3
|
as :changed_mode, "file mode change"
|
4
4
|
option :from, "Mode changed from (octal, eg 0600)"
|
5
5
|
option :to, "Mode changed to (octal, eg 0700)"
|
6
6
|
|
7
|
-
example "Changed the file mode", "
|
8
|
-
example "Did not change the file mode", "
|
9
|
-
example "Changed the file mode from 0666 to 0755", "
|
10
|
-
example "Changed the file mode to 0750", "
|
7
|
+
example "Changed the file mode", "check '/tmp/foo', :changed_mode => true"
|
8
|
+
example "Did not change the file mode", "check '/tmp/foo', :changed_mode => false"
|
9
|
+
example "Changed the file mode from 0666 to 0755", "check '/tmp/foo', :changed_mode => {:from => 0666, :to => 0755}"
|
10
|
+
example "Changed the file mode to 0750", "check '/tmp/foo', :changed_mode => {:to => 0750}"
|
11
11
|
|
12
12
|
def before
|
13
13
|
assert File.exist?(target), "File does not exist at #{target}"
|
@@ -1,17 +1,17 @@
|
|
1
1
|
require 'etc'
|
2
2
|
|
3
3
|
module Spex
|
4
|
-
class
|
4
|
+
class ChangedOwnerCheck < FileCheck
|
5
5
|
as :changed_owner, 'file owner change'
|
6
6
|
option :from, "From username or uid"
|
7
7
|
option :to, "To username or uid"
|
8
8
|
|
9
|
-
example "Changed the file owner", "
|
10
|
-
example "Did not change the file owner", "
|
11
|
-
example "Changed the file owner from 'root' to 'bruce'", "
|
12
|
-
example "Changed the file owner from uid 501 to uid 503", "
|
13
|
-
example "Changed the file owner to 'jim'", "
|
14
|
-
example "Changed the file owner to uid 506", "
|
9
|
+
example "Changed the file owner", "check '/tmp/foo', :changed_owner => true"
|
10
|
+
example "Did not change the file owner", "check '/tmp/foo', :changed_owner => false"
|
11
|
+
example "Changed the file owner from 'root' to 'bruce'", "check '/tmp/foo', :changed_owner => {:from => 'root', :to => 'bruce'}"
|
12
|
+
example "Changed the file owner from uid 501 to uid 503", "check '/tmp/foo', :changed_owner => {:from => 501, :to => 503}"
|
13
|
+
example "Changed the file owner to 'jim'", "check '/tmp/foo', :changed_owner => {:to => 'jim'}"
|
14
|
+
example "Changed the file owner to uid 506", "check '/tmp/foo', :changed_owner => {:to => 506}"
|
15
15
|
|
16
16
|
def before
|
17
17
|
assert File.exist?(target), "File does not exist at #{target}"
|
@@ -1,11 +1,11 @@
|
|
1
1
|
module Spex
|
2
|
-
class
|
2
|
+
class CreatedCheck < FileCheck
|
3
3
|
as :created, 'file creation'
|
4
4
|
option :type, "Type ('file' or 'directory'), optional"
|
5
|
-
example "File was created", "
|
6
|
-
example "File was not created", "
|
7
|
-
example "Regular file was created", "
|
8
|
-
example "Directory was created", "
|
5
|
+
example "File was created", "check '/tmp/foo', :created => true"
|
6
|
+
example "File was not created", "check '/tmp/foo', :created => false"
|
7
|
+
example "Regular file was created", "check '/tmp/foo', :created => {:type => 'file'}"
|
8
|
+
example "Directory was created", "check '/tmp/foo', :created => {:type => 'directory'}"
|
9
9
|
|
10
10
|
def before
|
11
11
|
assert !File.exist?(target), "File already exists at #{target}"
|
@@ -5,16 +5,16 @@ require 'diff/lcs/array'
|
|
5
5
|
module Spex
|
6
6
|
|
7
7
|
# With no option, just verifies a change occurs
|
8
|
-
class
|
8
|
+
class ModifiedCheck < FileCheck
|
9
9
|
as :modified, 'file modification'
|
10
10
|
option :added, "Added content (string or regexp)"
|
11
11
|
option :removed, "Removed content (string or regexp)"
|
12
|
-
example "Modified a file", "
|
13
|
-
example "Did not modify a file", "
|
14
|
-
example "Added a line with 'a substring' in it", "
|
15
|
-
example "Added a line matching /a substring pattern/", "
|
16
|
-
example "Removed a line with 'a substring' in it", "
|
17
|
-
example "Removed a line matching /a substring pattern/", "
|
12
|
+
example "Modified a file", "check '/tmp/foo', :modified => true"
|
13
|
+
example "Did not modify a file", "check '/tmp/foo', :modified => false"
|
14
|
+
example "Added a line with 'a substring' in it", "check '/tmp/foo', :modified => {:added => 'a substring'}"
|
15
|
+
example "Added a line matching /a substring pattern/", "check '/tmp/foo', :modified => {:added => /a substring pattern/}"
|
16
|
+
example "Removed a line with 'a substring' in it", "check '/tmp/foo', :modified => {:removed => 'a substring'}"
|
17
|
+
example "Removed a line matching /a substring pattern/", "check '/tmp/foo', :modified => {:removed => /a substring pattern/}"
|
18
18
|
|
19
19
|
def prepare
|
20
20
|
track_checksum!
|
@@ -1,11 +1,11 @@
|
|
1
1
|
module Spex
|
2
|
-
class
|
2
|
+
class RemovedCheck < FileCheck
|
3
3
|
as :removed, 'file removal'
|
4
4
|
option :type, "Type (:file or :directory), optional"
|
5
|
-
example "File was removed", "
|
6
|
-
example "File was not removed", "
|
7
|
-
example "Regular file was removed", "
|
8
|
-
example "Directory was removed", "
|
5
|
+
example "File was removed", "check '/tmp/foo', :removed => true"
|
6
|
+
example "File was not removed", "check '/tmp/foo', :removed => false"
|
7
|
+
example "Regular file was removed", "check '/tmp/foo', :removed => {:type => 'file'}"
|
8
|
+
example "Directory was removed", "check '/tmp/foo', :removed => {:type => 'directory'}"
|
9
9
|
|
10
10
|
def before
|
11
11
|
assert File.exist?(target), "File does not exist at #{target}"
|
@@ -1,8 +1,8 @@
|
|
1
1
|
module Spex
|
2
|
-
class
|
2
|
+
class RestartedCheck < ProcessCheck
|
3
3
|
as :restarted, 'process restart'
|
4
|
-
example "Process was restarted", "
|
5
|
-
example "Process was not restarted", "
|
4
|
+
example "Process was restarted", "check 'postfix', :restarted => true"
|
5
|
+
example "Process was not restarted", "check 'postfix', :restarted => false"
|
6
6
|
|
7
7
|
def before
|
8
8
|
@before_pid = current_pid
|
@@ -1,8 +1,8 @@
|
|
1
1
|
module Spex
|
2
|
-
class
|
2
|
+
class StartedCheck < ProcessCheck
|
3
3
|
as :started, 'process start'
|
4
|
-
example "Process was started", "
|
5
|
-
example "Process was not started", "
|
4
|
+
example "Process was started", "check 'postfix', :started => true"
|
5
|
+
example "Process was not started", "check 'postfix', :started => false"
|
6
6
|
|
7
7
|
def before
|
8
8
|
pid = current_pid
|
@@ -1,8 +1,8 @@
|
|
1
1
|
module Spex
|
2
|
-
class
|
2
|
+
class StoppedCheck < ProcessCheck
|
3
3
|
as :stopped, 'process stop'
|
4
|
-
example "Process was stopped", "
|
5
|
-
example "Process was not stopped", "
|
4
|
+
example "Process was stopped", "check 'postfix', :stopped => true"
|
5
|
+
example "Process was not stopped", "check 'postfix', :stopped => false"
|
6
6
|
|
7
7
|
def before
|
8
8
|
assert current_pid, "Process '#{target}' is not running (will not be stopped)"
|
data/lib/spex/cli.rb
CHANGED
@@ -23,8 +23,8 @@ module Spex
|
|
23
23
|
opts.on('--describe', '-d', 'Describe DEFINITION_FILE') do
|
24
24
|
options.describe = true
|
25
25
|
end
|
26
|
-
opts.on('--
|
27
|
-
|
26
|
+
opts.on('--checks', '-c', "List supported checks") do
|
27
|
+
display_checks
|
28
28
|
exit
|
29
29
|
end
|
30
30
|
end
|
@@ -53,9 +53,9 @@ module Spex
|
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
56
|
-
def
|
57
|
-
|
58
|
-
line = "
|
56
|
+
def display_checks
|
57
|
+
Check.registry.each_value do |klass|
|
58
|
+
line = "Check: :#{klass.name} (#{klass.description})"
|
59
59
|
puts line
|
60
60
|
if klass.options.any? || klass.examples.any?
|
61
61
|
puts('=' * line.size)
|
@@ -82,8 +82,8 @@ module Spex
|
|
82
82
|
puts %(In scenario "#{scenario.name}")
|
83
83
|
scenario.executions.each do |execution|
|
84
84
|
puts " When executing `#{execution.command}`"
|
85
|
-
execution.
|
86
|
-
puts " assert #{
|
85
|
+
execution.checks.each do |check|
|
86
|
+
puts " assert #{check}"
|
87
87
|
end
|
88
88
|
end
|
89
89
|
end
|
data/lib/spex/execution.rb
CHANGED
@@ -9,16 +9,16 @@ module Spex
|
|
9
9
|
Builder.new(self, &block)
|
10
10
|
end
|
11
11
|
|
12
|
-
def
|
13
|
-
@
|
12
|
+
def checks
|
13
|
+
@checks ||= []
|
14
14
|
end
|
15
15
|
|
16
|
-
def <<(
|
17
|
-
|
16
|
+
def <<(check)
|
17
|
+
checks << check
|
18
18
|
end
|
19
19
|
|
20
20
|
def each(&block)
|
21
|
-
|
21
|
+
checks.each(&block)
|
22
22
|
end
|
23
23
|
|
24
24
|
class Builder
|
@@ -27,9 +27,9 @@ module Spex
|
|
27
27
|
instance_eval(&block) if block_given?
|
28
28
|
end
|
29
29
|
|
30
|
-
def
|
31
|
-
|
32
|
-
@execution <<
|
30
|
+
def check(target, check_names = {})
|
31
|
+
check_names.each do |name, options|
|
32
|
+
@execution << Check[name].new(target, options)
|
33
33
|
end
|
34
34
|
end
|
35
35
|
end
|
data/lib/spex/runner.rb
CHANGED
@@ -19,10 +19,10 @@ module Spex
|
|
19
19
|
proceed = true
|
20
20
|
scenario.each do |execution|
|
21
21
|
puts %(Preparing to execute "#{execution.command}").bold
|
22
|
-
execution.
|
23
|
-
print "Pre-
|
24
|
-
|
25
|
-
proceed = report {
|
22
|
+
execution.checks.each do |check|
|
23
|
+
print "Pre-checks for #{check}: "
|
24
|
+
check.prepare
|
25
|
+
proceed = report { check.before }
|
26
26
|
break unless proceed
|
27
27
|
end
|
28
28
|
if proceed
|
@@ -32,13 +32,13 @@ module Spex
|
|
32
32
|
elapsed = Time.now - start
|
33
33
|
puts 'DONE (%.2fs)' % elapsed
|
34
34
|
passed = true
|
35
|
-
execution.
|
36
|
-
print "Post-
|
37
|
-
passed = report {
|
35
|
+
execution.checks.reverse.each do |check|
|
36
|
+
print "Post-checks for #{check}: "
|
37
|
+
passed = report { check.after }
|
38
38
|
break unless passed
|
39
39
|
end
|
40
40
|
unless passed
|
41
|
-
abort "SCENARIO
|
41
|
+
abort "SCENARIO CHECKS FAILED".red.bold
|
42
42
|
end
|
43
43
|
output_log(execution, log)
|
44
44
|
else
|
@@ -96,13 +96,13 @@ module Spex
|
|
96
96
|
setup do
|
97
97
|
@executed ||= self.class.spex_runner.execute(self.class.execution)
|
98
98
|
end
|
99
|
-
order = parent.execution.
|
99
|
+
order = parent.execution.checks.reverse
|
100
100
|
when :before
|
101
|
-
order = parent.execution.
|
101
|
+
order = parent.execution.checks
|
102
102
|
end
|
103
|
-
order.each do |
|
104
|
-
should "pass
|
105
|
-
|
103
|
+
order.each do |check|
|
104
|
+
should "pass check #{check.inspect}" do
|
105
|
+
check.__send__(event, self)
|
106
106
|
end
|
107
107
|
end
|
108
108
|
end
|
data/test/helper.rb
CHANGED
@@ -17,34 +17,34 @@ class Test::Unit::TestCase
|
|
17
17
|
@script = Spex::Script.evaluate(&block)
|
18
18
|
end
|
19
19
|
|
20
|
-
def
|
21
|
-
@
|
22
|
-
@
|
20
|
+
def check_passes(&block)
|
21
|
+
@check.prepare
|
22
|
+
@check.before
|
23
23
|
yield if block_given?
|
24
|
-
@
|
24
|
+
@check.after
|
25
25
|
end
|
26
26
|
|
27
|
-
def
|
27
|
+
def check_fails_before
|
28
28
|
assert_raises Test::Unit::AssertionFailedError do
|
29
|
-
@
|
30
|
-
@
|
29
|
+
@check.prepare
|
30
|
+
@check.before
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
def
|
34
|
+
def check_fails(&block)
|
35
35
|
assert_raises Test::Unit::AssertionFailedError do
|
36
|
-
|
36
|
+
check_passes(&block)
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
40
|
def start_process!(pid = '100')
|
41
|
-
flexmock(@
|
42
|
-
flexmock(@
|
41
|
+
flexmock(@check).flexmock_teardown
|
42
|
+
flexmock(@check).should_receive(:current_pid).and_return(pid)
|
43
43
|
end
|
44
44
|
|
45
45
|
def stop_process!
|
46
|
-
flexmock(@
|
47
|
-
flexmock(@
|
46
|
+
flexmock(@check).flexmock_teardown
|
47
|
+
flexmock(@check).should_receive(:current_pid).and_return(nil)
|
48
48
|
end
|
49
49
|
|
50
50
|
end
|
@@ -1,14 +1,14 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
|
-
class
|
4
|
-
context "
|
3
|
+
class TestCheck < Test::Unit::TestCase
|
4
|
+
context "Check" do
|
5
5
|
setup do
|
6
|
-
@klass = Class.new(Spex::
|
6
|
+
@klass = Class.new(Spex::Check)
|
7
7
|
end
|
8
8
|
|
9
9
|
context "instances" do
|
10
10
|
should "raise an exception if instantiated with an unknown option" do
|
11
|
-
assert_raises Spex::
|
11
|
+
assert_raises Spex::Check::UnknownOptionError do
|
12
12
|
@klass.new('/tmp/foo', :unknown => 'option')
|
13
13
|
end
|
14
14
|
end
|
@@ -20,8 +20,8 @@ class TestAssertion < Test::Unit::TestCase
|
|
20
20
|
@klass.as :something, "Something being added"
|
21
21
|
end
|
22
22
|
|
23
|
-
should "be added to the list of
|
24
|
-
assert_equal @klass, Spex::
|
23
|
+
should "be added to the list of checks" do
|
24
|
+
assert_equal @klass, Spex::Check[:something]
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
@@ -41,7 +41,7 @@ class TestAssertion < Test::Unit::TestCase
|
|
41
41
|
end
|
42
42
|
|
43
43
|
should "be of the correct class" do
|
44
|
-
assert_kind_of Spex::
|
44
|
+
assert_kind_of Spex::Check::Option, @option
|
45
45
|
end
|
46
46
|
|
47
47
|
should "have a name" do
|
@@ -1,9 +1,9 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
|
-
class
|
3
|
+
class TestModifiedCheck < Test::Unit::TestCase
|
4
4
|
|
5
|
-
def
|
6
|
-
@
|
5
|
+
def set_check(options = {})
|
6
|
+
@check = Spex::ModifiedCheck.new(@filename, options)
|
7
7
|
end
|
8
8
|
|
9
9
|
def non_blank_file!(text = 'test')
|
@@ -14,7 +14,7 @@ class TestModifiedAssertion < Test::Unit::TestCase
|
|
14
14
|
File.open(@filename, 'w') { |f| f.puts }
|
15
15
|
end
|
16
16
|
|
17
|
-
context "Modified
|
17
|
+
context "Modified Check" do
|
18
18
|
setup do
|
19
19
|
FakeFS.activate!
|
20
20
|
@filename = '/tmp/modified-test'
|
@@ -27,56 +27,56 @@ class TestModifiedAssertion < Test::Unit::TestCase
|
|
27
27
|
context "instances" do
|
28
28
|
context "without options" do
|
29
29
|
setup do
|
30
|
-
|
30
|
+
set_check
|
31
31
|
blank_file!
|
32
32
|
end
|
33
33
|
should "pass when modifications happen" do
|
34
|
-
|
34
|
+
check_passes { non_blank_file! }
|
35
35
|
end
|
36
36
|
should "when modifications don't happen" do
|
37
|
-
|
37
|
+
check_fails
|
38
38
|
end
|
39
39
|
end
|
40
40
|
context "with :added" do
|
41
41
|
context "as a string" do
|
42
42
|
setup do
|
43
|
-
|
43
|
+
set_check(:added => 'test')
|
44
44
|
blank_file!
|
45
45
|
end
|
46
46
|
context "when the text is added" do
|
47
47
|
should "pass" do
|
48
|
-
|
48
|
+
check_passes { non_blank_file! }
|
49
49
|
end
|
50
50
|
end
|
51
51
|
context "when different text is added" do
|
52
52
|
should "fail" do
|
53
|
-
|
53
|
+
check_fails { non_blank_file!('other') }
|
54
54
|
end
|
55
55
|
end
|
56
56
|
context "when modifications don't happen" do
|
57
57
|
should "fail when modifications don't happen" do
|
58
|
-
|
58
|
+
check_fails
|
59
59
|
end
|
60
60
|
end
|
61
61
|
end
|
62
62
|
context "as a regexp" do
|
63
63
|
setup do
|
64
|
-
|
64
|
+
set_check(:added => /t.st/)
|
65
65
|
blank_file!
|
66
66
|
end
|
67
67
|
context "when the text is added" do
|
68
68
|
should "pass" do
|
69
|
-
|
69
|
+
check_passes { non_blank_file! }
|
70
70
|
end
|
71
71
|
end
|
72
72
|
context "when different text is added" do
|
73
73
|
should "fail" do
|
74
|
-
|
74
|
+
check_fails { non_blank_file!('other') }
|
75
75
|
end
|
76
76
|
end
|
77
77
|
context "when modifications don't happen" do
|
78
78
|
should "fail when modifications don't happen" do
|
79
|
-
|
79
|
+
check_fails
|
80
80
|
end
|
81
81
|
end
|
82
82
|
end
|
@@ -84,14 +84,14 @@ class TestModifiedAssertion < Test::Unit::TestCase
|
|
84
84
|
context "with :removed" do
|
85
85
|
context "as a string" do
|
86
86
|
setup do
|
87
|
-
|
87
|
+
set_check(:removed => 'test')
|
88
88
|
end
|
89
89
|
context "when the text is removed" do
|
90
90
|
setup do
|
91
91
|
non_blank_file!
|
92
92
|
end
|
93
93
|
should "pass" do
|
94
|
-
|
94
|
+
check_passes { blank_file! }
|
95
95
|
end
|
96
96
|
end
|
97
97
|
context "when different text is removed" do
|
@@ -99,25 +99,25 @@ class TestModifiedAssertion < Test::Unit::TestCase
|
|
99
99
|
non_blank_file!('other')
|
100
100
|
end
|
101
101
|
should "fail" do
|
102
|
-
|
102
|
+
check_fails { blank_file! }
|
103
103
|
end
|
104
104
|
end
|
105
105
|
context "when modifications don't happen" do
|
106
106
|
should "fail when modifications don't happen" do
|
107
|
-
|
107
|
+
check_fails
|
108
108
|
end
|
109
109
|
end
|
110
110
|
end
|
111
111
|
context "as a regexp" do
|
112
112
|
setup do
|
113
|
-
|
113
|
+
set_check(:removed => /t.st/)
|
114
114
|
end
|
115
115
|
context "when the text is removed" do
|
116
116
|
setup do
|
117
117
|
non_blank_file!
|
118
118
|
end
|
119
119
|
should "pass" do
|
120
|
-
|
120
|
+
check_passes { blank_file! }
|
121
121
|
end
|
122
122
|
end
|
123
123
|
context "when different text is removed" do
|
@@ -125,12 +125,12 @@ class TestModifiedAssertion < Test::Unit::TestCase
|
|
125
125
|
non_blank_file!('other')
|
126
126
|
end
|
127
127
|
should "fail" do
|
128
|
-
|
128
|
+
check_fails { blank_file! }
|
129
129
|
end
|
130
130
|
end
|
131
131
|
context "when modifications don't happen" do
|
132
132
|
should "fail when modifications don't happen" do
|
133
|
-
|
133
|
+
check_fails
|
134
134
|
end
|
135
135
|
end
|
136
136
|
end
|
@@ -1,16 +1,16 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
|
-
class
|
3
|
+
class TestRestartedCheck < Test::Unit::TestCase
|
4
4
|
|
5
|
-
def
|
6
|
-
@
|
5
|
+
def set_check(options = {})
|
6
|
+
@check = Spex::RestartedCheck.new('testproc', options)
|
7
7
|
end
|
8
8
|
|
9
|
-
context "Restarted
|
9
|
+
context "Restarted Check" do
|
10
10
|
context "instances" do
|
11
11
|
context "set to true" do
|
12
12
|
setup do
|
13
|
-
|
13
|
+
set_check(true)
|
14
14
|
end
|
15
15
|
context "process running before execution" do
|
16
16
|
setup do
|
@@ -19,30 +19,30 @@ class TestRestartedAssertion < Test::Unit::TestCase
|
|
19
19
|
context "and process running after execution" do
|
20
20
|
context "with the same pid" do
|
21
21
|
should 'fail' do
|
22
|
-
|
22
|
+
check_fails
|
23
23
|
end
|
24
24
|
end
|
25
25
|
context "with a different pid" do
|
26
26
|
should 'pass' do
|
27
|
-
|
27
|
+
check_passes { start_process!('101') }
|
28
28
|
end
|
29
29
|
end
|
30
30
|
end
|
31
31
|
context "but process not running after execution" do
|
32
32
|
should "fail" do
|
33
|
-
|
33
|
+
check_fails
|
34
34
|
end
|
35
35
|
end
|
36
36
|
end
|
37
37
|
context "process not running before execution" do
|
38
38
|
should "fail" do
|
39
|
-
|
39
|
+
check_fails_before
|
40
40
|
end
|
41
41
|
end
|
42
42
|
end
|
43
43
|
context "set to false" do
|
44
44
|
setup do
|
45
|
-
|
45
|
+
set_check(false)
|
46
46
|
end
|
47
47
|
context "process running before execution" do
|
48
48
|
setup do
|
@@ -51,24 +51,24 @@ class TestRestartedAssertion < Test::Unit::TestCase
|
|
51
51
|
context "and process running after execution" do
|
52
52
|
context "with the same pid" do
|
53
53
|
should 'pass' do
|
54
|
-
|
54
|
+
check_passes
|
55
55
|
end
|
56
56
|
end
|
57
57
|
context "with a different pid" do
|
58
58
|
should 'fail' do
|
59
|
-
|
59
|
+
check_fails { start_process!('101') }
|
60
60
|
end
|
61
61
|
end
|
62
62
|
end
|
63
63
|
context "but process not running after execution" do
|
64
64
|
should "fail" do
|
65
|
-
|
65
|
+
check_fails { stop_process! }
|
66
66
|
end
|
67
67
|
end
|
68
68
|
end
|
69
69
|
context "process not running before execution" do
|
70
70
|
should "fail" do
|
71
|
-
|
71
|
+
check_fails_before
|
72
72
|
end
|
73
73
|
end
|
74
74
|
end
|
data/test/test_script.rb
CHANGED
@@ -28,25 +28,25 @@ class TestScript < Test::Unit::TestCase
|
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
|
-
context "a scenario and execution definition with an
|
31
|
+
context "a scenario and execution definition with an check" do
|
32
32
|
setup do
|
33
33
|
script do
|
34
34
|
scenario("name") do
|
35
35
|
executing('foo') do
|
36
|
-
|
36
|
+
check '/tmp/foo', :created => true
|
37
37
|
end
|
38
38
|
end
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
|
-
should "create an
|
42
|
+
should "create an check instance" do
|
43
43
|
execution = @script.scenarios.first.executions.first
|
44
|
-
assert_equal 1, execution.
|
45
|
-
|
46
|
-
assert_kind_of Spex::
|
47
|
-
assert_equal '/tmp/foo',
|
48
|
-
assert
|
49
|
-
assert_equal({},
|
44
|
+
assert_equal 1, execution.checks.size
|
45
|
+
check = execution.checks.first
|
46
|
+
assert_kind_of Spex::Check, check
|
47
|
+
assert_equal '/tmp/foo', check.target
|
48
|
+
assert check.active?
|
49
|
+
assert_equal({}, check.options)
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
@@ -1,59 +1,59 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
|
-
class
|
3
|
+
class TestStartedCheck < Test::Unit::TestCase
|
4
4
|
|
5
|
-
def
|
6
|
-
@
|
5
|
+
def set_check(options = {})
|
6
|
+
@check = Spex::StartedCheck.new('testproc', options)
|
7
7
|
end
|
8
8
|
|
9
|
-
context "Started
|
9
|
+
context "Started Check" do
|
10
10
|
context "instances" do
|
11
11
|
context "set to true" do
|
12
12
|
setup do
|
13
|
-
|
13
|
+
set_check(true)
|
14
14
|
end
|
15
15
|
context "process running before execution" do
|
16
16
|
setup do
|
17
17
|
start_process!
|
18
18
|
end
|
19
19
|
should "fail" do
|
20
|
-
|
20
|
+
check_fails_before
|
21
21
|
end
|
22
22
|
end
|
23
23
|
context "process not running before execution" do
|
24
24
|
context "process running after execution" do
|
25
25
|
should "pass" do
|
26
|
-
|
26
|
+
check_passes { start_process! }
|
27
27
|
end
|
28
28
|
end
|
29
29
|
context "process not running after execution" do
|
30
30
|
should 'fail' do
|
31
|
-
|
31
|
+
check_fails
|
32
32
|
end
|
33
33
|
end
|
34
34
|
end
|
35
35
|
end
|
36
36
|
context "set to false" do
|
37
37
|
setup do
|
38
|
-
|
38
|
+
set_check(false)
|
39
39
|
end
|
40
40
|
context "process running before execution" do
|
41
41
|
setup do
|
42
42
|
start_process!
|
43
43
|
end
|
44
44
|
should "fail" do
|
45
|
-
|
45
|
+
check_fails_before
|
46
46
|
end
|
47
47
|
end
|
48
48
|
context "process not running before execution" do
|
49
49
|
context "but process running after execution" do
|
50
50
|
should "fail" do
|
51
|
-
|
51
|
+
check_fails { start_process! }
|
52
52
|
end
|
53
53
|
end
|
54
54
|
context "but process not running after execution" do
|
55
55
|
should 'pass' do
|
56
|
-
|
56
|
+
check_passes
|
57
57
|
end
|
58
58
|
end
|
59
59
|
end
|
@@ -1,16 +1,16 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
|
-
class
|
3
|
+
class TestStoppedCheck < Test::Unit::TestCase
|
4
4
|
|
5
|
-
def
|
6
|
-
@
|
5
|
+
def set_check(options = {})
|
6
|
+
@check = Spex::StoppedCheck.new('testproc', options)
|
7
7
|
end
|
8
8
|
|
9
|
-
context "Stopped
|
9
|
+
context "Stopped Check" do
|
10
10
|
context "instances" do
|
11
11
|
context "set to true" do
|
12
12
|
setup do
|
13
|
-
|
13
|
+
set_check(true)
|
14
14
|
end
|
15
15
|
context "process running before execution" do
|
16
16
|
setup do
|
@@ -18,24 +18,24 @@ class TestStoppedAssertion < Test::Unit::TestCase
|
|
18
18
|
end
|
19
19
|
context "and process running after execution" do
|
20
20
|
should 'fail' do
|
21
|
-
|
21
|
+
check_fails
|
22
22
|
end
|
23
23
|
end
|
24
24
|
context "but process not running after execution" do
|
25
25
|
should "pass" do
|
26
|
-
|
26
|
+
check_passes { stop_process! }
|
27
27
|
end
|
28
28
|
end
|
29
29
|
end
|
30
30
|
context "process not running before execution" do
|
31
31
|
should "fail" do
|
32
|
-
|
32
|
+
check_fails_before
|
33
33
|
end
|
34
34
|
end
|
35
35
|
end
|
36
36
|
context "set to false" do
|
37
37
|
setup do
|
38
|
-
|
38
|
+
set_check(false)
|
39
39
|
end
|
40
40
|
context "process running before execution" do
|
41
41
|
setup do
|
@@ -43,18 +43,18 @@ class TestStoppedAssertion < Test::Unit::TestCase
|
|
43
43
|
end
|
44
44
|
context "and process running after execution" do
|
45
45
|
should 'pass' do
|
46
|
-
|
46
|
+
check_passes
|
47
47
|
end
|
48
48
|
end
|
49
49
|
context "but process not running after execution" do
|
50
50
|
should "fail" do
|
51
|
-
|
51
|
+
check_fails { stop_process! }
|
52
52
|
end
|
53
53
|
end
|
54
54
|
end
|
55
55
|
context "process not running before execution" do
|
56
56
|
should "fail" do
|
57
|
-
|
57
|
+
check_fails_before
|
58
58
|
end
|
59
59
|
end
|
60
60
|
end
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
7
|
+
- 7
|
8
8
|
- 0
|
9
|
-
version: 0.
|
9
|
+
version: 0.7.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Bruce Williams
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-04-
|
17
|
+
date: 2010-04-22 00:00:00 -07:00
|
18
18
|
default_executable: spex
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -78,30 +78,30 @@ files:
|
|
78
78
|
- examples/touch.rb
|
79
79
|
- examples/writing.rb
|
80
80
|
- lib/spex.rb
|
81
|
-
- lib/spex/
|
82
|
-
- lib/spex/
|
83
|
-
- lib/spex/
|
84
|
-
- lib/spex/
|
85
|
-
- lib/spex/
|
86
|
-
- lib/spex/
|
87
|
-
- lib/spex/
|
88
|
-
- lib/spex/
|
89
|
-
- lib/spex/
|
90
|
-
- lib/spex/
|
91
|
-
- lib/spex/
|
92
|
-
- lib/spex/
|
81
|
+
- lib/spex/check.rb
|
82
|
+
- lib/spex/checks/changed_group_check.rb
|
83
|
+
- lib/spex/checks/changed_mode_check.rb
|
84
|
+
- lib/spex/checks/changed_owner_check.rb
|
85
|
+
- lib/spex/checks/created_check.rb
|
86
|
+
- lib/spex/checks/file_check.rb
|
87
|
+
- lib/spex/checks/modified_check.rb
|
88
|
+
- lib/spex/checks/process_check.rb
|
89
|
+
- lib/spex/checks/removed_check.rb
|
90
|
+
- lib/spex/checks/restarted_check.rb
|
91
|
+
- lib/spex/checks/started_check.rb
|
92
|
+
- lib/spex/checks/stopped_check.rb
|
93
93
|
- lib/spex/cli.rb
|
94
94
|
- lib/spex/execution.rb
|
95
95
|
- lib/spex/runner.rb
|
96
96
|
- lib/spex/scenario.rb
|
97
97
|
- lib/spex/script.rb
|
98
98
|
- test/helper.rb
|
99
|
-
- test/
|
100
|
-
- test/
|
101
|
-
- test/
|
99
|
+
- test/test_check.rb
|
100
|
+
- test/test_modified_check.rb
|
101
|
+
- test/test_restarted_check.rb
|
102
102
|
- test/test_script.rb
|
103
|
-
- test/
|
104
|
-
- test/
|
103
|
+
- test/test_started_check.rb
|
104
|
+
- test/test_stopped_check.rb
|
105
105
|
has_rdoc: true
|
106
106
|
homepage: http://github.com/bruce/spex
|
107
107
|
licenses: []
|
@@ -134,12 +134,12 @@ specification_version: 3
|
|
134
134
|
summary: A test harness for executables
|
135
135
|
test_files:
|
136
136
|
- test/helper.rb
|
137
|
-
- test/
|
138
|
-
- test/
|
139
|
-
- test/
|
137
|
+
- test/test_check.rb
|
138
|
+
- test/test_modified_check.rb
|
139
|
+
- test/test_restarted_check.rb
|
140
140
|
- test/test_script.rb
|
141
|
-
- test/
|
142
|
-
- test/
|
141
|
+
- test/test_started_check.rb
|
142
|
+
- test/test_stopped_check.rb
|
143
143
|
- examples/chgrp.rb
|
144
144
|
- examples/chmod.rb
|
145
145
|
- examples/chown.rb
|