pathspec 0.0.2 → 1.0.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.
@@ -0,0 +1,386 @@
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
metadata CHANGED
@@ -1,61 +1,144 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pathspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon High
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-11 00:00:00.000000000 Z
11
+ date: 2018-01-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '2.2'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: '2.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: fakefs
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: kramdown
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '13.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '13.0'
27
69
  - !ruby/object:Gem::Dependency
28
70
  name: rspec
29
71
  requirement: !ruby/object:Gem::Requirement
30
72
  requirements:
31
- - - ">="
73
+ - - "~>"
32
74
  - !ruby/object:Gem::Version
33
- version: '0'
75
+ version: '3.10'
34
76
  type: :development
35
77
  prerelease: false
36
78
  version_requirements: !ruby/object:Gem::Requirement
37
79
  requirements:
38
- - - ">="
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.10'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
39
88
  - !ruby/object:Gem::Version
40
- version: '0'
89
+ version: '1.7'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.7'
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.21'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.21'
41
111
  description: Use to match path patterns such as gitignore
42
- email: bh@brandon-high.com
43
- executables: []
112
+ email: highb@users.noreply.github.com
113
+ executables:
114
+ - pathspec-rb
44
115
  extensions: []
45
116
  extra_rdoc_files: []
46
117
  files:
47
118
  - CHANGELOG.md
48
119
  - LICENSE
49
120
  - README.md
121
+ - bin/pathspec-rb
122
+ - docs/html/pathspec-rb.html
123
+ - docs/man/pathspec-rb.man.1
124
+ - docs/pathspec-rb.md
50
125
  - lib/pathspec.rb
51
126
  - lib/pathspec/gitignorespec.rb
52
127
  - lib/pathspec/regexspec.rb
53
128
  - lib/pathspec/spec.rb
54
- homepage: http://rubygems.org/gems/pathspec
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
+ homepage: https://github.com/highb/pathspec-ruby
55
138
  licenses:
56
- - Apache
139
+ - Apache-2.0
57
140
  metadata: {}
58
- post_install_message:
141
+ post_install_message:
59
142
  rdoc_options: []
60
143
  require_paths:
61
144
  - lib
@@ -63,16 +146,23 @@ required_ruby_version: !ruby/object:Gem::Requirement
63
146
  requirements:
64
147
  - - ">="
65
148
  - !ruby/object:Gem::Version
66
- version: '0'
149
+ version: 2.6.0
67
150
  required_rubygems_version: !ruby/object:Gem::Requirement
68
151
  requirements:
69
152
  - - ">="
70
153
  - !ruby/object:Gem::Version
71
154
  version: '0'
72
155
  requirements: []
73
- rubyforge_project:
74
- rubygems_version: 2.2.2
75
- signing_key:
156
+ rubygems_version: 3.1.4
157
+ signing_key:
76
158
  specification_version: 4
77
159
  summary: 'PathSpec: for matching path patterns'
78
- test_files: []
160
+ test_files:
161
+ - spec/files/gitignore_readme
162
+ - spec/files/gitignore_ruby
163
+ - spec/files/gitignore_simple
164
+ - spec/files/regex_simple
165
+ - spec/spec_helper.rb
166
+ - spec/unit/pathspec/gitignorespec_spec.rb
167
+ - spec/unit/pathspec/spec_spec.rb
168
+ - spec/unit/pathspec_spec.rb