spex 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +66 -0
- data/Rakefile +1 -2
- data/VERSION +1 -1
- data/bin/spex +1 -1
- data/examples/chgrp.rb +5 -0
- data/examples/chmod.rb +5 -0
- data/examples/chown.rb +5 -0
- data/examples/puppet.rb +9 -0
- data/examples/touch.rb +5 -0
- data/examples/writing.rb +5 -0
- data/lib/spex.rb +4 -4
- data/lib/spex/assertion.rb +57 -13
- data/lib/spex/assertions/changed_group_assertion.rb +61 -0
- data/lib/spex/assertions/changed_mode_assertion.rb +48 -0
- data/lib/spex/assertions/changed_owner_assertion.rb +73 -0
- data/lib/spex/assertions/created_assertion.rb +26 -0
- data/lib/spex/assertions/file_assertion.rb +1 -10
- data/lib/spex/assertions/modified_assertion.rb +56 -0
- data/lib/spex/assertions/removed_assertion.rb +27 -0
- data/lib/spex/cli.rb +65 -36
- data/lib/spex/execution.rb +37 -0
- data/lib/spex/runner.rb +73 -51
- data/lib/spex/scenario.rb +22 -12
- data/lib/spex/script.rb +13 -18
- data/test/helper.rb +7 -0
- data/test/test_assertion.rb +58 -0
- data/test/test_script.rb +54 -0
- metadata +29 -42
- data/README.markdown +0 -116
- data/examples/chgrp/run.sh +0 -3
- data/examples/chgrp/scenarios.rb +0 -5
- data/examples/chmod/run.sh +0 -3
- data/examples/chmod/scenarios.rb +0 -5
- data/examples/chown/run.sh +0 -3
- data/examples/chown/scenarios.rb +0 -5
- data/examples/puppet/manifest.pp +0 -3
- data/examples/puppet/run.sh +0 -3
- data/examples/puppet/scenarios.rb +0 -5
- data/examples/touch/run.sh +0 -3
- data/examples/touch/scenarios.rb +0 -5
- data/lib/spex/assertions/chgrps_file_assertion.rb +0 -81
- data/lib/spex/assertions/chmods_file_assertion.rb +0 -56
- data/lib/spex/assertions/chowns_file_assertion.rb +0 -81
- data/lib/spex/assertions/creates_file_assertion.rb +0 -31
- data/lib/spex/assertions/removes_file_assertion.rb +0 -31
- data/lib/spex/script/builder.rb +0 -15
- data/test/test_stringup.rb +0 -7
data/examples/chown/run.sh
DELETED
data/examples/chown/scenarios.rb
DELETED
data/examples/puppet/manifest.pp
DELETED
data/examples/puppet/run.sh
DELETED
data/examples/touch/run.sh
DELETED
data/examples/touch/scenarios.rb
DELETED
@@ -1,81 +0,0 @@
|
|
1
|
-
require 'etc'
|
2
|
-
|
3
|
-
module Spex
|
4
|
-
class ChgrpsFileAssertion < FileAssertion
|
5
|
-
assertion :chgrps_file
|
6
|
-
|
7
|
-
def before(test_case)
|
8
|
-
if from_groupname
|
9
|
-
test_case.assert File.exist?(@path), "File does not exist at #{@path}"
|
10
|
-
test_case.assert_equal from_groupname, current_groupname
|
11
|
-
elsif @options[:changes]
|
12
|
-
test_case.assert_not_equal to_groupname, current_groupname, "Group will not be changed; already '#{to_groupname}'"
|
13
|
-
end
|
14
|
-
@before_groupname = current_groupname
|
15
|
-
end
|
16
|
-
|
17
|
-
def before?
|
18
|
-
from_groupname || @options[:changes]
|
19
|
-
end
|
20
|
-
|
21
|
-
def after(test_case)
|
22
|
-
if to_groupname
|
23
|
-
test_case.assert File.exist?(@path), "File does not exist at #{@path}"
|
24
|
-
test_case.assert_equal to_groupname, current_groupname
|
25
|
-
elsif @options[:changes]
|
26
|
-
test_case.assert_not_equal @before_groupname, current_groupname, "Group is still '#{@before_groupname}'"
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def after?
|
31
|
-
to_groupname || @options[:changes]
|
32
|
-
end
|
33
|
-
|
34
|
-
def describe_should_at(event)
|
35
|
-
case event
|
36
|
-
when :before
|
37
|
-
if from_groupname
|
38
|
-
"change group of file at `#{@path}` from '#{from_groupname}'"
|
39
|
-
elsif @options[:changes]
|
40
|
-
"not have a file at `#{@path}` with group '#{to_groupname}'"
|
41
|
-
end
|
42
|
-
when :after
|
43
|
-
if to_groupname
|
44
|
-
"have changed group of file at `#{@path}` to '#{to_groupname}'"
|
45
|
-
elsif @options[:changes]
|
46
|
-
"have changed group of file at `#{@path}`"
|
47
|
-
end
|
48
|
-
else
|
49
|
-
super
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
def current_groupname
|
54
|
-
normalize(File.stat(@path).gid)
|
55
|
-
end
|
56
|
-
|
57
|
-
def from_groupname
|
58
|
-
if @options[:from]
|
59
|
-
@from_groupname ||= normalize(@options[:from])
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
def to_groupname
|
64
|
-
if @options[:to]
|
65
|
-
@to_groupname ||= normalize(@options[:to])
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
def normalize(gid_or_groupname)
|
70
|
-
case gid_or_groupname
|
71
|
-
when String, Symbol
|
72
|
-
gid_or_groupname.to_s
|
73
|
-
when Fixnum
|
74
|
-
Etc.getgrgid(gid_or_groupname).name
|
75
|
-
else
|
76
|
-
raise ArgumentError, "Does not appear to be a gid or group name: #{gid_or_groupname}"
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
end
|
81
|
-
end
|
@@ -1,56 +0,0 @@
|
|
1
|
-
module Spex
|
2
|
-
class ChmodsFileAssertion < FileAssertion
|
3
|
-
assertion :chmods_file
|
4
|
-
|
5
|
-
def before(test_case)
|
6
|
-
if @options[:from]
|
7
|
-
test_case.assert File.exist?(@path), "File does not exist at #{@path}"
|
8
|
-
test_case.assert_equal @options[:from].to_s(8), current_mode.to_s(8)
|
9
|
-
elsif @options[:changes]
|
10
|
-
test_case.assert_not_equal @options[:to].to_s(8), current_mode.to_s(8), "Mode will not be changed; already at mode #{@options[:to].to_s(8)}"
|
11
|
-
end
|
12
|
-
@before_mode = current_mode
|
13
|
-
end
|
14
|
-
|
15
|
-
def before?
|
16
|
-
@options[:from] || @options[:changes]
|
17
|
-
end
|
18
|
-
|
19
|
-
def after(test_case)
|
20
|
-
if @options[:to]
|
21
|
-
test_case.assert File.exist?(@path), "File does not exist at #{@path}"
|
22
|
-
test_case.assert_equal @options[:to].to_s(8), current_mode.to_s(8)
|
23
|
-
elsif @options[:changes]
|
24
|
-
test_case.assert_not_equal @before_mode.to_s(8), current_mode.to_s(8), "Mode is still #{@before_mode.to_s(8)}"
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def after?
|
29
|
-
@options[:to] || @options[:changes]
|
30
|
-
end
|
31
|
-
|
32
|
-
def describe_should_at(event)
|
33
|
-
case event
|
34
|
-
when :before
|
35
|
-
if @options[:from]
|
36
|
-
"change mode of file at `#{@path}` from #{@options[:from].to_s(8)}"
|
37
|
-
elsif @options[:changes]
|
38
|
-
"not have a file at `#{@path}` with a mode of #{@options[:to].to_s(8)}"
|
39
|
-
end
|
40
|
-
when :after
|
41
|
-
if @options[:to]
|
42
|
-
"change mode of file at `#{@path}` to #{@options[:to].to_s(8)}"
|
43
|
-
elsif @options[:changes]
|
44
|
-
"change mode of file at `#{@path}`"
|
45
|
-
end
|
46
|
-
else
|
47
|
-
super
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def current_mode
|
52
|
-
Integer(File.stat(@path).mode.to_s(8)[1..-1])
|
53
|
-
end
|
54
|
-
|
55
|
-
end
|
56
|
-
end
|
@@ -1,81 +0,0 @@
|
|
1
|
-
require 'etc'
|
2
|
-
|
3
|
-
module Spex
|
4
|
-
class ChownsFileAssertion < FileAssertion
|
5
|
-
assertion :chowns_file
|
6
|
-
|
7
|
-
def before(test_case)
|
8
|
-
if from_username
|
9
|
-
test_case.assert File.exist?(@path), "File does not exist at #{@path}"
|
10
|
-
test_case.assert_equal from_username, current_username
|
11
|
-
elsif @options[:changes]
|
12
|
-
test_case.assert_not_equal to_username, current_username, "Owner will not be changed; already '#{to_username}'"
|
13
|
-
end
|
14
|
-
@before_username = current_username
|
15
|
-
end
|
16
|
-
|
17
|
-
def before?
|
18
|
-
from_username || @options[:changes]
|
19
|
-
end
|
20
|
-
|
21
|
-
def after(test_case)
|
22
|
-
if to_username
|
23
|
-
test_case.assert File.exist?(@path), "File does not exist at #{@path}"
|
24
|
-
test_case.assert_equal to_username, current_username
|
25
|
-
elsif @options[:changes]
|
26
|
-
test_case.assert_not_equal @before_username, current_username, "Owner is still '#{@before_username}'"
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def after?
|
31
|
-
to_username || @options[:changes]
|
32
|
-
end
|
33
|
-
|
34
|
-
def describe_should_at(event)
|
35
|
-
case event
|
36
|
-
when :before
|
37
|
-
if from_username
|
38
|
-
"change owner of file at `#{@path}` from '#{from_username}'"
|
39
|
-
elsif @options[:changes]
|
40
|
-
"not have a file at `#{@path}` with owner '#{to_username}'"
|
41
|
-
end
|
42
|
-
when :after
|
43
|
-
if to_username
|
44
|
-
"have changed owner of file at `#{@path}` to '#{to_username}'"
|
45
|
-
elsif @options[:changes]
|
46
|
-
"have changed owner of file at `#{@path}`"
|
47
|
-
end
|
48
|
-
else
|
49
|
-
super
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
def current_username
|
54
|
-
normalize(File.stat(@path).uid)
|
55
|
-
end
|
56
|
-
|
57
|
-
def from_username
|
58
|
-
if @options[:from]
|
59
|
-
@from_username ||= normalize(@options[:from])
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
def to_username
|
64
|
-
if @options[:to]
|
65
|
-
@to_username ||= normalize(@options[:to])
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
def normalize(uid_or_username)
|
70
|
-
case uid_or_username
|
71
|
-
when String, Symbol
|
72
|
-
uid_or_username.to_s
|
73
|
-
when Fixnum
|
74
|
-
Etc.getpwuid(uid_or_username).name
|
75
|
-
else
|
76
|
-
raise ArgumentError, "Does not appear to be a uid or username: #{uid_or_username}"
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
end
|
81
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
module Spex
|
2
|
-
class CreatesFileAssertion < FileAssertion
|
3
|
-
assertion :creates_file
|
4
|
-
|
5
|
-
def before(test_case)
|
6
|
-
test_case.assert !File.exist?(@path), "File already exists at #{@path}"
|
7
|
-
end
|
8
|
-
|
9
|
-
def after(test_case)
|
10
|
-
test_case.assert File.exist?(@path), "File was not created at #{@path}"
|
11
|
-
case kind
|
12
|
-
when :file
|
13
|
-
test_case.assert File.file?(@path), "File created at #{@path} is not a regular file"
|
14
|
-
when :directory
|
15
|
-
test_case.assert File.file?(@path), "File created at #{@path} is not a directory"
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def describe_should_at(event)
|
20
|
-
case event
|
21
|
-
when :before
|
22
|
-
"not find #{kind_name} at `#{@path}`"
|
23
|
-
when :after
|
24
|
-
"have created #{kind_name} at `#{@path}`"
|
25
|
-
else
|
26
|
-
super
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
31
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
module Spex
|
2
|
-
class RemovesFileAssertion < FileAssertion
|
3
|
-
assertion :removes_file
|
4
|
-
|
5
|
-
def after(test_case)
|
6
|
-
test_case.assert !File.exist?(@path), "File still exists at #{@path}"
|
7
|
-
end
|
8
|
-
|
9
|
-
def before(test_case)
|
10
|
-
test_case.assert File.exist?(@path), "File does not exist at #{@path}"
|
11
|
-
case kind
|
12
|
-
when :file
|
13
|
-
test_case.assert File.file?(@path), "File to remove at #{@path} is not a regular file"
|
14
|
-
when :directory
|
15
|
-
test_case.assert File.file?(@path), "File to remove at #{@path} is not a directory"
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def describe_should_at(event)
|
20
|
-
case event
|
21
|
-
when :after
|
22
|
-
"have removed #{kind_name} at `#{@path}`"
|
23
|
-
when :before
|
24
|
-
"find #{kind_name} at `#{@path}` to remove"
|
25
|
-
else
|
26
|
-
super
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
31
|
-
end
|
data/lib/spex/script/builder.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
module Spex
|
2
|
-
class Script::Language
|
3
|
-
|
4
|
-
def initialize(script)
|
5
|
-
@script = script
|
6
|
-
end
|
7
|
-
|
8
|
-
def doing(name, description, &block)
|
9
|
-
scenario = Scenario.new(name, description)
|
10
|
-
Scenario::Builder.new(scenario, &block)
|
11
|
-
@script << scenario
|
12
|
-
end
|
13
|
-
|
14
|
-
end
|
15
|
-
end
|