pathspec 2.0.0 → 2.1.0

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: a68a1f2de0af463918423adf4905b099d6bd20137f77df03c2a771ccca52d2da
4
- data.tar.gz: 55652f63f95caf42cc227f4e8535263eb527a517c9b82443d29e31bba8b702fe
3
+ metadata.gz: c8cbc90066974f8467fb62548b62bc51b00c56623b98c6fdf99897ab170378c3
4
+ data.tar.gz: 649ab494204ab19fd65086ea8f01efb16ee523b9ccf107f7b06234cff031aefb
5
5
  SHA512:
6
- metadata.gz: b2c9cae60c4ddc32a1fdfff6cd9736ad7a351cbfa32d7e2dea124a86f5a75e2a32dca443fef1280ba71051f7bd57e00a38b47e553a52a3c966dcf2eb7e75d2fd
7
- data.tar.gz: 44cf94223ca155dcba01ea68a6616071e9f0fc07b6f89e6fdef57864729a0ea73f80fbff8d5e2f7f38ca5503e9606486da2027f67baae43d70385487f7f6b7c6
6
+ metadata.gz: 67698a0b54e5cc851d86347a1929feaaf2c8967c75010f92fd1087f30e56cb39278b7d78c6fae3c8f034a52dc52d56aa23208279b5e4a3006244e65ebdc86b10
7
+ data.tar.gz: c17cdce06ee08bbddce5b92239e79f9bf76d3d5fba9684584ae1e3c13f2891f5ba3aa369be5a2f755f60ad3ffb5bde50d4672cd2ad826ef89567ac09eb356683
data/CHANGELOG.md CHANGED
@@ -1,17 +1,52 @@
1
1
  # pathspec-ruby CHANGELOG
2
2
 
3
+ ## 2.1.0
4
+
5
+ ## refactor/perf
6
+
7
+ - Add missing frozen_string_literal comments to reduce object allocations
8
+
9
+ ## build
10
+
11
+ - Updated Rubocop to 1.18.3
12
+ - Fixed/re-enabled Rubocop
13
+ - Updated fakefs to 1.3
14
+ - Cleaned up unnecessary spec files from the Gem
15
+
16
+ Thanks for the above contributions @ericproulx! #50
17
+
3
18
  ## 2.0.0
4
19
 
5
20
  - (Maint) Remove deprecated/security release versions of Ruby. The Gem will now only support and be tested against >= 3.1.0 e.g. 3.1, 3.2, and 3.3.
6
21
 
22
+ ## 1.1.3 (Patch/Bug Fix Release)
23
+
24
+ - Fixed Man page generation bug in GH Actions
25
+
26
+ ## 1.1.1 (Patch/Bug Fix Release)
27
+
28
+ - (Maint) Updated Supported Ruby Versions (>= 2.6.9 is the earliest supported now)
29
+ - (Maint) Linting corrections
30
+ - Setup a CI system with GH Actions to do better validation of the gem before release.
31
+
7
32
  ## 1.1.0 (Minor Release)
8
33
 
34
+ :alert: This release was mis-tagged. Use 1.1.1 instead. :alert:
35
+
9
36
  - (Maint) Updated Supported Ruby Versions
10
37
  - (Maint) Linting corrections
11
38
 
12
- ## Undocumented Releases (Sorry!)
39
+ ## 1.0.0 (Major Release)
40
+
41
+ - Adds a required ruby version of 2.6 (reason for major version bump)
42
+ - Adds man/html docs
43
+
44
+ ## 0.2.1 (Patch/Bug Fix Release)
45
+
46
+ - Fixes incorrectly pushed gem on Rubygems.org
13
47
 
14
48
  ## 0.2.0 (Minor Release)
49
+
15
50
  - (Feature) A CLI tool, pathspec-rb, is now provided with the gem.
16
51
  - (API Change) New namespace for gem: `PathSpec`: Everything is now namespaced under `PathSpec`, to prevent naming collisions with other libraries. Thanks @tenderlove!
17
52
  - (License) License version updated to Apache 2. Thanks @kytrinyx!
@@ -20,20 +55,24 @@
20
55
  - (Maint) Added Rubocop and made some corrections
21
56
 
22
57
  ## 0.1.2 (Patch/Bug Fix Release)
58
+
23
59
  - Fix for regexp matching Thanks @incase! #16
24
60
  - File handling cleanup Thanks @martinandert! #13
25
61
  - `from_filename` actually works now! Thanks @martinandert! #12
26
62
 
27
63
  ## 0.1.0 (Minor Release)
64
+
28
65
  - Port new edgecase handling from [python-path-specification](https://github.com/cpburnz/python-path-specification/pull/8). Many thanks to @jdpace! :)
29
66
  - Removed EOL Ruby support
30
67
  - Added current Ruby stable to Travis testing
31
68
 
32
69
  ## 0.0.2 (Patch/Bug Fix Release)
70
+
33
71
  - Fixed issues with Ruby 1.8.7/2.1.1
34
72
  - Added more testing scripts
35
73
  - Fixed Windows path related issues
36
74
  - Cleanup unnecessary things in gem
37
75
 
38
76
  ## 0.0.1
77
+
39
78
  - Initial version.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'pathspec/regexspec'
2
4
 
3
5
  class PathSpec
@@ -87,7 +89,7 @@ class PathSpec
87
89
  end
88
90
 
89
91
  # Build regular expression from pattern.
90
- regex = '^'
92
+ regex = +'^'
91
93
  need_slash = false
92
94
  regex_end = pattern_segs.size - 1
93
95
  pattern_segs.each_index do |i|
@@ -165,7 +167,7 @@ class PathSpec
165
167
  # the POSIX function `fnmatch()` with the `FNM_PATHNAME` flag set.
166
168
 
167
169
  escape = false
168
- regex = ''
170
+ regex = +''
169
171
  i = 0
170
172
 
171
173
  while i < pattern.size
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'pathspec/spec'
2
4
 
3
5
  class PathSpec
data/lib/pathspec/spec.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class PathSpec
2
4
  # Abstract spec
3
5
  class Spec
data/lib/pathspec.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'pathspec/gitignorespec'
2
4
  require 'pathspec/regexspec'
3
5
  require 'find'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pathspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon High
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-01-16 00:00:00.000000000 Z
11
+ date: 2024-04-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.3'
33
+ version: '2.5'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '1.3'
40
+ version: '2.5'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: kramdown
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -86,14 +86,14 @@ dependencies:
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '1.7'
89
+ version: 1.63.0
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '1.7'
96
+ version: 1.63.0
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: simplecov
99
99
  requirement: !ruby/object:Gem::Requirement
@@ -126,14 +126,6 @@ files:
126
126
  - lib/pathspec/gitignorespec.rb
127
127
  - lib/pathspec/regexspec.rb
128
128
  - lib/pathspec/spec.rb
129
- - spec/files/gitignore_readme
130
- - spec/files/gitignore_ruby
131
- - spec/files/gitignore_simple
132
- - spec/files/regex_simple
133
- - spec/spec_helper.rb
134
- - spec/unit/pathspec/gitignorespec_spec.rb
135
- - spec/unit/pathspec/spec_spec.rb
136
- - spec/unit/pathspec_spec.rb
137
129
  homepage: https://github.com/highb/pathspec-ruby
138
130
  licenses:
139
131
  - Apache-2.0
@@ -159,12 +151,4 @@ rubygems_version: 3.3.26
159
151
  signing_key:
160
152
  specification_version: 4
161
153
  summary: 'PathSpec: for matching path patterns'
162
- test_files:
163
- - spec/files/gitignore_readme
164
- - spec/files/gitignore_ruby
165
- - spec/files/gitignore_simple
166
- - spec/files/regex_simple
167
- - spec/spec_helper.rb
168
- - spec/unit/pathspec/gitignorespec_spec.rb
169
- - spec/unit/pathspec/spec_spec.rb
170
- - spec/unit/pathspec_spec.rb
154
+ test_files: []
@@ -1,2 +0,0 @@
1
- !**/important.txt
2
- abc/**
@@ -1,51 +0,0 @@
1
- # Source: https://github.com/github/gitignore/blob/master/Ruby.gitignore
2
- *.gem
3
- *.rbc
4
- /.config
5
- /coverage/
6
- /InstalledFiles
7
- /pkg/
8
- /spec/reports/
9
- /spec/examples.txt
10
- /test/tmp/
11
- /test/version_tmp/
12
- /tmp/
13
-
14
- # Used by dotenv library to load environment variables.
15
- # .env
16
-
17
- ## Specific to RubyMotion:
18
- .dat*
19
- .repl_history
20
- build/
21
- *.bridgesupport
22
- build-iPhoneOS/
23
- build-iPhoneSimulator/
24
-
25
- ## Specific to RubyMotion (use of CocoaPods):
26
- #
27
- # We recommend against adding the Pods directory to your .gitignore. However
28
- # you should judge for yourself, the pros and cons are mentioned at:
29
- # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
30
- #
31
- # vendor/Pods/
32
-
33
- ## Documentation cache and generated files:
34
- /.yardoc/
35
- /_yardoc/
36
- /doc/
37
- /rdoc/
38
-
39
- ## Environment normalization:
40
- /.bundle/
41
- /vendor/bundle
42
- /lib/bundler/man/
43
-
44
- # for a library or gem, you might want to ignore these files since the code is
45
- # intended to run in multiple environments; otherwise, check them in:
46
- # Gemfile.lock
47
- # .ruby-version
48
- # .ruby-gemset
49
-
50
- # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
51
- .rvmrc
@@ -1 +0,0 @@
1
- *.md
@@ -1 +0,0 @@
1
- .*\.md
data/spec/spec_helper.rb DELETED
@@ -1,6 +0,0 @@
1
- begin
2
- require 'simplecov'
3
- SimpleCov.start
4
- rescue StandardError
5
- puts 'SimpleCov failed to start, most likely this due to running Ruby 1.8.7'
6
- end
@@ -1,303 +0,0 @@
1
- require 'spec_helper'
2
- require 'pathspec/gitignorespec'
3
-
4
- describe PathSpec::GitIgnoreSpec do
5
- # Original specification by http://git-scm.com/docs/gitignore
6
-
7
- # A blank line matches no files, so it can serve as a separator for
8
- # readability.
9
- describe 'does nothing for newlines' do
10
- subject { PathSpec::GitIgnoreSpec.new "\n" }
11
- it { is_expected.to_not match('foo.tmp') }
12
- it { is_expected.to_not match(' ') }
13
- it { is_expected.to_not be_inclusive }
14
- end
15
-
16
- describe 'does nothing for blank strings' do
17
- subject { PathSpec::GitIgnoreSpec.new '' }
18
- it { is_expected.to_not match 'foo.tmp' }
19
- it { is_expected.to_not match ' ' }
20
- it { is_expected.to_not be_inclusive }
21
- end
22
-
23
- # A line starting with # serves as a comment. Put a backslash ("\") in front
24
- # of the first hash for patterns that begin with a hash.
25
- describe 'does nothing for comments' do
26
- subject { PathSpec::GitIgnoreSpec.new '# this is a gitignore style comment' }
27
- it { is_expected.to_not match('foo.tmp') }
28
- it { is_expected.to_not match(' ') }
29
- it { is_expected.to_not be_inclusive }
30
- end
31
-
32
- describe 'ignores comment char with a slash' do
33
- subject { PathSpec::GitIgnoreSpec.new '\#averystrangefile' }
34
- it { is_expected.to match('#averystrangefile') }
35
- it { is_expected.to_not match('foobar') }
36
- it { is_expected.to be_inclusive }
37
- end
38
-
39
- describe 'escapes characters with slashes' do
40
- subject { PathSpec::GitIgnoreSpec.new 'twinkletwinkle\*' }
41
- it { is_expected.to match('twinkletwinkle*') }
42
- it { is_expected.to_not match('twinkletwinkletwinkle') }
43
- it { is_expected.to be_inclusive }
44
- end
45
-
46
- # Trailing spaces are ignored unless they are quoted with backlash ("\").
47
- describe 'ignores trailing spaces' do
48
- subject { PathSpec::GitIgnoreSpec.new 'foo ' }
49
- it { is_expected.to match('foo') }
50
- it { is_expected.to_not match('foo ') }
51
- it { is_expected.to be_inclusive }
52
- end
53
-
54
- # This is not handled properly yet
55
- describe 'does not ignore escaped trailing spaces'
56
-
57
- # An optional prefix "!" which negates the pattern; any matching file excluded
58
- # by a previous pattern will become included again. It is not possible to
59
- # re-include a file if a parent directory of that file is excluded. Git
60
- # doesn't list excluded directories for performance reasons, so any patterns
61
- # on contained files have no effect, no matter where they are defined. Put a
62
- # backslash ("\") in front of the first "!" for patterns that begin with a
63
- # literal "!", for example, "\!important!.txt".
64
- describe 'is exclusive of !' do
65
- subject { PathSpec::GitIgnoreSpec.new '!important.txt' }
66
- it { is_expected.to match('important.txt') }
67
- it { is_expected.to_not be_inclusive }
68
- it { is_expected.to_not match('!important.txt') }
69
- end
70
-
71
- # If the pattern ends with a slash, it is removed for the purpose of the
72
- # following description, but it would only find a match with a directory. In
73
- # other words, foo/ will match a directory foo and paths underneath it, but
74
- # will not match a regular file or a symbolic link foo (this is consistent
75
- # with the way how pathspec works in general in Git).
76
- describe 'trailing slashes match directories and their contents but not regular files or symlinks' do
77
- subject { PathSpec::GitIgnoreSpec.new 'foo/' }
78
- it { is_expected.to match('foo/') }
79
- it { is_expected.to match('foo/bar') }
80
- it { is_expected.to match('baz/foo/bar') }
81
- it { is_expected.to_not match('foo') }
82
- it { is_expected.to be_inclusive }
83
- end
84
-
85
- # If the pattern does not contain a slash '/', Git treats it as a shell glob
86
- # pattern and checks for a match against the pathname relative to the location
87
- # of the .gitignore file (relative to the toplevel of the work tree if not
88
- # from a .gitignore file).
89
- describe 'handles basic globbing' do
90
- subject { PathSpec::GitIgnoreSpec.new '*.tmp' }
91
- it { is_expected.to match('foo.tmp') }
92
- it { is_expected.to match('foo/bar.tmp') }
93
- it { is_expected.to match('foo/bar.tmp/baz') }
94
- it { is_expected.to_not match('foo.rb') }
95
- it { is_expected.to be_inclusive }
96
- end
97
-
98
- describe 'handles inner globs' do
99
- subject { PathSpec::GitIgnoreSpec.new 'foo-*-bar' }
100
- it { is_expected.to match('foo--bar') }
101
- it { is_expected.to match('foo-hello-bar') }
102
- it { is_expected.to match('a/foo-hello-bar') }
103
- it { is_expected.to match('foo-hello-bar/b') }
104
- it { is_expected.to match('a/foo-hello-bar/b') }
105
- it { is_expected.to_not match('foo.tmp') }
106
- end
107
-
108
- describe 'handles postfix globs' do
109
- subject { PathSpec::GitIgnoreSpec.new '~temp-*' }
110
- it { is_expected.to match('~temp-') }
111
- it { is_expected.to match('~temp-foo') }
112
- it { is_expected.to match('foo/~temp-bar') }
113
- it { is_expected.to match('foo/~temp-bar/baz') }
114
- it { is_expected.to_not match('~temp') }
115
- end
116
-
117
- describe 'handles multiple globs' do
118
- subject { PathSpec::GitIgnoreSpec.new '*.middle.*' }
119
- it { is_expected.to match('hello.middle.rb') }
120
- it { is_expected.to_not match('foo.rb') }
121
- it { is_expected.to be_inclusive }
122
- end
123
-
124
- describe 'handles dir globs' do
125
- subject { PathSpec::GitIgnoreSpec.new 'dir/*' }
126
- it { is_expected.to match('dir/foo') }
127
- it { is_expected.to_not match('foo/') }
128
- it { is_expected.to be_inclusive }
129
- end
130
-
131
- # Otherwise, Git treats the pattern as a shell glob suitable for consumption
132
- # by fnmatch(3) with the FNM_PATHNAME flag: wildcards in the pattern will not
133
- # match a / in the pathname. For example, "Documentation/*.html" matches
134
- # "Documentation/git.html" but not "Documentation/ppc/ppc.html" or
135
- # "tools/perf/Documentation/perf.html".
136
- describe 'handles dir globs' do
137
- subject { PathSpec::GitIgnoreSpec.new 'dir/*' }
138
- it { is_expected.to match('dir/foo') }
139
- it { is_expected.to_not match('foo/') }
140
- it { is_expected.to be_inclusive }
141
- end
142
-
143
- describe 'handles globs inside of dirs' do
144
- subject { PathSpec::GitIgnoreSpec.new 'Documentation/*.html' }
145
- it { is_expected.to match('Documentation/git.html') }
146
- it { is_expected.to_not match('Documentation/ppc/ppc.html') }
147
- it { is_expected.to_not match('tools/perf/Documentation/perf.html') } # TODO: Or is it? Git 2 weirdness?
148
- it { is_expected.to be_inclusive }
149
- end
150
-
151
- describe 'handles wildcards' do
152
- subject { PathSpec::GitIgnoreSpec.new 'jokeris????' }
153
- it { is_expected.to match('jokeriswild') }
154
- it { is_expected.to_not match('jokerisfat') }
155
- it { is_expected.to be_inclusive }
156
- end
157
-
158
- describe 'handles brackets' do
159
- subject { PathSpec::GitIgnoreSpec.new '*[eu][xl]*' }
160
- it { is_expected.to match('youknowregex') }
161
- it { is_expected.to match('youknowregularexpressions') }
162
- it { is_expected.to_not match('youknownothing') }
163
- it { is_expected.to be_inclusive }
164
- end
165
-
166
- describe 'handles unmatched brackets' do
167
- subject { PathSpec::GitIgnoreSpec.new '*[*[*' }
168
- it { is_expected.to match('bracket[oh[wow') }
169
- it { is_expected.to be_inclusive }
170
- end
171
-
172
- describe 'handles brackets with carats' do
173
- subject { PathSpec::GitIgnoreSpec.new '*[^]' }
174
- it { is_expected.to match('myfavorite^') }
175
- it { is_expected.to be_inclusive }
176
- end
177
-
178
- describe 'handles brackets for brackets' do
179
- subject { PathSpec::GitIgnoreSpec.new '*[]]' }
180
- it { is_expected.to match('yodawg[]]') }
181
- it { is_expected.to be_inclusive }
182
- end
183
-
184
- describe 'handles brackets with escaped characters' do
185
- # subject { GitIgnoreSpec.new 'back[\\]slash' }
186
- # it { is_expected.to match('back\\slash') }
187
- # it { is_expected.to_not match('back\\\\slash') }
188
- # it { is_expected.to be_inclusive }
189
- end
190
-
191
- describe 'handles negated brackets' do
192
- subject { PathSpec::GitIgnoreSpec.new 'ab[!cd]ef' }
193
- it { is_expected.to_not match('abcef') }
194
- it { is_expected.to match('abzef') }
195
- it { is_expected.to be_inclusive }
196
- end
197
-
198
- # A leading slash matches the beginning of the pathname. For example, "/*.c"
199
- # matches "cat-file.c" but not "mozilla-sha1/sha1.c".
200
- describe 'handles leading / as relative to base directory' do
201
- subject { PathSpec::GitIgnoreSpec.new '/*.c' }
202
- it { is_expected.to match('cat-file.c') }
203
- it { is_expected.to_not match('mozilla-sha1/sha1.c') }
204
- it { is_expected.to be_inclusive }
205
- end
206
-
207
- describe 'handles simple single paths' do
208
- subject { PathSpec::GitIgnoreSpec.new 'spam' }
209
- it { is_expected.to match('spam') }
210
- it { is_expected.to match('spam/') }
211
- it { is_expected.to match('foo/spam') }
212
- it { is_expected.to match('spam/foo') }
213
- it { is_expected.to match('foo/spam/bar') }
214
- it { is_expected.to_not match('foo') }
215
- end
216
-
217
- # Two consecutive asterisks ("**") in patterns matched against full pathname
218
- # may have special meaning:
219
-
220
- # A leading "**" followed by a slash means match in all directories. For
221
- # example, "**/foo" matches file or directory "foo" anywhere, the same as
222
- # pattern "foo". "**/foo/bar" matches file or directory "bar" anywhere that is
223
- # directly under directory "foo".
224
- describe 'handles prefixed ** as searching any location' do
225
- subject { PathSpec::GitIgnoreSpec.new '**/foo' }
226
- it { is_expected.to match('foo') }
227
- it { is_expected.to match('bar/foo') }
228
- it { is_expected.to match('baz/bar/foo') }
229
- it { is_expected.to_not match('baz/bar/foo.rb') }
230
- it { is_expected.to be_inclusive }
231
- end
232
-
233
- describe 'handles prefixed ** with a directory as searching a file under a directory in any location' do
234
- subject { PathSpec::GitIgnoreSpec.new '**/foo/bar' }
235
- it { is_expected.to_not match('foo') }
236
- it { is_expected.to match('foo/bar') }
237
- it { is_expected.to match('baz/foo/bar') }
238
- it { is_expected.to match('baz/foo/bar/sub') }
239
- it { is_expected.to_not match('baz/foo/bar.rb') }
240
- it { is_expected.to_not match('baz/bananafoo/bar') }
241
- it { is_expected.to be_inclusive }
242
- end
243
-
244
- # A trailing "/**" matches everything inside. For example, "abc/**" matches
245
- # all files inside directory "abc", relative to the location of the .gitignore
246
- # file, with infinite depth.
247
- describe 'handles leading /** as all files inside a directory' do
248
- subject { PathSpec::GitIgnoreSpec.new 'abc/**' }
249
- it { is_expected.to match('abc/') }
250
- it { is_expected.to match('abc/def') }
251
- it { is_expected.to_not match('123/abc/def') }
252
- it { is_expected.to_not match('123/456/abc/') }
253
- it { is_expected.to be_inclusive }
254
- end
255
-
256
- # A slash followed by two consecutive asterisks then a slash matches zero or
257
- # more directories. For example, "a/**/b" matches "a/b", "a/x/b", "a/x/y/b"
258
- # and so on.
259
- describe 'handles /** in the middle of a path' do
260
- subject { PathSpec::GitIgnoreSpec.new 'a/**/b' }
261
- it { is_expected.to match('a/b') }
262
- it { is_expected.to match('a/x/b') }
263
- it { is_expected.to match('a/x/y/b') }
264
- it { is_expected.to_not match('123/a/b') }
265
- it { is_expected.to_not match('123/a/x/b') }
266
- it { is_expected.to be_inclusive }
267
- end
268
-
269
- describe 'matches all paths when given **' do
270
- subject { PathSpec::GitIgnoreSpec.new '**' }
271
-
272
- it { is_expected.to match('a/b') }
273
- it { is_expected.to match('a/x/b') }
274
- it { is_expected.to match('a/x/y/b') }
275
- it { is_expected.to match('123/a/b') }
276
- it { is_expected.to match('123/a/x/b') }
277
- end
278
-
279
- # Other consecutive asterisks are considered invalid.
280
- describe 'considers other consecutive asterisks invalid' do
281
- subject { PathSpec::GitIgnoreSpec.new 'a/***/b' }
282
- it { is_expected.to_not match('a/b') }
283
- it { is_expected.to_not match('a/x/b') }
284
- it { is_expected.to_not match('a/x/y/b') }
285
- it { is_expected.to_not match('123/a/b') }
286
- it { is_expected.to_not match('123/a/x/b') }
287
- it { is_expected.to_not be_inclusive }
288
- end
289
-
290
- describe 'does not match single absolute paths' do
291
- subject { PathSpec::GitIgnoreSpec.new '/' }
292
- it { is_expected.to_not match('foo.tmp') }
293
- it { is_expected.to_not match(' ') }
294
- it { is_expected.to_not match('a/b') }
295
- end
296
-
297
- describe 'nested paths are relative to the file' do
298
- subject { PathSpec::GitIgnoreSpec.new 'foo/spam' }
299
- it { is_expected.to match('foo/spam') }
300
- it { is_expected.to match('foo/spam/bar') }
301
- it { is_expected.to_not match('bar/foo/spam') }
302
- end
303
- end
@@ -1,12 +0,0 @@
1
- require 'spec_helper'
2
- require 'pathspec/spec'
3
-
4
- describe PathSpec::Spec do
5
- subject { PathSpec::Spec.new }
6
-
7
- it 'does not allow matching' do
8
- expect { subject.match 'anything' }.to raise_error(/Unimplemented/)
9
- end
10
-
11
- it { is_expected.to be_inclusive }
12
- end
@@ -1,386 +0,0 @@
1
- require 'spec_helper'
2
- require 'fakefs/safe'
3
- require 'pathspec'
4
- require 'fakefs/spec_helpers'
5
-
6
- describe PathSpec do
7
- shared_examples 'standard gitignore negation' do
8
- it { is_expected.not_to match('important.txt') }
9
- it { is_expected.not_to match('abc/important.txt') }
10
- it { is_expected.to match('bar/baz/') }
11
- it { is_expected.to match('foo/file') }
12
- it { is_expected.not_to match('foo/important.txt') }
13
- it { is_expected.to match('foo/subdir/file') }
14
- end
15
-
16
- # Specs that should be kept up to date with the README
17
- context 'README.md' do
18
- subject { PathSpec.from_filename 'spec/files/gitignore_readme' }
19
-
20
- it { is_expected.to match('abc/def.rb') }
21
- it { is_expected.not_to match('abc/important.txt') }
22
- it do
23
- expect(subject.match_paths(['/abc/123', '/abc/important.txt', '/abc/'])).to contain_exactly(
24
- '/abc/123',
25
- '/abc/'
26
- )
27
- end
28
- end
29
-
30
- context 'initialization' do
31
- context 'from multilines' do
32
- context '#new' do
33
- subject {
34
- PathSpec.new <<-IGNORELINES
35
- !important.txt
36
- foo/**
37
- /bar/baz
38
- IGNORELINES
39
- }
40
-
41
- it_behaves_like 'standard gitignore negation'
42
- end
43
- end
44
-
45
- context 'from a string with no newlines' do
46
- let(:str) { 'foo/**' }
47
-
48
- context '#new' do
49
- subject { PathSpec.new str }
50
-
51
- it { is_expected.to match('foo/important.txt') }
52
- it { is_expected.to match('foo/bar/') }
53
- end
54
- end
55
-
56
- context 'from a non-string/non-enumerable' do
57
- it 'throws an exception' do
58
- expect { PathSpec.new Object.new }.to raise_error(/Cannot make Pathspec/)
59
- end
60
- end
61
-
62
- context 'from array of gitignore strings' do
63
- let(:arr) { ['!important.txt', 'foo/**', '/bar/baz'] }
64
-
65
- context '#new' do
66
- subject { PathSpec.new arr }
67
-
68
- it_behaves_like 'standard gitignore negation'
69
- end
70
-
71
- context '#from_lines' do
72
- subject {
73
- PathSpec.from_lines(arr)
74
- }
75
-
76
- it_behaves_like 'standard gitignore negation'
77
- end
78
-
79
- context '#add array' do
80
- subject {
81
- ps = PathSpec.new []
82
- ps.add arr
83
- }
84
-
85
- it_behaves_like 'standard gitignore negation'
86
- end
87
- end
88
-
89
- context 'from linedelimited gitignore string' do
90
- let(:line) { "!important.txt\nfoo/**\n/bar/baz\n" }
91
-
92
- context '#new' do
93
- subject { PathSpec.new line }
94
-
95
- it_behaves_like 'standard gitignore negation'
96
- end
97
-
98
- context '#from_lines' do
99
- subject {
100
- PathSpec.from_lines(line)
101
- }
102
-
103
- it_behaves_like 'standard gitignore negation'
104
- end
105
-
106
- context '#add' do
107
- subject {
108
- ps = PathSpec.new
109
- ps.add line
110
- }
111
-
112
- it_behaves_like 'standard gitignore negation'
113
- end
114
- end
115
-
116
- context 'from a gitignore file' do
117
- include FakeFS::SpecHelpers
118
-
119
- let(:filename) { '.gitignore' }
120
- before(:each) do
121
- file = File.open(filename, 'w') { |f|
122
- f << "!important.txt\n"
123
- f << "foo/**\n"
124
- f << "/bar/baz\n"
125
- }
126
- end
127
-
128
- context '#new' do
129
- subject {
130
- PathSpec.new File.open(filename, 'r')
131
- }
132
-
133
- it_behaves_like 'standard gitignore negation'
134
- end
135
-
136
- context '#from_filename' do
137
- subject {
138
- PathSpec.from_filename(filename)
139
- }
140
-
141
- it_behaves_like 'standard gitignore negation'
142
- end
143
- end
144
-
145
- context 'from multiple gitignore files' do
146
- include FakeFS::SpecHelpers
147
-
148
- let(:filenames) { ['.gitignore', '.otherignore'] }
149
- before(:each) do
150
- file = File.open('.gitignore', 'w') { |f|
151
- f << "!important.txt\n"
152
- f << "foo/**\n"
153
- f << "/bar/baz\n"
154
- }
155
-
156
- file = File.open('.otherignore', 'w') { |f|
157
- f << "ban*na\n"
158
- f << "!banana\n"
159
- }
160
- end
161
-
162
- context '#new' do
163
- subject {
164
- arr = filenames.collect { |f| File.open(f, 'r') }
165
- PathSpec.new arr
166
- }
167
-
168
- it_behaves_like 'standard gitignore negation'
169
-
170
- it { is_expected.to_not match('banana') }
171
- it { is_expected.to match('banananananana') }
172
- end
173
-
174
- context '#add' do
175
- subject {
176
- arr = filenames.collect { |f| File.open(f, 'r') }
177
- ps = PathSpec.new
178
- ps.add arr
179
- }
180
-
181
- it_behaves_like 'standard gitignore negation'
182
-
183
- it { is_expected.to_not match('banana') }
184
- it { is_expected.to match('banananananana') }
185
- end
186
- end
187
- end
188
-
189
- context '#match_tree' do
190
- include FakeFS::SpecHelpers
191
-
192
- context 'unix' do
193
- let(:root) {'/tmp/project'}
194
- let(:gitignore) {
195
- <<-GITIGNORE
196
- !**/important.txt
197
- abc/**
198
- GITIGNORE
199
- }
200
-
201
- before(:each) {
202
- FileUtils.mkdir_p root
203
- FileUtils.mkdir_p "#{root}/abc"
204
- FileUtils.touch "#{root}/abc/1"
205
- FileUtils.touch "#{root}/abc/2"
206
- FileUtils.touch "#{root}/abc/important.txt"
207
- }
208
-
209
- subject {
210
- PathSpec.new(gitignore).match_tree(root)
211
- }
212
-
213
- it { is_expected.to include "#{root}/abc".to_s }
214
- it { is_expected.to include "#{root}/abc/1".to_s }
215
- it { is_expected.not_to include "#{root}/abc/important.txt".to_s }
216
- it { is_expected.not_to include root.to_s.to_s }
217
- end
218
-
219
- context 'windows' do
220
- let(:root) {'C:/project'}
221
- let(:gitignore) {
222
- <<-GITIGNORE
223
- !**/important.txt
224
- abc/**
225
- GITIGNORE
226
- }
227
-
228
- before(:each) {
229
- FileUtils.mkdir_p root
230
- FileUtils.mkdir_p "#{root}/abc"
231
- FileUtils.touch "#{root}/abc/1"
232
- FileUtils.touch "#{root}/abc/2"
233
- FileUtils.touch "#{root}/abc/important.txt"
234
- }
235
-
236
- subject {
237
- PathSpec.new(gitignore).match_tree(root)
238
- }
239
-
240
- it { is_expected.to include "#{root}/abc".to_s }
241
- it { is_expected.to include "#{root}/abc/1".to_s }
242
- it { is_expected.not_to include "#{root}/abc/important.txt".to_s }
243
- it { is_expected.not_to include root.to_s.to_s }
244
- end
245
- end
246
-
247
- context '#match_paths' do
248
- let(:gitignore) {
249
- <<-GITIGNORE
250
- !**/important.txt
251
- /abc/**
252
- GITIGNORE
253
- }
254
-
255
- context 'with no root arg' do
256
- subject { PathSpec.new(gitignore).match_paths(['/abc/important.txt', '/abc/', '/abc/1']) }
257
-
258
- it { is_expected.to include '/abc/' }
259
- it { is_expected.to include '/abc/1' }
260
- it { is_expected.not_to include '/abc/important.txt' }
261
- end
262
-
263
- context 'relative to non-root dir' do
264
- subject {
265
- PathSpec.new(gitignore).match_paths([
266
- '/def/abc/important.txt',
267
- '/def/abc/',
268
- '/def/abc/1'
269
- ], '/def') }
270
-
271
- it { is_expected.to include '/def/abc/' }
272
- it { is_expected.to include '/def/abc/1' }
273
- it { is_expected.not_to include '/def/abc/important.txt' }
274
- end
275
-
276
- context 'relative to windows drive letter' do
277
- subject {
278
- PathSpec.new(gitignore).match_paths([
279
- 'C:/def/abc/important.txt',
280
- 'C:/def/abc/',
281
- 'C:/def/abc/1'
282
- ], 'C:/def/') }
283
-
284
- it { is_expected.to include 'C:/def/abc/' }
285
- it { is_expected.to include 'C:/def/abc/1' }
286
- it { is_expected.not_to include 'C:/def/abc/important.txt' }
287
- end
288
- end
289
-
290
- # Example to exclude everything except a specific directory foo/bar (note
291
- # the /* - without the slash, the wildcard would also exclude everything
292
- # within foo/bar): (from git-scm.com)
293
- context 'very specific gitignore' do
294
- let(:gitignore) {
295
- <<-GITIGNORE
296
- # exclude everything except directory foo/bar
297
- /*
298
- !/foo
299
- /foo/*
300
- !/foo/bar
301
- GITIGNORE
302
- }
303
-
304
- subject { PathSpec.new(gitignore) }
305
-
306
- it { is_expected.not_to match('foo/bar') }
307
- it { is_expected.to match('anything') }
308
- it { is_expected.to match('foo/otherthing') }
309
- end
310
-
311
- context '#empty' do
312
- let(:gitignore) {
313
- <<-GITIGNORE
314
- # A comment
315
- GITIGNORE
316
- }
317
-
318
- subject { PathSpec.new gitignore }
319
-
320
- it 'is empty when there are no valid lines' do
321
- expect(subject.empty?).to be true
322
- end
323
- end
324
-
325
- context 'regex file' do
326
- let(:regexfile) {
327
- <<-REGEX
328
- ab*a
329
- REGEX
330
- }
331
-
332
- subject { PathSpec.new regexfile, :regex}
333
-
334
- it 'matches the regex' do
335
- expect(subject.match('anna')).to be false
336
- expect(subject.match('abba')).to be true
337
- end
338
-
339
- context '#from_filename' do
340
- it 'forwards the type argument' do
341
- io = double
342
-
343
- expect(File).to receive(:open).and_yield(io)
344
- expect(PathSpec).to receive(:from_lines).with(io, :regex)
345
-
346
- PathSpec.from_filename '/some/file', :regex
347
- end
348
-
349
- it 'reads a simple regex file' do
350
- spec = PathSpec.from_filename 'spec/files/regex_simple', :regex
351
-
352
- expect(spec.match('artifact.md')).to be true
353
- expect(spec.match('code.rb')).to be false
354
- end
355
-
356
- it 'reads a simple gitignore file' do
357
- spec = PathSpec.from_filename 'spec/files/gitignore_simple', :git
358
-
359
- expect(spec.match('artifact.md')).to be true
360
- expect(spec.match('code.rb')).to be false
361
- end
362
-
363
- it 'reads an example ruby gitignore file' do
364
- spec = PathSpec.from_filename 'spec/files/gitignore_ruby', :git
365
-
366
- expect(spec.match('coverage/')).to be true
367
- expect(spec.match('coverage/index.html')).to be true
368
- expect(spec.match('pathspec-0.0.1.gem')).to be true
369
- expect(spec.match('lib/pathspec')).to be false
370
- expect(spec.match('Gemfile')).to be false
371
- end
372
- end
373
- end
374
-
375
- context 'unsuppored spec type' do
376
- let(:file) {
377
- <<-REGEX
378
- This is some kind of nonsense.
379
- REGEX
380
- }
381
-
382
- it 'does not allow an unknown spec type' do
383
- expect { PathSpec.new file, :foo}.to raise_error(/Unknown/)
384
- end
385
- end
386
- end