build-files 1.7.0 → 1.7.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 266f5c2f5a839934620afe4a06289bf7c4363d39c04b39fc3fef8b87104d7ff1
4
- data.tar.gz: b775a997766d4ff2fc751e08fc93d6512a373e944813ee09097731f432087714
3
+ metadata.gz: 777a262af38e7bd84dc924b8e140d8d4e00077fab74b35d6f6ee555063809981
4
+ data.tar.gz: 981cbf1c9ff4234e9ef7e220de1362ecbcad2d61ae50d77ec072d19586471028
5
5
  SHA512:
6
- metadata.gz: 303be1f16bcadc201db4fd2c9530250926942e1f3f63d269646d943ca439b2c2ca930c0a9fc5caeb16fc4c35362c84580699f5732917f9df51739f339aa7640c
7
- data.tar.gz: 52f6d5d1441dcd15d5be335cab08620aa41524aef8294a13c4adaa2df5513d9e1a03b29b42336afe29b98bdd6f8f1c53c1eb90d7279d855738acfe4e0a29be3b
6
+ metadata.gz: 85211d1effb626dd6d7664a3eaa15ab1f96b456ea49588dcd231c231fb47bbe545e4ea1aacfd7971c523b1674d418f47f4b1c86aa0b472dbb7c4f98c7e6e2587
7
+ data.tar.gz: a3f499ce331105afe331dbc912a41a532d9478dae92be32da1362dc082133533f6e4b42305e22a7b5a32959093a74a753d30b47b6b3cf361cc8fb3438cef81fd
data/lib/.DS_Store ADDED
Binary file
Binary file
@@ -110,6 +110,8 @@ module Build
110
110
  @full_path.length
111
111
  end
112
112
 
113
+ alias size length
114
+
113
115
  def components
114
116
  @components ||= @full_path.split(File::SEPARATOR).freeze
115
117
  end
@@ -126,6 +128,10 @@ module Build
126
128
  root = Path.root(root)
127
129
  end
128
130
 
131
+ if root.size == full_path.size
132
+ root = Path.root(root)
133
+ end
134
+
129
135
  self.class.new(full_path, root)
130
136
  end
131
137
 
@@ -20,6 +20,6 @@
20
20
 
21
21
  module Build
22
22
  module Files
23
- VERSION = "1.7.0"
23
+ VERSION = "1.7.1"
24
24
  end
25
25
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: build-files
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.0
4
+ version: 1.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
@@ -11,7 +11,7 @@ cert_chain: []
11
11
  date: 2021-05-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: covered
14
+ name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
@@ -25,7 +25,7 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: bundler
28
+ name: covered
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
@@ -52,34 +52,15 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.4'
55
- - !ruby/object:Gem::Dependency
56
- name: bake-bundler
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
55
  description:
70
56
  email:
71
- - samuel.williams@oriontransfer.co.nz
72
57
  executables: []
73
58
  extensions: []
74
59
  extra_rdoc_files: []
75
60
  files:
76
- - ".gitignore"
77
- - ".rspec"
78
- - ".travis.yml"
79
- - Gemfile
80
- - README.md
81
- - build-files.gemspec
61
+ - lib/.DS_Store
82
62
  - lib/build/files.rb
63
+ - lib/build/files/.DS_Store
83
64
  - lib/build/files/composite.rb
84
65
  - lib/build/files/difference.rb
85
66
  - lib/build/files/directory.rb
@@ -89,16 +70,7 @@ files:
89
70
  - lib/build/files/paths.rb
90
71
  - lib/build/files/system.rb
91
72
  - lib/build/files/version.rb
92
- - spec/build/files/directory_spec.rb
93
- - spec/build/files/directory_spec/.dot_file.yaml
94
- - spec/build/files/directory_spec/normal_file.txt
95
- - spec/build/files/glob_spec.rb
96
- - spec/build/files/glob_spec/dotfiles/.file
97
- - spec/build/files/list_spec.rb
98
- - spec/build/files/path_spec.rb
99
- - spec/build/files/system_spec.rb
100
- - spec/spec_helper.rb
101
- homepage: ''
73
+ homepage:
102
74
  licenses:
103
75
  - MIT
104
76
  metadata: {}
@@ -120,15 +92,5 @@ requirements: []
120
92
  rubygems_version: 3.2.3
121
93
  signing_key:
122
94
  specification_version: 4
123
- summary: Build::Files is a set of idiomatic classes for dealing with paths and monitoring
124
- directories.
125
- test_files:
126
- - spec/build/files/directory_spec.rb
127
- - spec/build/files/directory_spec/.dot_file.yaml
128
- - spec/build/files/directory_spec/normal_file.txt
129
- - spec/build/files/glob_spec.rb
130
- - spec/build/files/glob_spec/dotfiles/.file
131
- - spec/build/files/list_spec.rb
132
- - spec/build/files/path_spec.rb
133
- - spec/build/files/system_spec.rb
134
- - spec/spec_helper.rb
95
+ summary: Abstractions for handling and mapping paths.
96
+ test_files: []
data/.gitignore DELETED
@@ -1,24 +0,0 @@
1
- *.gem
2
- *.rbc
3
- .bundle
4
- .config
5
- .yardoc
6
- Gemfile.lock
7
- InstalledFiles
8
- _yardoc
9
- coverage
10
- doc/
11
- lib/bundler/man
12
- pkg
13
- rdoc
14
- spec/reports
15
- test/tmp
16
- test/version_tmp
17
- tmp
18
- *.bundle
19
- *.so
20
- *.o
21
- *.a
22
- mkmf.log
23
- .rspec_status
24
-
data/.rspec DELETED
@@ -1,4 +0,0 @@
1
- --format documentation
2
- --backtrace
3
- --warnings
4
- --require spec_helper
data/.travis.yml DELETED
@@ -1,14 +0,0 @@
1
- language: ruby
2
- dist: xenial
3
- cache: bundler
4
-
5
- matrix:
6
- include:
7
- - rvm: 2.3
8
- - rvm: 2.4
9
- - rvm: 2.5
10
- - rvm: 2.6
11
- env: COVERAGE=BriefSummary,Coveralls
12
- - rvm: 2.6
13
- os: osx
14
- env: COVERAGE=BriefSummary,Coveralls
data/Gemfile DELETED
@@ -1,9 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in build-files.gemspec
4
- gemspec
5
-
6
- group :test do
7
- gem 'rb-fsevent'
8
- gem 'rb-inotify'
9
- end
data/README.md DELETED
@@ -1,69 +0,0 @@
1
- # Build::Files
2
-
3
- Build::Files is a set of idiomatic classes for dealing with paths and monitoring directories. File paths are represented with both root and relative parts which makes copying directory structures intuitive.
4
-
5
- [![Build Status](https://secure.travis-ci.org/ioquatix/build-files.svg)](http://travis-ci.org/ioquatix/build-files)
6
- [![Code Climate](https://codeclimate.com/github/ioquatix/build-files.svg)](https://codeclimate.com/github/ioquatix/build-files)
7
- [![Coverage Status](https://coveralls.io/repos/ioquatix/build-files/badge.svg)](https://coveralls.io/r/ioquatix/build-files)
8
-
9
- ## Installation
10
-
11
- Add this line to your application's Gemfile:
12
-
13
- gem 'build-files'
14
-
15
- And then execute:
16
-
17
- $ bundle
18
-
19
- Or install it yourself as:
20
-
21
- $ gem install build-files
22
-
23
- ## Usage
24
-
25
- The basic structure is the `Path`. Paths are stored with a root and relative part. By default, if no root is specified, it is the `dirname` part.
26
-
27
- require 'build/files'
28
-
29
- path = Build::Files::Path("/foo/bar/baz")
30
- => "/foo/bar"/"baz"
31
-
32
- > path.root
33
- => "/foo/bar"
34
- > path.relative_path
35
- => "baz"
36
-
37
- Paths can be coerced to strings and thus are suitable arguments to `exec`/`system` functions.
38
-
39
- ## Contributing
40
-
41
- 1. Fork it
42
- 2. Create your feature branch (`git checkout -b my-new-feature`)
43
- 3. Commit your changes (`git commit -am 'Add some feature'`)
44
- 4. Push to the branch (`git push origin my-new-feature`)
45
- 5. Create new Pull Request
46
-
47
- ## License
48
-
49
- Released under the MIT license.
50
-
51
- Copyright, 2014, by [Samuel G. D. Williams](http://www.codeotaku.com/samuel-williams).
52
-
53
- Permission is hereby granted, free of charge, to any person obtaining a copy
54
- of this software and associated documentation files (the "Software"), to deal
55
- in the Software without restriction, including without limitation the rights
56
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
57
- copies of the Software, and to permit persons to whom the Software is
58
- furnished to do so, subject to the following conditions:
59
-
60
- The above copyright notice and this permission notice shall be included in
61
- all copies or substantial portions of the Software.
62
-
63
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
64
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
65
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
66
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
67
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
68
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
69
- THE SOFTWARE.
data/build-files.gemspec DELETED
@@ -1,25 +0,0 @@
1
-
2
- require_relative 'lib/build/files/version'
3
-
4
- Gem::Specification.new do |spec|
5
- spec.name = "build-files"
6
- spec.version = Build::Files::VERSION
7
- spec.authors = ["Samuel Williams"]
8
- spec.email = ["samuel.williams@oriontransfer.co.nz"]
9
- # spec.description = %q{}
10
- spec.summary = %q{Build::Files is a set of idiomatic classes for dealing with paths and monitoring directories.}
11
- spec.homepage = ""
12
- spec.license = "MIT"
13
-
14
- spec.files = `git ls-files`.split($/)
15
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
- spec.require_paths = ["lib"]
18
-
19
- spec.required_ruby_version = '>= 2.0'
20
-
21
- spec.add_development_dependency "covered"
22
- spec.add_development_dependency "bundler"
23
- spec.add_development_dependency "rspec", "~> 3.4"
24
- spec.add_development_dependency "bake-bundler"
25
- end
@@ -1,80 +0,0 @@
1
- # Copyright, 2014, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the "Software"), to deal
5
- # in the Software without restriction, including without limitation the rights
6
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- # copies of the Software, and to permit persons to whom the Software is
8
- # furnished to do so, subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in
11
- # all copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- # THE SOFTWARE.
20
-
21
- require 'build/files/directory'
22
-
23
- module Build::Files::DirectorySpec
24
- include Build::Files
25
-
26
- describe Build::Files::Directory do
27
- let(:path) {Path.new("/foo/bar/baz", "/foo")}
28
- let(:directory) {Directory.new(path)}
29
-
30
- it "can be constructed using join" do
31
- joined_directory = Directory.join('/foo', 'bar/baz')
32
-
33
- expect(joined_directory).to be == directory
34
- end
35
-
36
- it "has a root and path component" do
37
- expect(directory.root).to be == path
38
- expect(directory.to_path).to be == path
39
-
40
- expect(directory.roots).to be_include(path)
41
- end
42
-
43
- it "can be converted into a string" do
44
- expect(directory.to_str).to be == path.to_str
45
- end
46
-
47
- it "can be used as a key" do
48
- hash = {directory => true}
49
-
50
- expect(hash).to be_include directory
51
- end
52
-
53
- it "includes subpaths" do
54
- expect(directory).to be_include "/foo/bar/baz/bob/dole"
55
- end
56
-
57
- it "can be compared" do
58
- other_directory = Directory.new(path + 'dole')
59
-
60
- expect(directory).to be_eql directory
61
- expect(directory).to_not be_eql other_directory
62
- end
63
-
64
- it "can be rebased" do
65
- rebased_directory = directory.rebase("/fu")
66
-
67
- expect(rebased_directory.root).to be == '/fu/bar/baz'
68
- end
69
-
70
- context Directory.join(__dir__, "directory_spec") do
71
- it "can list dot files" do
72
- expect(subject).to include(subject.root + '.dot_file.yaml')
73
- end
74
-
75
- it "can list normal files" do
76
- expect(subject).to include(subject.root + 'normal_file.txt')
77
- end
78
- end
79
- end
80
- end
File without changes
File without changes
@@ -1,53 +0,0 @@
1
- # Copyright, 2014, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the "Software"), to deal
5
- # in the Software without restriction, including without limitation the rights
6
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- # copies of the Software, and to permit persons to whom the Software is
8
- # furnished to do so, subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in
11
- # all copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- # THE SOFTWARE.
20
-
21
- require 'build/files/glob'
22
-
23
- RSpec.describe Build::Files::Glob do
24
- let(:path) {Build::Files::Path.new(__dir__)}
25
-
26
- it "can glob paths" do
27
- paths = path.glob("*.rb")
28
-
29
- expect(paths.count).to be >= 1
30
- end
31
-
32
- it "can be used as key in hash" do
33
- cache = {}
34
-
35
- cache[path.glob("*.rb")] = true
36
-
37
- expect(cache).to be_include(path.glob("*.rb"))
38
- end
39
-
40
- it "should print nice string represenation" do
41
- glob = Build::Files::Glob.new(".", "*.rb")
42
-
43
- expect("#{glob}").to be == '<Glob "."/"*.rb">'
44
- end
45
-
46
- context 'with dotfiles' do
47
- it "should list files starting with dot" do
48
- paths = path.glob("glob_spec/dotfiles/**/*")
49
-
50
- expect(paths.count).to be == 1
51
- end
52
- end
53
- end
File without changes
@@ -1,182 +0,0 @@
1
- # Copyright, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the "Software"), to deal
5
- # in the Software without restriction, including without limitation the rights
6
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- # copies of the Software, and to permit persons to whom the Software is
8
- # furnished to do so, subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in
11
- # all copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- # THE SOFTWARE.
20
-
21
- require 'build/files'
22
- require 'build/files/list'
23
- require 'build/files/glob'
24
-
25
- module Build::Files::ListSpec
26
- include Build::Files
27
-
28
- describe Build::Files::Paths do
29
- let(:path) {Path.new("/foo/bar/baz", "/foo")}
30
-
31
- it "should be inspectable" do
32
- paths = Paths.new(path)
33
-
34
- expect(paths.inspect).to be_include path.inspect
35
- end
36
-
37
- it "should be possible to convert to paths" do
38
- paths = Paths.new(path)
39
-
40
- expect(paths.to_paths).to be paths
41
- end
42
-
43
- it "should be count number of paths" do
44
- paths = Paths.new(path)
45
-
46
- expect(paths.count).to be == 1
47
- end
48
-
49
- it "should coerce array to paths" do
50
- paths = Paths.coerce([path])
51
-
52
- expect(paths).to be_kind_of Paths
53
- expect(paths.count).to be == 1
54
- expect(paths).to be_include path
55
-
56
- same_paths = Paths.coerce(paths)
57
- expect(same_paths).to be paths
58
- end
59
-
60
- it "can add two lists of paths together" do
61
- paths_a = Paths.new(path)
62
- paths_b = Paths.new(Path.join('/foo/bar', 'alice'))
63
-
64
- paths = paths_a + paths_b
65
-
66
- expect(paths.count).to be 2
67
- expect(paths).to be_include path
68
- expect(paths).to be_kind_of Composite
69
-
70
- # Composite equality
71
- expect(paths).to be_eql paths
72
- expect(paths).to_not be_eql paths_a
73
- end
74
-
75
- it "maps paths with a new extension" do
76
- paths = Paths.new([
77
- Path.join('/foo/bar', 'alice'),
78
- Path.join('/foo/bar', 'bob'),
79
- Path.join('/foo/bar', 'charles'),
80
- path
81
- ])
82
-
83
- expect(paths).to include(path)
84
-
85
- expect(paths).to be_intersects(paths)
86
- expect(paths).to_not be_intersects(Paths::NONE)
87
-
88
- mapped_paths = paths.map {|path| path + ".o"}
89
-
90
- expect(mapped_paths).to be_kind_of(Paths)
91
- expect(mapped_paths.roots).to be == paths.roots
92
- end
93
-
94
- it "globs multiple files" do
95
- glob = Glob.new(__dir__, '*.rb')
96
-
97
- expect(glob.count).to be > 1
98
-
99
- mapped_paths = glob.map {|path| path + ".txt"}
100
-
101
- expect(glob.roots).to be == mapped_paths.roots
102
- end
103
-
104
- it "should intersect one file in the glob" do
105
- # Glob all test files:
106
- glob = Glob.new(__dir__, "*.rb")
107
-
108
- expect(glob.count).to be > 0
109
-
110
- # Should include this file:
111
- expect(glob).to include(__FILE__)
112
-
113
- # Glob should intersect self:
114
- expect(glob).to be_intersects(glob)
115
- end
116
-
117
- it "should include composites" do
118
- lib = File.join(__dir__, "../lib")
119
-
120
- test_glob = Glob.new(__dir__, "*.rb")
121
- lib_glob = Glob.new(lib, "*.rb")
122
-
123
- both = test_glob + lib_glob
124
-
125
- # List#roots is the generic accessor for Lists
126
- expect(both.roots).to include test_glob.root
127
-
128
- # The composite should include both:
129
- expect(both).to include(__FILE__)
130
- end
131
-
132
- it "should have path with correct root" do
133
- test_glob = Glob.new(__dir__, "*.rb")
134
-
135
- expect(test_glob.first).to be_kind_of Path
136
-
137
- expect(test_glob.first.root).to be == __dir__
138
- end
139
-
140
- it "maps paths with new extension" do
141
- glob = Glob.new(__dir__, "*.rb")
142
-
143
- paths = glob.map {|path| path.append ".txt"}
144
-
145
- expect(paths.first).to be == (glob.first.append ".txt")
146
- expect(paths.first.to_s).to be_end_with ".rb.txt"
147
- end
148
-
149
- it "should map paths using with" do
150
- glob = Glob.new(__dir__, "*.rb")
151
-
152
- paths = glob.with extension: ".txt"
153
- path = paths.first
154
-
155
- expect(path).to be_kind_of Array
156
-
157
- expect(path[0]).to be == glob.first
158
- expect(path[1]).to be == glob.first.append(".txt")
159
- end
160
-
161
- it "should define an empty set of files" do
162
- expect(Paths::NONE).to be_kind_of List
163
-
164
- expect(Paths::NONE.count).to be 0
165
- end
166
-
167
- it "can be used as key in hash" do
168
- cache = {}
169
-
170
- cache[Paths.new(path)] = true
171
-
172
- expect(cache).to be_include(Paths.new(path))
173
- end
174
-
175
- it "can be constructed from a list of relative paths" do
176
- paths = Paths.directory('/foo', ['bar', 'baz', 'bob'])
177
-
178
- expect(paths.count).to be 3
179
- expect(paths).to be_include Path.new('/foo/bar')
180
- end
181
- end
182
- end
@@ -1,223 +0,0 @@
1
- # Copyright, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the "Software"), to deal
5
- # in the Software without restriction, including without limitation the rights
6
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- # copies of the Software, and to permit persons to whom the Software is
8
- # furnished to do so, subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in
11
- # all copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- # THE SOFTWARE.
20
-
21
- require 'build/files'
22
- require 'build/files/path'
23
-
24
- require 'pathname'
25
-
26
- RSpec.describe Build::Files::Path do
27
- it "can get current path" do
28
- expect(Build::Files::Path.current.full_path).to be == Dir.pwd
29
- end
30
-
31
- it "should expand the path" do
32
- expect(Build::Files::Path.expand("foo", "/bar")).to be == "/bar/foo"
33
- end
34
-
35
- it "should give current path" do
36
- path = Build::Files::Path.new("/a/b/c/file.cpp")
37
-
38
- expect(path.shortest_path(path)).to be == "."
39
- end
40
-
41
- it "should give the shortest path for outer paths" do
42
- input = Build::Files::Path.new("/a/b/c/file.cpp")
43
- output = Build::Files::Path.new("/a/b/c/d/e/")
44
-
45
- expect(input.root).to be == "/a/b/c"
46
- expect(output.root).to be == "/a/b/c/d/e"
47
-
48
- short = input.shortest_path(output)
49
-
50
- expect(short).to be == "../../file.cpp"
51
-
52
- expect(File.expand_path(short, output)).to be == input
53
- end
54
-
55
- it "should give the shortest path for inner paths" do
56
- input = Build::Files::Path.new("/a/b/c/file.cpp")
57
- output = Build::Files::Path.new("/a/")
58
-
59
- expect(input.root).to be == "/a/b/c"
60
- expect(output.root).to be == "/a"
61
-
62
- short = input.shortest_path(output)
63
-
64
- expect(short).to be == "b/c/file.cpp"
65
-
66
- expect(File.expand_path(short, output)).to be == input
67
- end
68
- end
69
-
70
- RSpec.describe Build::Files::Path.new("/test") do
71
- it "should start_with? full path" do
72
- expect(subject).to be_start_with '/test'
73
- end
74
-
75
- it "should start_with? partial pattern" do
76
- expect(subject).to be_start_with '/te'
77
- end
78
- end
79
-
80
- RSpec.describe Build::Files::Path.new("/foo/bar.txt") do
81
- it "should replace existing file extension" do
82
- expect(subject.with(extension: '.jpeg', basename: true)).to be == "/foo/bar.jpeg"
83
- end
84
-
85
- it "should append file extension" do
86
- expect(subject.with(extension: '.jpeg')).to be == "/foo/bar.txt.jpeg"
87
- end
88
-
89
- it "should change basename" do
90
- expect(subject.with(basename: 'baz', extension: '.txt')).to be == "/foo/baz.txt"
91
- end
92
- end
93
-
94
- RSpec.describe Build::Files::Path.new("/foo/bar/baz", "/foo") do
95
- it "can compute parent path" do
96
- parent = subject.parent
97
-
98
- expect(parent.root).to be == subject.root
99
- expect(parent.relative_path).to be == "bar"
100
- expect(parent.full_path).to be == "/foo/bar"
101
- end
102
-
103
- it "can add nil path" do
104
- expect(subject + nil).to be == subject
105
- end
106
-
107
- it "can inspect path with nil root" do
108
- expect do
109
- (subject / nil).inspect
110
- end.to_not raise_error
111
- end
112
-
113
- it "can add nil root" do
114
- expect(subject / nil).to be == subject
115
- end
116
-
117
- it "should be inspectable" do
118
- expect(subject.inspect).to be_include subject.root.to_s
119
- expect(subject.inspect).to be_include subject.relative_path.to_s
120
- end
121
-
122
- it "should convert to path" do
123
- pathname = Pathname("/foo/bar/baz")
124
-
125
- expect(Build::Files::Path[pathname]).to be == subject
126
- expect(Build::Files::Path["/foo/bar/baz"]).to be == subject
127
- end
128
-
129
- it "should be equal" do
130
- expect(subject).to be_eql subject
131
- expect(subject).to be == subject
132
-
133
- different_root_path = Build::Files::Path.join("/foo/bar", "baz")
134
- expect(subject).to_not be_eql different_root_path
135
- expect(subject).to be == different_root_path
136
- end
137
-
138
- it "should convert to string" do
139
- expect(subject.to_s).to be == "/foo/bar/baz"
140
-
141
- # The to_str method should return the full path (i.e. the same as to_s):
142
- expect(subject.to_s).to be == subject.to_str
143
-
144
- # Check the equality operator:
145
- expect(subject).to be == subject.dup
146
-
147
- # The length should be reported correctly:
148
- expect(subject.length).to be == subject.to_s.length
149
-
150
- # Check the return types:
151
- expect(subject).to be_kind_of Build::Files::Path
152
- expect(subject.root).to be_kind_of String
153
- expect(subject.relative_path).to be_kind_of String
154
- end
155
-
156
- it "should consist of parts" do
157
- expect(subject.parts).to be == ["", "foo", "bar", "baz"]
158
-
159
- expect(subject.root).to be == "/foo"
160
-
161
- expect(subject.relative_path).to be == "bar/baz"
162
-
163
- expect(subject.relative_parts).to be == ["bar", "baz"]
164
- end
165
-
166
- it "should have a new extension" do
167
- renamed_path = subject.with(root: '/tmp', extension: '.txt')
168
-
169
- expect(renamed_path.root).to be == '/tmp'
170
-
171
- expect(renamed_path.relative_path).to be == 'bar/baz.txt'
172
-
173
- object_path = subject.append(".o")
174
-
175
- expect(object_path.root).to be == "/foo"
176
- expect(object_path.relative_path).to be == "bar/baz.o"
177
- end
178
-
179
- it "should append a path" do
180
- subject = Build::Files::Path.new("/a/b/c")
181
-
182
- expect(subject + "d/e/f").to be == "/a/b/c/d/e/f"
183
- end
184
-
185
- it "should give a list of components" do
186
- expect(Build::Files::Path.components(subject)).to be == ["", "foo", "bar", "baz"]
187
- expect(Build::Files::Path.components(subject.to_s)).to be == ["", "foo", "bar", "baz"]
188
- end
189
-
190
- it "should give a basename" do
191
- expect(subject.basename).to be == "baz"
192
- end
193
-
194
- it "should have a new root" do
195
- rerooted_path = subject / "cat"
196
-
197
- expect(rerooted_path.root).to be == "/foo/bar/baz"
198
- expect(rerooted_path.relative_path).to be == "cat"
199
- end
200
-
201
- it "should give correct modes for reading" do
202
- expect(subject.for_reading).to be == [subject.to_s, File::RDONLY]
203
- end
204
-
205
- it "should give correct modes for writing" do
206
- expect(subject.for_writing).to be == [subject.to_s, File::CREAT|File::TRUNC|File::WRONLY]
207
- end
208
-
209
- it "should give correct modes for appending" do
210
- expect(subject.for_appending).to be == [subject.to_s, File::CREAT|File::APPEND|File::WRONLY]
211
- end
212
-
213
- it "should match against relative path" do
214
- expect(subject.match(subject.relative_path)).to be_truthy
215
- expect(subject.match("*/baz")).to be_truthy
216
- expect(subject.match("/baz")).to be_falsey
217
- end
218
-
219
- it "should match against absolute path" do
220
- expect(subject.match(subject.to_s)).to be_truthy
221
- expect(subject.match("/foo/**")).to be_truthy
222
- end
223
- end
@@ -1,56 +0,0 @@
1
- # Copyright, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the "Software"), to deal
5
- # in the Software without restriction, including without limitation the rights
6
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- # copies of the Software, and to permit persons to whom the Software is
8
- # furnished to do so, subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in
11
- # all copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- # THE SOFTWARE.
20
-
21
- require 'build/files'
22
- require 'build/files/path'
23
- require 'build/files/system'
24
-
25
- require 'pathname'
26
-
27
- module Build::Files::FilesystemSpec
28
- include Build::Files
29
-
30
- describe Build::Files::Path do
31
- let(:root) {Path.new(__dir__)}
32
- let(:path) {root + "filesystem_spec"}
33
-
34
- after(:each) do
35
- path.delete
36
- end
37
-
38
- it "should open file for writing" do
39
- path.write("Hello World")
40
-
41
- expect(File).to be_exist(path)
42
- expect(path.read).to be == "Hello World"
43
-
44
- expect(path).to be_exist
45
- expect(path.directory?).to be == false
46
-
47
- expect(path.modified_time.to_f).to be_within(5.0).of(Time.now.to_f)
48
- end
49
-
50
- it "should make a directory" do
51
- path.create
52
-
53
- expect(path.directory?).to be == true
54
- end
55
- end
56
- end
data/spec/spec_helper.rb DELETED
@@ -1,11 +0,0 @@
1
-
2
- require "covered/rspec"
3
-
4
- RSpec.configure do |config|
5
- # Enable flags like --only-failures and --next-failure
6
- config.example_status_persistence_file_path = ".rspec_status"
7
-
8
- config.expect_with :rspec do |c|
9
- c.syntax = :expect
10
- end
11
- end