Bacon_FS_Matchers 0.1.1

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 ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
@@ -0,0 +1,70 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{Bacon_FS_Matchers}
8
+ s.version = "0.1.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = [%q{da99}]
12
+ s.date = %q{2011-08-17}
13
+ s.description = %q{Includes matchers: a_file, a_directory, etc.}
14
+ s.email = %q{i-hate-spam-45671204@mailinator.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ "Bacon_FS_Matchers.gemspec",
22
+ "Gemfile",
23
+ "LICENSE.txt",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "lib/Bacon_FS_Matchers.rb",
28
+ "spec/main.rb",
29
+ "spec/spec_helper.rb",
30
+ "spec/tests/a_directory.rb",
31
+ "spec/tests/a_file.rb",
32
+ "spec/tests/a_file_containing.rb",
33
+ "spec/tests/have_key.rb",
34
+ "spec/tests/have_permissions.rb",
35
+ "spec/tests/owned_and_in.rb"
36
+ ]
37
+ s.homepage = %q{http://github.com/da01/Bacon_FS_Matchers}
38
+ s.licenses = [%q{MIT}]
39
+ s.require_paths = [%q{lib}]
40
+ s.rubygems_version = %q{1.8.8}
41
+ s.summary = %q{Custom matchers for Bacon when dealing with the file system.}
42
+
43
+ if s.respond_to? :specification_version then
44
+ s.specification_version = 3
45
+
46
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
47
+ s.add_runtime_dependency(%q<Shell_Helpers>, [">= 0"])
48
+ s.add_development_dependency(%q<bacon>, [">= 0"])
49
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
50
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
51
+ s.add_development_dependency(%q<rcov>, [">= 0"])
52
+ s.add_development_dependency(%q<Gem_Raker_da99>, [">= 0"])
53
+ else
54
+ s.add_dependency(%q<Shell_Helpers>, [">= 0"])
55
+ s.add_dependency(%q<bacon>, [">= 0"])
56
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
57
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
58
+ s.add_dependency(%q<rcov>, [">= 0"])
59
+ s.add_dependency(%q<Gem_Raker_da99>, [">= 0"])
60
+ end
61
+ else
62
+ s.add_dependency(%q<Shell_Helpers>, [">= 0"])
63
+ s.add_dependency(%q<bacon>, [">= 0"])
64
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
65
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
66
+ s.add_dependency(%q<rcov>, [">= 0"])
67
+ s.add_dependency(%q<Gem_Raker_da99>, [">= 0"])
68
+ end
69
+ end
70
+
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+ gem "Shell_Helpers"
6
+
7
+ # Add dependencies to develop your gem here.
8
+ # Include everything needed to run rake, tests, features, etc.
9
+ group :development do
10
+ gem "bacon", ">= 0"
11
+ gem "bundler", "~> 1.0.0"
12
+ gem "jeweler", "~> 1.6.4"
13
+ gem "rcov", ">= 0"
14
+ gem "Gem_Raker_da99"
15
+ end
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,40 @@
1
+ = Bacon_FS_Matchers
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_Matchers', :git => 'git://gitorious.org/da99_ruby_gems/bacon_fs_matchers.git'
11
+ =end
12
+
13
+ == Usage:
14
+
15
+ = begin rdoc
16
+ require 'Bacon_FS_Matchers'
17
+ include Bacon_FS_Matchers::DSL
18
+
19
+ describe 'My home files.' do
20
+
21
+ it 'should be a file' do
22
+ "~/.bashrc".should.be a_file
23
+ end
24
+
25
+ it 'should be a directory' do
26
+ "~/.ssh".should.be a_directory
27
+ end
28
+
29
+ end
30
+
31
+ =end
32
+
33
+
34
+
35
+ == Copyright
36
+
37
+ Copyright (c) 2011 da99. See LICENSE.txt for
38
+ further details.
39
+
40
+
data/Rakefile ADDED
@@ -0,0 +1,57 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "Bacon_FS_Matchers"
18
+ gem.homepage = "http://github.com/da01/Bacon_FS_Matchers"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Custom matchers for Bacon when dealing with the file system.}
21
+ gem.description = %Q{Includes matchers: a_file, a_directory, etc.}
22
+ gem.email = "i-hate-spam-45671204@mailinator.com"
23
+ gem.authors = ["da99"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new(:spec) do |spec|
30
+ spec.libs << 'lib' << 'spec'
31
+ spec.pattern = 'spec/**/*_spec.rb'
32
+ spec.verbose = true
33
+ end
34
+
35
+ # require 'rcov/rcovtask'
36
+ # Rcov::RcovTask.new do |spec|
37
+ # spec.libs << 'spec'
38
+ # spec.pattern = 'spec/**/*_spec.rb'
39
+ # spec.verbose = true
40
+ # spec.rcov_opts << '--exclude "gems/*"'
41
+ # end
42
+
43
+ task :default => :spec
44
+
45
+ require 'rake/rdoctask'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "Bacon_FS_Matchers #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
54
+
55
+ require 'Gem_Raker_da99/tasks'
56
+ Gem_Raker_da99::Tasks.new
57
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.1
@@ -0,0 +1,86 @@
1
+ require 'Shell_Helpers'
2
+
3
+ class Bacon_FS_Matchers
4
+
5
+ module DSL
6
+
7
+ include Shell_Helpers::DSL
8
+
9
+ 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
16
+ }
17
+ end
18
+
19
+ def a_file_containing msg, show_contents = false
20
+ lambda { |obj|
21
+ if not File.file?(obj)
22
+ should.flunk "Not a file: #{obj}"
23
+ end
24
+
25
+ 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
35
+ }
36
+ end
37
+
38
+ def owned_and_in( user )
39
+ lambda { |obj|
40
+ actual = permissions(obj).split[1,2]
41
+ 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
47
+ }
48
+ end
49
+
50
+ def have_permissions str
51
+ lambda { |obj|
52
+ actual = permissions(obj).split.first
53
+ desired = str
54
+ if actual == desired
55
+ true
56
+ else
57
+ should.flunk "#{obj.inspect} permissions: #{actual} Should be: #{desired}"
58
+ end
59
+
60
+ }
61
+ end
62
+
63
+ def a_directory
64
+ lambda { |obj|
65
+ if File.directory?(obj)
66
+ true
67
+ else
68
+ should.flunk "#{obj.inspect} is not a directory."
69
+ end
70
+ }
71
+ end
72
+
73
+ def a_file
74
+ lambda { |obj|
75
+ if File.file?(obj)
76
+ true
77
+ else
78
+ should.flunk "#{obj.inspect} is not a file."
79
+ end
80
+ }
81
+ end
82
+
83
+
84
+ end # === module
85
+
86
+ end # === class
data/spec/main.rb ADDED
@@ -0,0 +1,31 @@
1
+ require File.expand_path('spec/spec_helper')
2
+ require 'Bacon_FS_Matchers'
3
+
4
+ FOLDER = "/tmp/BACON_FS_MATCHERS"
5
+ %x! mkdir -p #{FOLDER} !
6
+
7
+ FILE = "#{FOLDER}/story.txt"
8
+
9
+ %x! echo "I awoke to dawn." > #{FILE}!
10
+
11
+ at_exit {
12
+ %x! rm -rf #{FOLDER} !
13
+ }
14
+
15
+ class Box
16
+ include Bacon_FS_Matchers::DSL
17
+ end # === class
18
+
19
+ shared 'box' do
20
+
21
+ before do
22
+ @bx = Box.new
23
+ end
24
+
25
+ end # === shared
26
+
27
+ Dir.glob('spec/tests/*.rb').each { |file|
28
+ ruby_file = file.sub(%r!\.rb!, '')
29
+ require File.expand_path(ruby_file)
30
+ }
31
+
@@ -0,0 +1,16 @@
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
+ require 'Bacon_FS_Matchers'
15
+
16
+ Bacon.summary_on_exit
@@ -0,0 +1,18 @@
1
+
2
+ describe ":a_directory" do
3
+
4
+ behaves_like 'box'
5
+
6
+ it 'must return true if directory exists' do
7
+ @bx.a_directory.call(FOLDER).should.be == true
8
+ end
9
+
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!
16
+ end
17
+
18
+ end # === describe :a_directory
@@ -0,0 +1,19 @@
1
+
2
+
3
+ describe ":a_file" do
4
+
5
+ behaves_like 'box'
6
+
7
+ it 'must return true if file exists' do
8
+ @bx.a_file.call(FILE).should.be == true
9
+ end
10
+
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!
17
+ end
18
+
19
+ end # === describe :a_file
@@ -0,0 +1,18 @@
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.a_file_containing('dawn').call(FILE).should.be == true
8
+ end
9
+
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!
16
+ end
17
+
18
+ end # === describe :a_file_containing
@@ -0,0 +1,18 @@
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').should.be == true
8
+ end
9
+
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!
16
+ end
17
+
18
+ end # === describe have_key
@@ -0,0 +1,19 @@
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).should.be == true
8
+ end
9
+
10
+ it 'must return false if file does not have the desired mode bits' do
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}!
17
+ end
18
+
19
+ end # === describe :have_permissions
@@ -0,0 +1,23 @@
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).should.be == true
12
+ end
13
+
14
+ it 'must return false if file is owned and in group of wrong user' do
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.\]!
21
+ end
22
+
23
+ end # === describe :owned_and_in
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: Bacon_FS_Matchers
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - da99
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-08-17 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: Shell_Helpers
16
+ requirement: &21021420 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *21021420
25
+ - !ruby/object:Gem::Dependency
26
+ name: bacon
27
+ requirement: &21019840 !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: *21019840
36
+ - !ruby/object:Gem::Dependency
37
+ name: bundler
38
+ requirement: &21017600 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: 1.0.0
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *21017600
47
+ - !ruby/object:Gem::Dependency
48
+ name: jeweler
49
+ requirement: &21012800 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 1.6.4
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *21012800
58
+ - !ruby/object:Gem::Dependency
59
+ name: rcov
60
+ requirement: &21010920 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *21010920
69
+ - !ruby/object:Gem::Dependency
70
+ name: Gem_Raker_da99
71
+ requirement: &21009160 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *21009160
80
+ description: ! 'Includes matchers: a_file, a_directory, etc.'
81
+ email: i-hate-spam-45671204@mailinator.com
82
+ executables: []
83
+ extensions: []
84
+ extra_rdoc_files:
85
+ - LICENSE.txt
86
+ - README.rdoc
87
+ files:
88
+ - .document
89
+ - Bacon_FS_Matchers.gemspec
90
+ - Gemfile
91
+ - LICENSE.txt
92
+ - README.rdoc
93
+ - Rakefile
94
+ - VERSION
95
+ - lib/Bacon_FS_Matchers.rb
96
+ - spec/main.rb
97
+ - spec/spec_helper.rb
98
+ - spec/tests/a_directory.rb
99
+ - spec/tests/a_file.rb
100
+ - spec/tests/a_file_containing.rb
101
+ - spec/tests/have_key.rb
102
+ - spec/tests/have_permissions.rb
103
+ - spec/tests/owned_and_in.rb
104
+ homepage: http://github.com/da01/Bacon_FS_Matchers
105
+ licenses:
106
+ - MIT
107
+ post_install_message:
108
+ rdoc_options: []
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ none: false
113
+ requirements:
114
+ - - ! '>='
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ segments:
118
+ - 0
119
+ hash: -3029710945020247774
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ requirements: []
127
+ rubyforge_project:
128
+ rubygems_version: 1.8.8
129
+ signing_key:
130
+ specification_version: 3
131
+ summary: Custom matchers for Bacon when dealing with the file system.
132
+ test_files: []