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.
@@ -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.1.2"
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-22}
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.2
1
+ 0.2.0
@@ -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
- lambda { |obj|
11
- if obj.has_key?(key)
12
- true
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 a_file_containing msg, show_contents = false
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
- if actual == desired
43
- true
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 = permissions(obj).first
64
+ actual = permissions(obj).first
53
65
  desired = str
54
- if actual == desired
55
- true
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 a_directory
72
+ def directory
64
73
  lambda { |obj|
65
- if File.directory?(obj)
66
- true
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 a_file
79
+ def file
74
80
  lambda { |obj|
75
- if File.file?(obj)
76
- true
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
 
@@ -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.a_directory.call(FOLDER).should.be == true
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
- lambda {
12
- @bx.a_directory.call(FILE)
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.a_file.call(FILE).should.be == true
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
- lambda {
13
- @bx.a_file.call(FOLDER)
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.a_file_containing('dawn').call(FILE).should.be == true
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
- lambda {
12
- @bx.a_file_containing('Wallace Thornhill').call(FILE)
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
@@ -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
- lambda {
12
- @bx.have_key('KEY').call('GOZER'=>'master')
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
- lambda {
13
- @bx.have_permissions(target).call(FILE)
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
@@ -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
- lambda {
17
- @bx.owned_and_in('root').call(FILE)
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.1.2
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-22 00:00:00.000000000Z
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: &6029140 !ruby/object:Gem::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: *6029140
24
+ version_requirements: *11152900
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: bacon
27
- requirement: &6028020 !ruby/object:Gem::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: *6028020
35
+ version_requirements: *11151860
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: bundler
38
- requirement: &6026860 !ruby/object:Gem::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: *6026860
46
+ version_requirements: *11149000
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: jeweler
49
- requirement: &6025280 !ruby/object:Gem::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: *6025280
57
+ version_requirements: *11146680
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rcov
60
- requirement: &6023760 !ruby/object:Gem::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: *6023760
68
+ version_requirements: *11144600
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: Gem_Raker_da99
71
- requirement: &6022240 !ruby/object:Gem::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: *6022240
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: 3141586923638519899
119
+ hash: 3989566519328336101
120
120
  required_rubygems_version: !ruby/object:Gem::Requirement
121
121
  none: false
122
122
  requirements: