Bacon_FS_Matchers 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Bacon_FS_Matchers.gemspec +2 -2
- data/VERSION +1 -1
- data/lib/Bacon_FS_Matchers.rb +42 -39
- data/spec/tests/a_directory.rb +3 -6
- data/spec/tests/a_file.rb +3 -6
- data/spec/tests/a_file_containing.rb +3 -6
- data/spec/tests/have_key.rb +2 -5
- data/spec/tests/have_permissions.rb +2 -5
- data/spec/tests/owned_and_in.rb +2 -5
- metadata +15 -15
data/Bacon_FS_Matchers.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{Bacon_FS_Matchers}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = [%q{da99}]
|
12
|
-
s.date = %q{2011-08-
|
12
|
+
s.date = %q{2011-08-24}
|
13
13
|
s.description = %q{Includes matchers: a_file, a_directory, etc.}
|
14
14
|
s.email = %q{i-hate-spam-45671204@mailinator.com}
|
15
15
|
s.extra_rdoc_files = [
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/lib/Bacon_FS_Matchers.rb
CHANGED
@@ -1,5 +1,30 @@
|
|
1
1
|
require 'Shell_Helpers'
|
2
2
|
|
3
|
+
class Should
|
4
|
+
|
5
|
+
class Exposed
|
6
|
+
def initalize shoulda
|
7
|
+
@negated = shoulda.instance_variable_get(:@negated)
|
8
|
+
@object = shoulda.instance_variable_get(:@object)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
alias_method :be_not_array, :be
|
13
|
+
def be *raw_args, &blok
|
14
|
+
|
15
|
+
args = raw_args.flatten
|
16
|
+
|
17
|
+
if !block_given? && args.size == 2 && args.first.is_a?(Proc) && args.last.is_a?(Proc)
|
18
|
+
desc = args.first.call(Exposed.new self)
|
19
|
+
blok = args.last
|
20
|
+
return be_not_array( desc, &blok )
|
21
|
+
end
|
22
|
+
|
23
|
+
be_not_array(*raw_args, &blok)
|
24
|
+
end
|
25
|
+
|
26
|
+
end # === class Should
|
27
|
+
|
3
28
|
class Bacon_FS_Matchers
|
4
29
|
|
5
30
|
module DSL
|
@@ -7,31 +32,21 @@ class Bacon_FS_Matchers
|
|
7
32
|
include Shell_Helpers::DSL
|
8
33
|
|
9
34
|
def have_key key
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
else
|
14
|
-
should.flunk "#{obj.inspect} is missing key: #{key.inspect}"
|
15
|
-
end
|
35
|
+
|
36
|
+
matcher = lambda { |obj|
|
37
|
+
obj.has_key?(key)
|
16
38
|
}
|
39
|
+
|
17
40
|
end
|
18
41
|
|
19
|
-
def
|
42
|
+
def file_containing msg, show_contents = false
|
20
43
|
lambda { |obj|
|
21
44
|
if not File.file?(obj)
|
22
45
|
should.flunk "Not a file: #{obj}"
|
23
46
|
end
|
24
47
|
|
25
48
|
contents = File.read(obj)
|
26
|
-
|
27
|
-
if contents[msg]
|
28
|
-
true
|
29
|
-
else
|
30
|
-
should.flunk "
|
31
|
-
Does not contain #{msg.inspect}: #{obj}
|
32
|
-
#{show_contents ? contents : ''}
|
33
|
-
".strip
|
34
|
-
end
|
49
|
+
!!contents[msg]
|
35
50
|
}
|
36
51
|
end
|
37
52
|
|
@@ -39,44 +54,32 @@ class Bacon_FS_Matchers
|
|
39
54
|
lambda { |obj|
|
40
55
|
actual = permissions(obj)[1,2]
|
41
56
|
desired = [ user, user ]
|
42
|
-
|
43
|
-
|
44
|
-
else
|
45
|
-
should.flunk "#{obj.inspect} owner/group: #{actual} Should be: #{desired.inspect}"
|
46
|
-
end
|
57
|
+
actual == desired
|
58
|
+
# should.flunk "#{obj.inspect} owner/group: #{actual} Should be: #{desired.inspect}"
|
47
59
|
}
|
48
60
|
end
|
49
61
|
|
50
62
|
def have_permissions str
|
51
63
|
lambda { |obj|
|
52
|
-
actual
|
64
|
+
actual = permissions(obj).first
|
53
65
|
desired = str
|
54
|
-
|
55
|
-
|
56
|
-
else
|
57
|
-
should.flunk "#{obj.inspect} permissions: #{actual} Should be: #{desired}"
|
58
|
-
end
|
66
|
+
actual == desired
|
67
|
+
# should.flunk "#{obj.inspect} permissions: #{actual} Should be: #{desired}"
|
59
68
|
|
60
69
|
}
|
61
70
|
end
|
62
71
|
|
63
|
-
def
|
72
|
+
def directory
|
64
73
|
lambda { |obj|
|
65
|
-
|
66
|
-
|
67
|
-
else
|
68
|
-
should.flunk "#{obj.inspect} is not a directory."
|
69
|
-
end
|
74
|
+
File.directory?(obj)
|
75
|
+
# should.flunk "#{obj.inspect} is not a directory."
|
70
76
|
}
|
71
77
|
end
|
72
78
|
|
73
|
-
def
|
79
|
+
def file
|
74
80
|
lambda { |obj|
|
75
|
-
|
76
|
-
|
77
|
-
else
|
78
|
-
should.flunk "#{obj.inspect} is not a file."
|
79
|
-
end
|
81
|
+
File.file?(obj)
|
82
|
+
# should.flunk "#{obj.inspect} is not a file."
|
80
83
|
}
|
81
84
|
end
|
82
85
|
|
data/spec/tests/a_directory.rb
CHANGED
@@ -4,15 +4,12 @@ describe ":a_directory" do
|
|
4
4
|
behaves_like 'box'
|
5
5
|
|
6
6
|
it 'must return true if directory exists' do
|
7
|
-
@bx.
|
7
|
+
@bx.directory.call(FOLDER).should.be == true
|
8
8
|
end
|
9
9
|
|
10
10
|
it 'must return false if directory is a file' do
|
11
|
-
|
12
|
-
|
13
|
-
}
|
14
|
-
.should.raise(Bacon::Error)
|
15
|
-
.message.should.match %r!#{FILE.inspect} is not a directory!
|
11
|
+
@bx.directory.call(FILE)
|
12
|
+
.should.be == false
|
16
13
|
end
|
17
14
|
|
18
15
|
end # === describe :a_directory
|
data/spec/tests/a_file.rb
CHANGED
@@ -5,15 +5,12 @@ describe ":a_file" do
|
|
5
5
|
behaves_like 'box'
|
6
6
|
|
7
7
|
it 'must return true if file exists' do
|
8
|
-
@bx.
|
8
|
+
@bx.file.call(FILE).should.be == true
|
9
9
|
end
|
10
10
|
|
11
11
|
it 'must return false if file is a directory' do
|
12
|
-
|
13
|
-
|
14
|
-
}
|
15
|
-
.should.raise(Bacon::Error)
|
16
|
-
.message.should.match %r!#{FOLDER.inspect} is not a file!
|
12
|
+
@bx.file.call(FOLDER)
|
13
|
+
.should.be == false
|
17
14
|
end
|
18
15
|
|
19
16
|
end # === describe :a_file
|
@@ -4,15 +4,12 @@ describe ":a_file_containing" do
|
|
4
4
|
behaves_like 'box'
|
5
5
|
|
6
6
|
it 'must return true if file contains the String.' do
|
7
|
-
@bx.
|
7
|
+
@bx.file_containing('dawn').call(FILE).should.be == true
|
8
8
|
end
|
9
9
|
|
10
10
|
it 'must return false if file does not contains the String.' do
|
11
|
-
|
12
|
-
|
13
|
-
}
|
14
|
-
.should.raise(Bacon::Error)
|
15
|
-
.message.should.match %r!Does not contain .Wallace!
|
11
|
+
@bx.file_containing('Wallace Thornhill').call(FILE)
|
12
|
+
.should.be == false
|
16
13
|
end
|
17
14
|
|
18
15
|
end # === describe :a_file_containing
|
data/spec/tests/have_key.rb
CHANGED
@@ -8,11 +8,8 @@ describe "have_key" do
|
|
8
8
|
end
|
9
9
|
|
10
10
|
it 'must return false if array has desired key' do
|
11
|
-
|
12
|
-
|
13
|
-
}
|
14
|
-
.should.raise(Bacon::Error)
|
15
|
-
.message.should.match %r!is missing key: .KEY!
|
11
|
+
@bx.have_key('KEY').call('GOZER'=>'master')
|
12
|
+
.should.be == false
|
16
13
|
end
|
17
14
|
|
18
15
|
end # === describe have_key
|
@@ -9,11 +9,8 @@ describe ":have_permissions" do
|
|
9
9
|
|
10
10
|
it 'must return false if file does not have the desired mode bits' do
|
11
11
|
target = 'drwxr--r--'
|
12
|
-
|
13
|
-
|
14
|
-
}
|
15
|
-
.should.raise(Bacon::Error)
|
16
|
-
.message.should.match %r!Should be: #{target}!
|
12
|
+
@bx.have_permissions(target).call(FILE)
|
13
|
+
.should.be == false
|
17
14
|
end
|
18
15
|
|
19
16
|
end # === describe :have_permissions
|
data/spec/tests/owned_and_in.rb
CHANGED
@@ -13,11 +13,8 @@ describe ":owned_and_in" do
|
|
13
13
|
|
14
14
|
it 'must return false if file is owned and in group of wrong user' do
|
15
15
|
target = ['root', 'root']
|
16
|
-
|
17
|
-
|
18
|
-
}
|
19
|
-
.should.raise(Bacon::Error)
|
20
|
-
.message.should.match %r!Should be: \[.root., .root.\]!
|
16
|
+
@bx.owned_and_in('root').call(FILE)
|
17
|
+
.should.be == false
|
21
18
|
end
|
22
19
|
|
23
20
|
end # === describe :owned_and_in
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: Bacon_FS_Matchers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-08-
|
12
|
+
date: 2011-08-24 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: Shell_Helpers
|
16
|
-
requirement: &
|
16
|
+
requirement: &11152900 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 0.3.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *11152900
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: bacon
|
27
|
-
requirement: &
|
27
|
+
requirement: &11151860 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *11151860
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: bundler
|
38
|
-
requirement: &
|
38
|
+
requirement: &11149000 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 1.0.0
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *11149000
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: jeweler
|
49
|
-
requirement: &
|
49
|
+
requirement: &11146680 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: 1.6.4
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *11146680
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: rcov
|
60
|
-
requirement: &
|
60
|
+
requirement: &11144600 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *11144600
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: Gem_Raker_da99
|
71
|
-
requirement: &
|
71
|
+
requirement: &11143440 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,7 +76,7 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *11143440
|
80
80
|
description: ! 'Includes matchers: a_file, a_directory, etc.'
|
81
81
|
email: i-hate-spam-45671204@mailinator.com
|
82
82
|
executables: []
|
@@ -116,7 +116,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
116
116
|
version: '0'
|
117
117
|
segments:
|
118
118
|
- 0
|
119
|
-
hash:
|
119
|
+
hash: 3989566519328336101
|
120
120
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
121
121
|
none: false
|
122
122
|
requirements:
|