file-spec 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/.document CHANGED
File without changes
data/.gitignore CHANGED
File without changes
data/.rspec CHANGED
File without changes
data/LICENSE CHANGED
File without changes
data/README.markdown CHANGED
@@ -4,25 +4,40 @@ RSpec 2 matcher to specify expected file structures.
4
4
 
5
5
  ## Usage
6
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
7
+ The following demonstrates File expectation nesting to test a File hierarchy structure!
8
+ Each block is evaluated in a new Dir context, using a Dir#chdir block.
9
+
10
+ Example: Nested file structure specs
11
+ <pre>
12
+ Dir.chdir(my_path)
13
+ Dir.pwd.should have_file 'hello.txt' do |dir|
14
+ dir.should have_files 'abc.rb', 'def.rb'
15
+ dir.should have_dir :test do |test_dir|
16
+ test_dir.should have_dirs :test_abc, :test_def
17
+ end
18
+ dir.should have_symlink :xyz
19
+ dir.should have_symlink_files 'blip.rb', 'blap.rb', 'logfile.log'
20
+ dir.should have_symlink_dir 'my-secret-dir'
21
+ end
22
+ end
23
+ </pre>
24
+
25
+ See /spec folder for more usage examples.
19
26
 
20
27
  ## TODO - advanced
21
28
 
29
+ * use Dir.tmpdir
22
30
  * have_file_structure yaml
23
31
 
24
- Should test that the files and dirs match the tree structure of the yaml string (or file).
32
+ Should test that the files and dirs match the tree structure as indicated by the yaml string (or file).
25
33
  This is very convenient for more complex file structure specs!
34
+ <pre>
35
+ mydir:
36
+ - file1.txt
37
+ - file2.txt
38
+ subdir1: [abc.rb, def.rb]
39
+ subdir2: [x.txt, logfile.log]
40
+ </pre>
26
41
 
27
42
  ## Note on Patches/Pull Requests
28
43
 
data/Rakefile CHANGED
File without changes
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
data/file-spec.gemspec ADDED
@@ -0,0 +1,76 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{file-spec}
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 = ["Kristian Mandrup"]
12
+ s.date = %q{2010-09-12}
13
+ s.description = %q{RSpec 2 matchers for files, directories and symlinks}
14
+ s.email = %q{kmandrup@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.markdown"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ ".rspec",
23
+ "LICENSE",
24
+ "README.markdown",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "file-spec.gemspec",
28
+ "lib/file-spec.rb",
29
+ "lib/file_spec/file_helpers/test_dirs.rb",
30
+ "lib/file_spec/file_helpers/test_files.rb",
31
+ "lib/file_spec/file_helpers/test_symlinks.rb",
32
+ "lib/file_spec/matchers/abstract/have_file_item.rb",
33
+ "lib/file_spec/matchers/abstract/have_file_items.rb",
34
+ "lib/file_spec/matchers/have_dir.rb",
35
+ "lib/file_spec/matchers/have_file.rb",
36
+ "lib/file_spec/matchers/have_symlink.rb",
37
+ "spec/file-spec/matchers/multiple/have_directories_spec.rb",
38
+ "spec/file-spec/matchers/multiple/have_files_spec.rb",
39
+ "spec/file-spec/matchers/multiple/have_symlinks_spec.rb",
40
+ "spec/file-spec/matchers/single/have_directory_spec.rb",
41
+ "spec/file-spec/matchers/single/have_file_spec.rb",
42
+ "spec/file-spec/matchers/single/have_symlink_spec.rb",
43
+ "spec/spec_helper.rb"
44
+ ]
45
+ s.homepage = %q{http://github.com/kristianmandrup/file-spec}
46
+ s.rdoc_options = ["--charset=UTF-8"]
47
+ s.require_paths = ["lib"]
48
+ s.rubygems_version = %q{1.3.7}
49
+ s.summary = %q{RSpec 2 matchers for files, directories and symlinks}
50
+ s.test_files = [
51
+ "spec/file-spec/matchers/multiple/have_directories_spec.rb",
52
+ "spec/file-spec/matchers/multiple/have_files_spec.rb",
53
+ "spec/file-spec/matchers/multiple/have_symlinks_spec.rb",
54
+ "spec/file-spec/matchers/single/have_directory_spec.rb",
55
+ "spec/file-spec/matchers/single/have_file_spec.rb",
56
+ "spec/file-spec/matchers/single/have_symlink_spec.rb",
57
+ "spec/spec_helper.rb"
58
+ ]
59
+
60
+ if s.respond_to? :specification_version then
61
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
62
+ s.specification_version = 3
63
+
64
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
65
+ s.add_development_dependency(%q<rspec>, [">= 2.0.0.beta.19"])
66
+ s.add_runtime_dependency(%q<require_all>, [">= 1.1.0"])
67
+ else
68
+ s.add_dependency(%q<rspec>, [">= 2.0.0.beta.19"])
69
+ s.add_dependency(%q<require_all>, [">= 1.1.0"])
70
+ end
71
+ else
72
+ s.add_dependency(%q<rspec>, [">= 2.0.0.beta.19"])
73
+ s.add_dependency(%q<require_all>, [">= 1.1.0"])
74
+ end
75
+ end
76
+
data/lib/file-spec.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'rspec'
2
2
  require 'require_all'
3
3
  require 'fileutils'
4
+ require 'tmpdir'
4
5
  require 'active_support/inflector'
5
6
 
6
7
  module RSpec
@@ -10,6 +11,7 @@ end
10
11
 
11
12
  require_all File.dirname(__FILE__) + '/file_spec/matchers/abstract'
12
13
  require_all File.dirname(__FILE__) + '/file_spec/matchers'
14
+ require_all File.dirname(__FILE__) + '/file_spec/file_helpers'
13
15
 
14
16
  RSpec.configure do |config|
15
17
  config.include(RSpec::FileMatchers)
@@ -0,0 +1,59 @@
1
+ module FileHelper
2
+ module TestDirs
3
+ module Names
4
+ def test_dir
5
+ 'test'
6
+ end
7
+
8
+ def test_dir2
9
+ 'test2'
10
+ end
11
+
12
+ def test_dirs
13
+ [test_dir, test_dir2]
14
+ end
15
+ end
16
+
17
+ module Make
18
+ def make_dir dir
19
+ Dir.mkdir dir if !File.directory? dir
20
+ end
21
+
22
+ def make_test_dir
23
+ make_dir test_dir
24
+ end
25
+
26
+ def make_test_dirs
27
+ test_dirs.each{|dir| make_dir dir}
28
+ end
29
+
30
+ def make_nested_test_dirs
31
+ make_test_dir
32
+ FileUtils.chdir test_dir do
33
+ make_test_dirs
34
+ make_test_files
35
+ end
36
+ end
37
+ end
38
+
39
+ module Remove
40
+ def remove_dir dir
41
+ FileUtils.rm_rf dir if File.directory? dir
42
+ end
43
+
44
+ def remove_test_dir
45
+ remove_dir test_dir
46
+ end
47
+
48
+ def remove_test_dirs
49
+ test_dirs.each{|dir| remove_dir dir}
50
+ end
51
+ end
52
+
53
+ include Names
54
+ include Make
55
+ include Remove
56
+ end
57
+
58
+ include TestDirs
59
+ end
@@ -0,0 +1,58 @@
1
+ module FileHelper
2
+ def remove_all_test
3
+ remove_test_files
4
+ remove_test_dirs
5
+ remove_test_symlink_files
6
+ remove_test_symlink_dirs
7
+ end
8
+
9
+ module TestFiles
10
+ module Names
11
+ def test_file
12
+ 'test.txt'
13
+ end
14
+
15
+ def test_file2
16
+ 'test2.txt'
17
+ end
18
+
19
+ def test_files
20
+ [test_file, test_file2]
21
+ end
22
+ end
23
+
24
+ module Make
25
+ def make_test_file
26
+ make_file test_file
27
+ end
28
+
29
+ def make_test_files
30
+ test_files.each{|f| make_file f}
31
+ end
32
+
33
+ def make_file file
34
+ File.open(file, 'w') {|f| f.write "hello" }
35
+ end
36
+ end
37
+
38
+ module Remove
39
+ def remove_file file
40
+ File.delete file if File.exist? file
41
+ end
42
+
43
+ def remove_test_file
44
+ remove_file test_file
45
+ end
46
+
47
+ def remove_test_files
48
+ test_files.each{|f| remove_file f}
49
+ end
50
+ end
51
+
52
+ include Names
53
+ include Make
54
+ include Remove
55
+ end
56
+
57
+ include TestFiles
58
+ end
@@ -0,0 +1,106 @@
1
+ module FileHelper
2
+ module TestSymlinks
3
+ module Files
4
+ module Names
5
+ def sym_test_file
6
+ "sym-#{test_file}"
7
+ end
8
+
9
+ def sym_test_file2
10
+ "sym-#{test_file2}"
11
+ end
12
+
13
+ def sym_test_files
14
+ [sym_test_file, sym_test_file2]
15
+ end
16
+ end
17
+
18
+ module Make
19
+ def make_file_symlink orig_file, sym_file
20
+ make_file orig_file if !File.file?(orig_file)
21
+ File.symlink(orig_file, sym_file) if !File.symlink?(sym_file)
22
+ end
23
+
24
+ def make_test_symlink_file
25
+ make_file_symlink test_file, sym_test_file
26
+ end
27
+
28
+ def make_test_symlink_files
29
+ test_files.each_with_index{|file, i| make_file_symlink(file, sym_test_files[i])}
30
+ end
31
+ end
32
+
33
+ module Remove
34
+ def remove_symlink_file path
35
+ File.delete path if File.symlink? path
36
+ end
37
+
38
+ def remove_test_symlink_file
39
+ remove_symlink_file sym_test_file
40
+ end
41
+
42
+ def remove_test_symlink_files
43
+ sym_test_files.each{|f| remove_symlink_file f}
44
+ end
45
+ end
46
+
47
+ include Names
48
+ include Make
49
+ include Remove
50
+ end
51
+
52
+ module Dirs
53
+ module Names
54
+ def sym_test_dir
55
+ 'sym-test-dir'
56
+ end
57
+
58
+ def sym_test_dir2
59
+ "#{sym_test_dir}2"
60
+ end
61
+
62
+ def sym_test_dirs
63
+ [sym_test_dir, sym_test_dir2]
64
+ end
65
+ end
66
+
67
+ module Make
68
+ def make_dir_symlink orig_dir, sym_dir
69
+ make_dir orig_dir if !File.directory?(orig_dir)
70
+ File.symlink(orig_dir, sym_dir) if !File.symlink?(sym_dir)
71
+ end
72
+
73
+ def make_test_symlink_dir
74
+ make_dir_symlink test_dir, sym_test_dir
75
+ end
76
+
77
+ def make_test_symlink_dirs
78
+ test_dirs.each_with_index{|file, i| make_dir_symlink(file, sym_test_dirs[i])}
79
+ end
80
+ end
81
+
82
+ module Remove
83
+ def remove_symlink_dir path
84
+ File.delete path if File.symlink? path
85
+ end
86
+
87
+ def remove_test_symlink_dir
88
+ remove_symlink_dir sym_test_dir
89
+ end
90
+
91
+ def remove_test_symlink_dirs
92
+ sym_test_dirs.each{|dir| remove_symlink_dir dir}
93
+ end
94
+ end
95
+
96
+ include Names
97
+ include Make
98
+ include Remove
99
+ end
100
+
101
+ include Dirs
102
+ include Files
103
+ end
104
+
105
+ include TestSymlinks
106
+ end
@@ -1,6 +1,6 @@
1
1
  module RSpec::FileMatchers
2
2
  class HaveFileItem
3
- attr_accessor :location
3
+ attr_accessor :location, :symlink_type
4
4
 
5
5
  def initialize(*args)
6
6
  self.location = get_location(args).to_s
@@ -8,6 +8,12 @@ module RSpec::FileMatchers
8
8
 
9
9
  def get_location(*args)
10
10
  args = args.flatten
11
+
12
+ case args.last
13
+ when Hash
14
+ self.symlink_type = args.last[:type]
15
+ end
16
+
11
17
  loc = if args.size > 1
12
18
  dir, name = *args
13
19
  File.join(dir.to_s, name.to_s)
@@ -16,10 +22,40 @@ module RSpec::FileMatchers
16
22
  end
17
23
  end
18
24
 
19
- def matches? x=nil, &block
20
- puts location.inspect
25
+ def matches? relative_path, &block
26
+ case relative_path
27
+ when File, Dir
28
+ @location = relative_path if !@location
29
+ Dir.chdir File.dirname(location)
30
+ when String
31
+ if File.exist?(relative_path)
32
+ @location = relative_path if !@location
33
+ Dir.chdir File.dirname(location)
34
+ end
35
+ end
36
+
21
37
  match = File.send :"#{artifact}?", location
22
- yield if block && match
38
+ if artifact == :symlink
39
+ case symlink_type
40
+ when :dir, :directory
41
+ match = File.readlink(location).directory?
42
+ when :file
43
+ match = File.readlink(location).file?
44
+ else
45
+ raise ArgumentError, "Bad symlink type #{symlink_type}, must be either :file or :dir" if symlink_type
46
+ end
47
+ end
48
+
49
+ if block && match
50
+ case artifact
51
+ when :directory
52
+ Dir.chdir location do
53
+ yield Dir.new(location)
54
+ end
55
+ when :file
56
+ yield File.new(location)
57
+ end
58
+ end
23
59
  match
24
60
  end
25
61
 
@@ -1,14 +1,48 @@
1
1
  module RSpec::FileMatchers
2
2
  class HaveFileItems
3
- attr_accessor :file_items
3
+ attr_accessor :file_items, :location, :symlink_type
4
4
 
5
5
  def initialize(*file_items)
6
- self.file_items = file_items.flatten
6
+ items = file_items.flatten
7
+ case items.last
8
+ when Hash
9
+ self.symlink_type = items.last[:type]
10
+ end
11
+ self.file_items = items.select{|item| !item.kind_of? Hash}
7
12
  end
8
13
 
9
- def matches? x=nil, &block
10
- file_item_names.each do |location|
11
- return false if !File.send(:"#{artifact}?", location)
14
+ def matches? relative_path=nil, &block
15
+ case relative_path
16
+ when File, Dir
17
+ full_path = File.expand_path(relative_path.path)
18
+ @location = File.dirname(full_path) if !@location
19
+ when String
20
+ begin
21
+ full_path = File.expand_path(relative_path)
22
+ if File.directory?(full_path)
23
+ @location = full_path if !@location
24
+ end
25
+ rescue
26
+ raise ArgumentError, "The path string #{relative_path} could not be resolved to an existing directory on this filesystem."
27
+ end
28
+ end
29
+
30
+ file_item_names.each do |loc|
31
+ path = location ? File.join(location, loc) : loc
32
+ bad = !File.send(:"#{artifact}?", path)
33
+
34
+ if artifact == :symlink && !bad
35
+ sym_path = File.readlink(path)
36
+ case symlink_type
37
+ when :dir, :directory
38
+ bad = !File.directory?(sym_path)
39
+ when :file
40
+ bad = !File.file?(sym_path)
41
+ else
42
+ raise ArgumentError, "Bad symlink type #{symlink_type}, must be either :file or :dir" if symlink_type
43
+ end
44
+ end
45
+ return false if bad
12
46
  end
13
47
  true
14
48
  end
@@ -23,12 +57,12 @@ module RSpec::FileMatchers
23
57
 
24
58
  def failure_message
25
59
  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"
60
+ "Expected #{artifact.to_s.pluralize} #{file_item_names} to exist, but they did not"
27
61
  end
28
62
 
29
63
  def negative_failure_message
30
64
  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"
65
+ "Did not expect #{artifact.to_s.pluralize} #{file_item_names} to exist, but they did"
32
66
  end
33
67
  end
34
68
 
@@ -2,7 +2,7 @@ module RSpec::FileMatchers
2
2
  class HaveDir < HaveFileItem
3
3
 
4
4
  def artifact
5
- 'directory'
5
+ :directory
6
6
  end
7
7
  end
8
8
 
@@ -15,7 +15,7 @@ module RSpec::FileMatchers
15
15
  class HaveDirs < HaveFileItems
16
16
 
17
17
  def artifact
18
- 'directory'
18
+ :directory
19
19
  end
20
20
  end
21
21
 
@@ -2,7 +2,7 @@ module RSpec::FileMatchers
2
2
  class HaveFile < HaveFileItem
3
3
 
4
4
  def artifact
5
- 'file'
5
+ :file
6
6
  end
7
7
  end
8
8
 
@@ -16,7 +16,7 @@ module RSpec::FileMatchers
16
16
  class HaveFiles < HaveFileItems
17
17
 
18
18
  def artifact
19
- 'file'
19
+ :file
20
20
  end
21
21
  end
22
22
 
@@ -2,7 +2,7 @@ module RSpec::FileMatchers
2
2
  class HaveSymlink < HaveFileItem
3
3
 
4
4
  def artifact
5
- 'symlink'
5
+ :symlink
6
6
  end
7
7
  end
8
8
 
@@ -10,19 +10,24 @@ module RSpec::FileMatchers
10
10
  HaveSymlink.new(args)
11
11
  end
12
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
13
+
14
+ def have_symlink_file(*args)
15
+ have_symlink args, :type => :file
16
+ end
17
+ alias_method :contain_symlink_file, :have_symlink_file
18
+
19
+ def have_symlink_dir(*args)
20
+ have_symlink args, :type => :dir
21
+ end
22
+ alias_method :contain_symlink_dir, :have_symlink_dir
23
+
19
24
  end
20
25
 
21
26
  module RSpec::FileMatchers
22
27
  class HaveSymlinks < HaveFileItems
23
28
 
24
29
  def artifact
25
- 'symlink'
30
+ :symlink
26
31
  end
27
32
  end
28
33
 
@@ -31,11 +36,14 @@ module RSpec::FileMatchers
31
36
  end
32
37
  alias_method :contain_symlinks, :have_symlinks
33
38
 
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
39
+ def have_symlink_files(*args)
40
+ have_symlinks args, :type => :file
41
+ end
42
+ alias_method :contain_symlink_files, :have_symlink_files
43
+
44
+ def have_symlink_dirs(*args)
45
+ have_symlinks args, :type => :dir
46
+ end
47
+ alias_method :contain_symlink_dirs, :have_symlink_dirs
40
48
  end
41
49
 
@@ -6,11 +6,11 @@ module RSpec::FileMatchers
6
6
  include FileHelper
7
7
 
8
8
  before :each do
9
- remove_test_dirs
9
+ remove_all_test
10
10
  end
11
11
 
12
12
  after :each do
13
- remove_test_dirs
13
+ remove_all_test
14
14
  end
15
15
 
16
16
  it "should not have 'test' dirs" do
@@ -21,6 +21,11 @@ module RSpec::FileMatchers
21
21
  make_test_dirs
22
22
  nil.should have_dirs test_dirs
23
23
  end
24
+
25
+ it "should have 'test' dirs in the current dir" do
26
+ make_test_dirs
27
+ Dir.pwd.should have_dirs test_dirs
28
+ end
24
29
  end
25
30
  end
26
31
  end
@@ -6,11 +6,11 @@ module RSpec::FileMatchers
6
6
  include FileHelper
7
7
 
8
8
  before :each do
9
- remove_test_files
9
+ remove_all_test
10
10
  end
11
11
 
12
12
  after :each do
13
- remove_test_files
13
+ remove_all_test
14
14
  end
15
15
 
16
16
  it "should have file" do
@@ -18,7 +18,7 @@ module RSpec::FileMatchers
18
18
  end
19
19
 
20
20
  it "should have symlink files" do
21
- make_test_symlinks
21
+ make_test_symlink_files
22
22
  nil.should have_symlinks sym_test_files
23
23
  end
24
24
 
@@ -4,29 +4,52 @@ module RSpec::FileMatchers
4
4
  describe HaveDir do
5
5
  describe '#have_dir' do
6
6
  include FileHelper
7
-
7
+
8
8
  before :each do
9
- remove_test_dir
9
+ remove_all_test
10
10
  end
11
-
11
+
12
12
  after :each do
13
- remove_test_dir
13
+ remove_all_test
14
14
  end
15
-
15
+
16
16
  it "should not have 'test' dir" do
17
17
  nil.should_not have_dir test_dir
18
18
  end
19
-
19
+
20
20
  it "should have 'test' dir" do
21
21
  make_test_dir
22
22
  nil.should have_dir test_dir
23
23
  end
24
-
24
+
25
25
  it "should have 'test' dirs" do
26
26
  make_test_dirs
27
27
  nil.should have_dirs test_dirs
28
28
  end
29
+
30
+ end
31
+
32
+ describe '#have_dir nested blocks' do
33
+ include FileHelper
34
+
35
+ before :each do
36
+ remove_all_test
37
+ end
29
38
 
39
+ after :each do
40
+ remove_all_test
41
+ end
42
+
43
+ it "should have nested test dirs" do
44
+ make_nested_test_dirs
45
+ nil.should have_dir :test
46
+ nil.should_not have_dir :test2
47
+ nil.should have_dir test_dir do |dir|
48
+ dir.should have_dirs test_dirs
49
+ dir.should have_files test_files
50
+ end
51
+ test_dir.should have_files test_files
52
+ end
30
53
  end
31
54
  end
32
55
  end
@@ -6,7 +6,7 @@ module RSpec::FileMatchers
6
6
  include FileHelper
7
7
 
8
8
  before :each do
9
- remove_test_file
9
+ remove_all_test
10
10
  end
11
11
 
12
12
  after :each do
@@ -16,12 +16,12 @@ module RSpec::FileMatchers
16
16
  it "should not have symlink file" do
17
17
  nil.should_not have_symlink sym_test_file
18
18
  end
19
-
19
+
20
20
  it "should have symlink file" do
21
- make_test_symlink
21
+ make_test_symlink_file
22
22
  nil.should have_symlink sym_test_file
23
23
  end
24
-
24
+
25
25
  it "should not have symlink dir" do
26
26
  nil.should_not have_symlink sym_test_dir
27
27
  end
@@ -30,6 +30,37 @@ module RSpec::FileMatchers
30
30
  make_test_symlink_dir
31
31
  nil.should have_symlink sym_test_dir
32
32
  end
33
+
34
+ it "should not have symlink dirs" do
35
+ nil.should_not have_symlinks sym_test_dirs
36
+ end
37
+
38
+ it "should not have symlink files" do
39
+ nil.should_not have_symlinks sym_test_files
40
+ end
41
+
42
+ it "should have symlink dirs" do
43
+ make_test_symlink_dirs
44
+ nil.should have_symlinks sym_test_dirs
45
+ end
46
+
47
+ it "should have symlink files" do
48
+ make_test_symlink_files
49
+ nil.should have_symlinks sym_test_files
50
+ end
51
+
52
+ it "should have symlink dirs" do
53
+ make_test_symlink_dirs
54
+ nil.should have_symlink_dirs sym_test_dirs
55
+ nil.should_not have_symlink_files sym_test_dirs
56
+ end
57
+
58
+ it "should have symlink files" do
59
+ make_test_symlink_files
60
+ nil.should have_symlink_files sym_test_files
61
+ nil.should_not have_symlink_dirs sym_test_files
62
+ end
63
+
33
64
  end
34
65
  end
35
66
  end
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  require 'rspec'
2
2
  require 'rspec/autorun'
3
3
  require 'file-spec'
4
- require 'file_spec/file_helper'
5
4
  require 'fileutils'
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 0
9
- version: 0.1.0
8
+ - 1
9
+ version: 0.1.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Kristian Mandrup
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-08-16 00:00:00 +02:00
17
+ date: 2010-09-12 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -66,8 +66,11 @@ files:
66
66
  - README.markdown
67
67
  - Rakefile
68
68
  - VERSION
69
+ - file-spec.gemspec
69
70
  - lib/file-spec.rb
70
- - lib/file_spec/file_helper.rb
71
+ - lib/file_spec/file_helpers/test_dirs.rb
72
+ - lib/file_spec/file_helpers/test_files.rb
73
+ - lib/file_spec/file_helpers/test_symlinks.rb
71
74
  - lib/file_spec/matchers/abstract/have_file_item.rb
72
75
  - lib/file_spec/matchers/abstract/have_file_items.rb
73
76
  - lib/file_spec/matchers/have_dir.rb
@@ -1,131 +0,0 @@
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