file-spec 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 ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --format nested --color
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Kristian Mandrup
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.markdown ADDED
@@ -0,0 +1,39 @@
1
+ # File spec
2
+
3
+ RSpec 2 matcher to specify expected file structures.
4
+
5
+ ## Usage
6
+
7
+ See /spec folder for usage examples.
8
+
9
+ ## TODO
10
+
11
+ Currently these do not check file type of target but are just alias of generic have_symlink.
12
+ This must be fixed!
13
+
14
+ * have_symlink_file sym_file
15
+ * have_symlink_dir sym_dir
16
+
17
+ * have_symlink_files sym_file1, sym_file2
18
+ * have_symlink_dirs sym_dir1, sym_dir2
19
+
20
+ ## TODO - advanced
21
+
22
+ * have_file_structure yaml
23
+
24
+ Should test that the files and dirs match the tree structure of the yaml string (or file).
25
+ This is very convenient for more complex file structure specs!
26
+
27
+ ## Note on Patches/Pull Requests
28
+
29
+ * Fork the project.
30
+ * Make your feature addition or bug fix.
31
+ * Add tests for it. This is important so I don't break it in a
32
+ future version unintentionally.
33
+ * Commit, do not mess with rakefile, version, or history.
34
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
35
+ * Send me a pull request. Bonus points for topic branches.
36
+
37
+ ## Copyright
38
+
39
+ Copyright (c) 2010 Kristian Mandrup. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,18 @@
1
+ begin
2
+ require 'jeweler'
3
+ Jeweler::Tasks.new do |gem|
4
+ gem.name = "file-spec"
5
+ gem.summary = 'RSpec 2 matchers for files, directories and symlinks'
6
+ gem.description = 'RSpec 2 matchers for files, directories and symlinks'
7
+ gem.email = "kmandrup@gmail.com"
8
+ gem.homepage = "http://github.com/kristianmandrup/file-spec"
9
+ gem.authors = ["Kristian Mandrup"]
10
+ gem.add_development_dependency "rspec", ">= 2.0.0.beta.19"
11
+ gem.add_dependency "require_all", ">= 1.1.0"
12
+ # gem.add_dependency "active_support", ">= 3.0.0.rc"
13
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
14
+ end
15
+ Jeweler::GemcutterTasks.new
16
+ rescue LoadError
17
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
18
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/lib/file-spec.rb ADDED
@@ -0,0 +1,16 @@
1
+ require 'rspec'
2
+ require 'require_all'
3
+ require 'fileutils'
4
+ require 'active_support/inflector'
5
+
6
+ module RSpec
7
+ module FileMatchers
8
+ end
9
+ end
10
+
11
+ require_all File.dirname(__FILE__) + '/file_spec/matchers/abstract'
12
+ require_all File.dirname(__FILE__) + '/file_spec/matchers'
13
+
14
+ RSpec.configure do |config|
15
+ config.include(RSpec::FileMatchers)
16
+ end
@@ -0,0 +1,131 @@
1
+ module FileHelper
2
+ def test_file
3
+ 'test.txt'
4
+ end
5
+
6
+ def test_files
7
+ [test_file, 'test2.txt']
8
+ end
9
+
10
+ def sym_test_file
11
+ 'sym-test.txt'
12
+ end
13
+
14
+ def sym_test_files
15
+ test_files.map{|f| "sym-#{f}" }
16
+ end
17
+
18
+ def test_dir
19
+ 'test'
20
+ end
21
+
22
+ def test_dirs
23
+ [test_dir, 'test2']
24
+ end
25
+
26
+ def sym_test_dir
27
+ 'sym-test'
28
+ end
29
+
30
+ def sym_test_dirs
31
+ [sym_test_dir, 'sym-test2']
32
+ end
33
+
34
+ def remove_all_test
35
+ remove_test_files
36
+ remove_test_dirs
37
+ remove_test_symlinks
38
+ remove_test_symlink_dirs
39
+ end
40
+
41
+ def make_test_file
42
+ make_file test_file
43
+ end
44
+
45
+ def make_test_files
46
+ test_files.each{|f| make_file f}
47
+ end
48
+
49
+ def make_file file
50
+ File.open(file, 'w') {|f| f.write "hello" }
51
+ end
52
+
53
+ def remove_file file
54
+ ::FileUtils.rm_f file
55
+ end
56
+
57
+ def remove_test_file
58
+ remove_file test_file
59
+ end
60
+
61
+ def remove_test_files
62
+ test_files.each{|f| remove_file f}
63
+ end
64
+
65
+ def make_dir dir
66
+ ::FileUtils.mkdir dir
67
+ end
68
+
69
+ def make_test_dir
70
+ make_dir test_dir
71
+ end
72
+
73
+ def make_test_dirs
74
+ test_dirs.each{|dir| make_dir dir}
75
+ end
76
+
77
+ def remove_dir dir
78
+ ::FileUtils.rm_rf dir
79
+ end
80
+
81
+ def remove_test_dir
82
+ remove_dir test_dir
83
+ end
84
+
85
+ def remove_test_dirs
86
+ test_dirs.each{|dir| remove_dir dir}
87
+ end
88
+
89
+ def make_file_symlink orig_file, sym_file
90
+ make_file orig_file if !File.file?(orig_file)
91
+ File.symlink(orig_file, sym_file) if !File.symlink?(sym_file)
92
+ end
93
+
94
+ def make_test_symlink
95
+ make_file_symlink test_file, sym_test_file
96
+ end
97
+
98
+ def make_test_symlinks
99
+ test_files.each_with_index{|file, i| make_file_symlink(file, sym_test_files[i])}
100
+ end
101
+
102
+ def remove_test_symlink
103
+ remove_file sym_test_file
104
+ end
105
+
106
+ def remove_test_symlinks
107
+ sym_test_files.each{|f| remove_file f}
108
+ end
109
+
110
+ def make_dir_symlink orig_dir, sym_dir
111
+ make_dir orig_dir if !File.directory?(orig_dir)
112
+ File.symlink(orig_dir, sym_dir) if !File.symlink?(sym_dir)
113
+ end
114
+
115
+ def make_test_symlink_dir
116
+ make_dir_symlink test_dir, sym_test_dir
117
+ end
118
+
119
+ def make_test_symlink_dirs
120
+ test_dirs.each_with_index{|file, i| make_dir_symlink(file, sym_test_dirs[i])}
121
+ end
122
+
123
+ def remove_test_symlink_dir
124
+ remove_dir sym_test_dir
125
+ end
126
+
127
+ def remove_test_symlink_dirs
128
+ sym_test_dirs.each{|dir| remove_dir dir}
129
+ end
130
+
131
+ end
@@ -0,0 +1,44 @@
1
+ module RSpec::FileMatchers
2
+ class HaveFileItem
3
+ attr_accessor :location
4
+
5
+ def initialize(*args)
6
+ self.location = get_location(args).to_s
7
+ end
8
+
9
+ def get_location(*args)
10
+ args = args.flatten
11
+ loc = if args.size > 1
12
+ dir, name = *args
13
+ File.join(dir.to_s, name.to_s)
14
+ else
15
+ args[0].to_s
16
+ end
17
+ end
18
+
19
+ def matches? x=nil, &block
20
+ puts location.inspect
21
+ match = File.send :"#{artifact}?", location
22
+ yield if block && match
23
+ match
24
+ end
25
+
26
+ def artifact
27
+ raise "artifact method must be overridden by subclass"
28
+ end
29
+
30
+ def failure_message
31
+ "Expected #{artifact} at: #{location} to exist, but it did not"
32
+ end
33
+
34
+ def negative_failure_message
35
+ "Did not expected #{artifact} at: #{location} to exist, but it did"
36
+ end
37
+ end
38
+
39
+ def have_file(*args)
40
+ HaveFile.new(args)
41
+ end
42
+ alias_method :contain_file, :have_file
43
+ end
44
+
@@ -0,0 +1,39 @@
1
+ module RSpec::FileMatchers
2
+ class HaveFileItems
3
+ attr_accessor :file_items
4
+
5
+ def initialize(*file_items)
6
+ self.file_items = file_items.flatten
7
+ end
8
+
9
+ def matches? x=nil, &block
10
+ file_item_names.each do |location|
11
+ return false if !File.send(:"#{artifact}?", location)
12
+ end
13
+ true
14
+ end
15
+
16
+ def file_item_names
17
+ @file_item_names ||= file_items.map(&:to_s)
18
+ end
19
+
20
+ def artifact
21
+ raise "artifact method must be overridden by subclass"
22
+ end
23
+
24
+ def failure_message
25
+ return "Expected #{artifact} #{file_item_names.first} to exist, but it did not" if file_items.size == 1
26
+ "Expected #{artifact.pluralize} [#{file_item_names}] to exist, but they did not"
27
+ end
28
+
29
+ def negative_failure_message
30
+ return "Did not expect #{artifact} #{file_item_names.first} to exist, but it did" if file_items.size == 1
31
+ "Did not expect #{artifact.pluralize} [#{file_item_names}] to exist, but they did"
32
+ end
33
+ end
34
+
35
+ def have_file_items(*args)
36
+ HaveFileItems.new(args)
37
+ end
38
+ end
39
+
@@ -0,0 +1,26 @@
1
+ module RSpec::FileMatchers
2
+ class HaveDir < HaveFileItem
3
+
4
+ def artifact
5
+ 'directory'
6
+ end
7
+ end
8
+
9
+ def have_dir(dir)
10
+ HaveDir.new(dir)
11
+ end
12
+ end
13
+
14
+ module RSpec::FileMatchers
15
+ class HaveDirs < HaveFileItems
16
+
17
+ def artifact
18
+ 'directory'
19
+ end
20
+ end
21
+
22
+ def have_dirs(*dirs)
23
+ HaveDirs.new(dirs)
24
+ end
25
+ end
26
+
@@ -0,0 +1,29 @@
1
+ module RSpec::FileMatchers
2
+ class HaveFile < HaveFileItem
3
+
4
+ def artifact
5
+ 'file'
6
+ end
7
+ end
8
+
9
+ def have_file(*args)
10
+ HaveFile.new(args)
11
+ end
12
+ alias_method :contain_file, :have_file
13
+ end
14
+
15
+ module RSpec::FileMatchers
16
+ class HaveFiles < HaveFileItems
17
+
18
+ def artifact
19
+ 'file'
20
+ end
21
+ end
22
+
23
+ def have_files(*args)
24
+ HaveFiles.new(args)
25
+ end
26
+ alias_method :contain_files, :have_files
27
+ end
28
+
29
+
@@ -0,0 +1,41 @@
1
+ module RSpec::FileMatchers
2
+ class HaveSymlink < HaveFileItem
3
+
4
+ def artifact
5
+ 'symlink'
6
+ end
7
+ end
8
+
9
+ def have_symlink(*args)
10
+ HaveSymlink.new(args)
11
+ end
12
+ alias_method :contain_symlink, :have_symlink
13
+
14
+ alias_method :contain_symlink_file, :have_symlink
15
+ alias_method :have_symlink_file, :have_symlink
16
+
17
+ alias_method :contain_symlink_dir, :have_symlink
18
+ alias_method :have_symlink_dir, :have_symlink
19
+ end
20
+
21
+ module RSpec::FileMatchers
22
+ class HaveSymlinks < HaveFileItems
23
+
24
+ def artifact
25
+ 'symlink'
26
+ end
27
+ end
28
+
29
+ def have_symlinks(*args)
30
+ HaveSymlinks.new(args)
31
+ end
32
+ alias_method :contain_symlinks, :have_symlinks
33
+
34
+ # TODO
35
+ alias_method :contain_symlink_files, :have_symlinks
36
+ alias_method :have_symlink_files, :have_symlinks
37
+
38
+ alias_method :contain_symlink_dirs, :have_symlinks
39
+ alias_method :have_symlink_dirs, :have_symlinks
40
+ end
41
+
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ module RSpec::FileMatchers
4
+ describe HaveFiles do
5
+ describe '#have_dirs' do
6
+ include FileHelper
7
+
8
+ before :each do
9
+ remove_test_dirs
10
+ end
11
+
12
+ after :each do
13
+ remove_test_dirs
14
+ end
15
+
16
+ it "should not have 'test' dirs" do
17
+ nil.should_not have_dirs test_dirs
18
+ end
19
+
20
+ it "should have 'test' dirs" do
21
+ make_test_dirs
22
+ nil.should have_dirs test_dirs
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ module RSpec::FileMatchers
4
+ describe HaveFiles do
5
+ describe '#have_files' do
6
+ include FileHelper
7
+
8
+ before :each do
9
+ remove_test_files
10
+ end
11
+
12
+ after :each do
13
+ remove_test_files
14
+ end
15
+
16
+ it "should have file" do
17
+ nil.should_not have_files test_files
18
+ end
19
+
20
+ it "should have file" do
21
+ make_test_files
22
+ nil.should have_files test_files
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ module RSpec::FileMatchers
4
+ describe HaveSymlinks do
5
+ describe '#have_symlinks' do
6
+ include FileHelper
7
+
8
+ before :each do
9
+ remove_all_test
10
+ end
11
+
12
+ after :each do
13
+ remove_all_test
14
+ end
15
+
16
+ it "should not have symlink files" do
17
+ nil.should_not have_symlinks sym_test_files
18
+ end
19
+
20
+ it "should have symlink files" do
21
+ make_test_symlinks
22
+ nil.should have_symlinks sym_test_files
23
+ end
24
+
25
+ it "should not have symlink dirs" do
26
+ nil.should_not have_symlink_dirs sym_test_dirs
27
+ end
28
+
29
+ it "should have symlink dirs" do
30
+ make_test_symlink_dirs
31
+ nil.should have_symlink_dirs sym_test_dirs
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ module RSpec::FileMatchers
4
+ describe HaveDir do
5
+ describe '#have_dir' do
6
+ include FileHelper
7
+
8
+ before :each do
9
+ remove_test_dir
10
+ end
11
+
12
+ after :each do
13
+ remove_test_dir
14
+ end
15
+
16
+ it "should not have 'test' dir" do
17
+ nil.should_not have_dir test_dir
18
+ end
19
+
20
+ it "should have 'test' dir" do
21
+ make_test_dir
22
+ nil.should have_dir test_dir
23
+ end
24
+
25
+ it "should have 'test' dirs" do
26
+ make_test_dirs
27
+ nil.should have_dirs test_dirs
28
+ end
29
+
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ module RSpec::FileMatchers
4
+ describe HaveFile do
5
+ describe '#have_file' do
6
+ include FileHelper
7
+
8
+ before :each do
9
+ remove_test_file
10
+ end
11
+
12
+ after :each do
13
+ remove_test_file
14
+ end
15
+
16
+ it "should have file" do
17
+ nil.should_not have_file test_file
18
+ end
19
+
20
+ it "should have file" do
21
+ make_test_file
22
+ nil.should have_file test_file
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ module RSpec::FileMatchers
4
+ describe HaveSymlink do
5
+ describe '#have_symlink' do
6
+ include FileHelper
7
+
8
+ before :each do
9
+ remove_all_test
10
+ end
11
+
12
+ after :each do
13
+ remove_all_test
14
+ end
15
+
16
+ it "should not have symlink file" do
17
+ nil.should_not have_symlink sym_test_file
18
+ end
19
+
20
+ it "should have symlink file" do
21
+ make_test_symlink
22
+ nil.should have_symlink sym_test_file
23
+ end
24
+
25
+ it "should not have symlink dir" do
26
+ nil.should_not have_symlink sym_test_dir
27
+ end
28
+
29
+ it "should have symlink dir" do
30
+ make_test_symlink_dir
31
+ nil.should have_symlink sym_test_dir
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,5 @@
1
+ require 'rspec'
2
+ require 'rspec/autorun'
3
+ require 'file-spec'
4
+ require 'file_spec/file_helper'
5
+ require 'fileutils'
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: file-spec
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - Kristian Mandrup
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-08-16 00:00:00 +02:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rspec
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 2
30
+ - 0
31
+ - 0
32
+ - beta
33
+ - 19
34
+ version: 2.0.0.beta.19
35
+ type: :development
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: require_all
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ segments:
46
+ - 1
47
+ - 1
48
+ - 0
49
+ version: 1.1.0
50
+ type: :runtime
51
+ version_requirements: *id002
52
+ description: RSpec 2 matchers for files, directories and symlinks
53
+ email: kmandrup@gmail.com
54
+ executables: []
55
+
56
+ extensions: []
57
+
58
+ extra_rdoc_files:
59
+ - LICENSE
60
+ - README.markdown
61
+ files:
62
+ - .document
63
+ - .gitignore
64
+ - .rspec
65
+ - LICENSE
66
+ - README.markdown
67
+ - Rakefile
68
+ - VERSION
69
+ - lib/file-spec.rb
70
+ - lib/file_spec/file_helper.rb
71
+ - lib/file_spec/matchers/abstract/have_file_item.rb
72
+ - lib/file_spec/matchers/abstract/have_file_items.rb
73
+ - lib/file_spec/matchers/have_dir.rb
74
+ - lib/file_spec/matchers/have_file.rb
75
+ - lib/file_spec/matchers/have_symlink.rb
76
+ - spec/file-spec/matchers/multiple/have_directories_spec.rb
77
+ - spec/file-spec/matchers/multiple/have_files_spec.rb
78
+ - spec/file-spec/matchers/multiple/have_symlinks_spec.rb
79
+ - spec/file-spec/matchers/single/have_directory_spec.rb
80
+ - spec/file-spec/matchers/single/have_file_spec.rb
81
+ - spec/file-spec/matchers/single/have_symlink_spec.rb
82
+ - spec/spec_helper.rb
83
+ has_rdoc: true
84
+ homepage: http://github.com/kristianmandrup/file-spec
85
+ licenses: []
86
+
87
+ post_install_message:
88
+ rdoc_options:
89
+ - --charset=UTF-8
90
+ require_paths:
91
+ - lib
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ none: false
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ segments:
98
+ - 0
99
+ version: "0"
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ none: false
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ segments:
106
+ - 0
107
+ version: "0"
108
+ requirements: []
109
+
110
+ rubyforge_project:
111
+ rubygems_version: 1.3.7
112
+ signing_key:
113
+ specification_version: 3
114
+ summary: RSpec 2 matchers for files, directories and symlinks
115
+ test_files:
116
+ - spec/file-spec/matchers/multiple/have_directories_spec.rb
117
+ - spec/file-spec/matchers/multiple/have_files_spec.rb
118
+ - spec/file-spec/matchers/multiple/have_symlinks_spec.rb
119
+ - spec/file-spec/matchers/single/have_directory_spec.rb
120
+ - spec/file-spec/matchers/single/have_file_spec.rb
121
+ - spec/file-spec/matchers/single/have_symlink_spec.rb
122
+ - spec/spec_helper.rb