Bacon_FS 0.1.0
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.
- data/.document +5 -0
- data/.gitignore +4 -0
- data/Bacon_FS.gemspec +30 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +43 -0
- data/Rakefile +1 -0
- data/lib/Bacon_FS.rb +99 -0
- data/lib/Bacon_FS/version.rb +3 -0
- data/spec/helper.rb +15 -0
- data/spec/main.rb +31 -0
- data/spec/tests/directory.rb +16 -0
- data/spec/tests/file.rb +17 -0
- data/spec/tests/file_containing.rb +16 -0
- data/spec/tests/have_key.rb +16 -0
- data/spec/tests/have_permissions.rb +17 -0
- data/spec/tests/owned_and_in.rb +21 -0
- metadata +85 -0
data/.document
ADDED
data/.gitignore
ADDED
data/Bacon_FS.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "Bacon_FS/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "Bacon_FS"
|
7
|
+
s.version = Bacon_FS::VERSION
|
8
|
+
s.authors = ["da99"]
|
9
|
+
s.email = ["i-hate-spam-45671204@mailinator.com"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{Matches for Bacon related to the file system.}
|
12
|
+
s.description = %q{
|
13
|
+
Matches for Bacon related to the file system.
|
14
|
+
|
15
|
+
"~/.bashrc".should.be file
|
16
|
+
}
|
17
|
+
|
18
|
+
s.rubyforge_project = "Bacon_FS"
|
19
|
+
|
20
|
+
s.files = `git ls-files`.split("\n")
|
21
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
22
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
23
|
+
s.add_development_dependency 'bacon'
|
24
|
+
s.add_development_dependency 'rake'
|
25
|
+
s.require_paths = ["lib"]
|
26
|
+
|
27
|
+
# specify any dependencies here; for example:
|
28
|
+
# s.add_development_dependency "rspec"
|
29
|
+
# s.add_runtime_dependency "rest-client"
|
30
|
+
end
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 da99
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
= Bacon_FS
|
2
|
+
|
3
|
+
Matchers for Bacon, https://github.com/chneukirchen/bacon/, when interacting with files.
|
4
|
+
|
5
|
+
== Install
|
6
|
+
|
7
|
+
In your Gemfile:
|
8
|
+
|
9
|
+
= begin rdoc
|
10
|
+
gem 'Bacon_FS'
|
11
|
+
=end
|
12
|
+
|
13
|
+
== Usage:
|
14
|
+
|
15
|
+
= begin rdoc
|
16
|
+
require 'Bacon_FS'
|
17
|
+
|
18
|
+
describe 'My home files.' do
|
19
|
+
|
20
|
+
before {
|
21
|
+
include Bacon_FS::DSL
|
22
|
+
}
|
23
|
+
|
24
|
+
it 'should be a file' do
|
25
|
+
"~/.bashrc".should.be.a file
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should be a directory' do
|
29
|
+
"~/.ssh".should.be.a directory
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
=end
|
35
|
+
|
36
|
+
|
37
|
+
|
38
|
+
== Copyright
|
39
|
+
|
40
|
+
Copyright (c) 2011 da99. See LICENSE.txt for
|
41
|
+
further details.
|
42
|
+
|
43
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/Bacon_FS.rb
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
require "Bacon_FS/version"
|
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
|
+
|
28
|
+
module Bacon_FS
|
29
|
+
|
30
|
+
module DSL
|
31
|
+
|
32
|
+
# Returns: Permissions_Array: %w! drwxr-xr-x user group !
|
33
|
+
def permissions raw_path
|
34
|
+
path = File.expand_path(raw_path)
|
35
|
+
dir = File.dirname(path.strip)
|
36
|
+
base_name = File.basename(path)
|
37
|
+
pattern = %r!\d+:\d+\s#{base_name}(\s|$)!
|
38
|
+
raise "Invalid character in path: #{dir}" if dir[/\s/]
|
39
|
+
|
40
|
+
results = %x! ls -al #{dir} !.split("\n").grep(pattern)
|
41
|
+
|
42
|
+
raise "Too many ls listings for #{raw_path}: #{results.inspect}" if results.size > 1
|
43
|
+
raise "No ls listings for #{raw_path}: #{results.inspect}" if results.size != 1
|
44
|
+
|
45
|
+
pieces = results.first.split
|
46
|
+
[ pieces[0], pieces[2], pieces[3] ]
|
47
|
+
end
|
48
|
+
|
49
|
+
def have_key key
|
50
|
+
|
51
|
+
matcher = lambda { |obj|
|
52
|
+
obj.has_key?(key)
|
53
|
+
}
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
def file_containing msg, show_contents = false
|
58
|
+
lambda { |obj|
|
59
|
+
if not File.file?(obj)
|
60
|
+
should.flunk "Not a file: #{obj}"
|
61
|
+
end
|
62
|
+
|
63
|
+
contents = File.read(obj)
|
64
|
+
!!contents[msg]
|
65
|
+
}
|
66
|
+
end
|
67
|
+
|
68
|
+
def owned_and_in( user )
|
69
|
+
lambda { |obj|
|
70
|
+
actual = permissions(obj)[1,2]
|
71
|
+
desired = [ user, user ]
|
72
|
+
actual == desired
|
73
|
+
}
|
74
|
+
end
|
75
|
+
|
76
|
+
def have_permissions str
|
77
|
+
lambda { |obj|
|
78
|
+
actual = permissions(obj).first
|
79
|
+
desired = str
|
80
|
+
actual == desired
|
81
|
+
}
|
82
|
+
end
|
83
|
+
|
84
|
+
def directory
|
85
|
+
lambda { |obj|
|
86
|
+
File.directory?(obj)
|
87
|
+
}
|
88
|
+
end
|
89
|
+
|
90
|
+
def file
|
91
|
+
lambda { |obj|
|
92
|
+
File.file?(obj)
|
93
|
+
}
|
94
|
+
end
|
95
|
+
|
96
|
+
|
97
|
+
end # === module
|
98
|
+
|
99
|
+
end # === class
|
data/spec/helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'bacon'
|
11
|
+
|
12
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
13
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
14
|
+
|
15
|
+
Bacon.summary_on_exit
|
data/spec/main.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
|
2
|
+
require File.expand_path('spec/helper')
|
3
|
+
require 'Bacon_FS'
|
4
|
+
|
5
|
+
FOLDER = "/tmp/BACON_FS"
|
6
|
+
%x! mkdir -p #{FOLDER} !
|
7
|
+
|
8
|
+
FILE = "#{FOLDER}/story.txt"
|
9
|
+
|
10
|
+
%x! echo "I awoke to dawn." > #{FILE}!
|
11
|
+
|
12
|
+
at_exit {
|
13
|
+
%x! rm -rf #{FOLDER} !
|
14
|
+
}
|
15
|
+
|
16
|
+
class Box
|
17
|
+
include Bacon_FS::DSL
|
18
|
+
end # === class
|
19
|
+
|
20
|
+
shared 'box' do
|
21
|
+
|
22
|
+
before do
|
23
|
+
@bx = Box.new
|
24
|
+
end
|
25
|
+
|
26
|
+
end # === shared
|
27
|
+
|
28
|
+
|
29
|
+
Dir.glob('spec/tests/*.rb').each { |file|
|
30
|
+
require File.expand_path(file.sub('.rb', '')) if File.file?(file)
|
31
|
+
}
|
@@ -0,0 +1,16 @@
|
|
1
|
+
|
2
|
+
describe ":directory" do
|
3
|
+
|
4
|
+
behaves_like 'box'
|
5
|
+
|
6
|
+
it 'must return true if directory exists' do
|
7
|
+
@bx.directory.call(FOLDER)
|
8
|
+
.should.be == true
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'must return false if directory is a file' do
|
12
|
+
@bx.directory.call(FILE)
|
13
|
+
.should.be == false
|
14
|
+
end
|
15
|
+
|
16
|
+
end # === describe :a_directory
|
data/spec/tests/file.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
describe ":a_file" do
|
4
|
+
|
5
|
+
behaves_like 'box'
|
6
|
+
|
7
|
+
it 'must return true if file exists' do
|
8
|
+
@bx.file.call(FILE)
|
9
|
+
.should.be == true
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'must return false if file is a directory' do
|
13
|
+
@bx.file.call(FOLDER)
|
14
|
+
.should.be == false
|
15
|
+
end
|
16
|
+
|
17
|
+
end # === describe :a_file
|
@@ -0,0 +1,16 @@
|
|
1
|
+
|
2
|
+
describe ":a_file_containing" do
|
3
|
+
|
4
|
+
behaves_like 'box'
|
5
|
+
|
6
|
+
it 'must return true if file contains the String.' do
|
7
|
+
@bx.file_containing('dawn').call(FILE)
|
8
|
+
.should.be == true
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'must return false if file does not contains the String.' do
|
12
|
+
@bx.file_containing('Wallace Thornhill').call(FILE)
|
13
|
+
.should.be == false
|
14
|
+
end
|
15
|
+
|
16
|
+
end # === describe :a_file_containing
|
@@ -0,0 +1,16 @@
|
|
1
|
+
|
2
|
+
describe "have_key" do
|
3
|
+
|
4
|
+
behaves_like 'box'
|
5
|
+
|
6
|
+
it 'must return true if array has desired key' do
|
7
|
+
@bx.have_key('KEY').call('KEY'=>'master')
|
8
|
+
.should.be == true
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'must return false if array has desired key' do
|
12
|
+
@bx.have_key('KEY').call('GOZER'=>'master')
|
13
|
+
.should.be == false
|
14
|
+
end
|
15
|
+
|
16
|
+
end # === describe have_key
|
@@ -0,0 +1,17 @@
|
|
1
|
+
|
2
|
+
describe ":have_permissions" do
|
3
|
+
|
4
|
+
behaves_like 'box'
|
5
|
+
|
6
|
+
it 'must return true if file has the desired mode bits' do
|
7
|
+
@bx.have_permissions('-rw-r--r--').call(FILE)
|
8
|
+
.should.be == true
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'must return false if file does not have the desired mode bits' do
|
12
|
+
target = 'drwxr--r--'
|
13
|
+
@bx.have_permissions(target).call(FILE)
|
14
|
+
.should.be == false
|
15
|
+
end
|
16
|
+
|
17
|
+
end # === describe :have_permissions
|
@@ -0,0 +1,21 @@
|
|
1
|
+
|
2
|
+
describe ":owned_and_in" do
|
3
|
+
|
4
|
+
behaves_like 'box'
|
5
|
+
|
6
|
+
before do
|
7
|
+
@user = %x!whoami!.strip
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'must return true if file is owned and in group of user' do
|
11
|
+
@bx.owned_and_in(@user).call(FILE)
|
12
|
+
.should.be == true
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'must return false if file is owned and in group of wrong user' do
|
16
|
+
target = ['root', 'root']
|
17
|
+
@bx.owned_and_in('root').call(FILE)
|
18
|
+
.should.be == false
|
19
|
+
end
|
20
|
+
|
21
|
+
end # === describe :owned_and_in
|
metadata
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: Bacon_FS
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- da99
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-10-13 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bacon
|
16
|
+
requirement: &12075980 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *12075980
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rake
|
27
|
+
requirement: &12075340 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *12075340
|
36
|
+
description: ! "\n Matches for Bacon related to the file system.\n \n \"~/.bashrc\".should.be
|
37
|
+
file\n "
|
38
|
+
email:
|
39
|
+
- i-hate-spam-45671204@mailinator.com
|
40
|
+
executables: []
|
41
|
+
extensions: []
|
42
|
+
extra_rdoc_files: []
|
43
|
+
files:
|
44
|
+
- .document
|
45
|
+
- .gitignore
|
46
|
+
- Bacon_FS.gemspec
|
47
|
+
- Gemfile
|
48
|
+
- LICENSE.txt
|
49
|
+
- README.rdoc
|
50
|
+
- Rakefile
|
51
|
+
- lib/Bacon_FS.rb
|
52
|
+
- lib/Bacon_FS/version.rb
|
53
|
+
- spec/helper.rb
|
54
|
+
- spec/main.rb
|
55
|
+
- spec/tests/directory.rb
|
56
|
+
- spec/tests/file.rb
|
57
|
+
- spec/tests/file_containing.rb
|
58
|
+
- spec/tests/have_key.rb
|
59
|
+
- spec/tests/have_permissions.rb
|
60
|
+
- spec/tests/owned_and_in.rb
|
61
|
+
homepage: ''
|
62
|
+
licenses: []
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options: []
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ! '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ! '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
requirements: []
|
80
|
+
rubyforge_project: Bacon_FS
|
81
|
+
rubygems_version: 1.8.11
|
82
|
+
signing_key:
|
83
|
+
specification_version: 3
|
84
|
+
summary: Matches for Bacon related to the file system.
|
85
|
+
test_files: []
|