danger-spec_postfix 0.0.4 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +18 -0
- data/Gemfile.lock +1 -1
- data/README.md +29 -6
- data/danger-spec_postfix.gemspec +1 -1
- data/lib/spec_postfix/gem_version.rb +1 -1
- data/lib/spec_postfix/plugin.rb +9 -10
- data/spec/spec_postfix_spec.rb +33 -20
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: acf829f0845c574d42a1fb15cc83470b25574042efd05749ec3b533bde18dcaf
|
4
|
+
data.tar.gz: fc48c175541ec881fc91779b353201bfa7556b0a51ec4dd673db0d37724a1478
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4a629d1298c250bbcfdebb1d117a021de6760d23b6e5081110e9b36e9dc46f480eb2e449ae53fb534ceb286a71456c1ce2d2f76401719ba5df45f2fcf1c86d8d
|
7
|
+
data.tar.gz: cd7976ffc6b336ad6293dba8fc7bafe1962d85426b6833d86e245ad014c7bb2e590f07dbb80ff6f2d6263922356410f0f81578236cd79e8681146c21c1cdacbf
|
data/.gitignore
ADDED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,20 +1,43 @@
|
|
1
|
-
# danger-
|
1
|
+
# danger-spec_postfix
|
2
2
|
|
3
|
-
Danger plugin to validate
|
3
|
+
Danger plugin to validate files (or directories) naming.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
7
7
|
$ gem install danger-spec_postfix
|
8
8
|
|
9
|
-
##
|
9
|
+
## Example of usage
|
10
10
|
|
11
|
-
Add
|
11
|
+
1. Add lint to your Dangerfile (specifying what you want to check and how)
|
12
12
|
|
13
|
-
|
13
|
+
For example in order to make sure that all tests in your 'spec/' folder have required postfix '_spec' (this is the purpose plugin was initially built for) add:
|
14
|
+
|
15
|
+
```
|
16
|
+
options = {
|
17
|
+
message: 'Tests should have `_spec` postfix',
|
18
|
+
scope: %r{spec/},
|
19
|
+
match: %r{_spec.rb$}
|
20
|
+
}
|
21
|
+
spec_postfix.lint(options)
|
22
|
+
```
|
14
23
|
|
15
24
|
You can also pass `exceptions` param in order to skip irrelevant files or directories:
|
16
25
|
|
17
|
-
|
26
|
+
```
|
27
|
+
options = {
|
28
|
+
message: 'Tests should have `_spec` postfix',
|
29
|
+
scope: %r{spec/},
|
30
|
+
match: %r{_spec.rb$}
|
31
|
+
exception: Regexp.union(%r{rails_helper.rb}, %r{rails_helper.rb}, %{spec/factories/}, %r{spec/support/})
|
32
|
+
}
|
33
|
+
spec_postfix.lint(options)
|
34
|
+
```
|
35
|
+
|
36
|
+
2. Get warnings:
|
37
|
+
|
38
|
+
```
|
39
|
+
"Tests should have `_spec` postfix: spec/models/test_without_postfix.rb"
|
40
|
+
```
|
18
41
|
|
19
42
|
## Development
|
20
43
|
|
data/danger-spec_postfix.gemspec
CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.version = SpecPostfix::VERSION
|
10
10
|
spec.authors = ['Igor Udalov']
|
11
11
|
spec.email = ['i.udalov@rambler-co.ru']
|
12
|
-
spec.summary = "Danger plugin to validate
|
12
|
+
spec.summary = "Danger plugin to validate files (or directories) naming."
|
13
13
|
spec.homepage = 'https://github.com/rambler-digital-solutions/danger-spec_postfix'
|
14
14
|
spec.license = 'MIT'
|
15
15
|
|
data/lib/spec_postfix/plugin.rb
CHANGED
@@ -1,20 +1,23 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Danger
|
4
|
-
# Lints
|
4
|
+
# Lints files (or directories) naming.
|
5
5
|
# Generates a `string` with warning.
|
6
6
|
#
|
7
7
|
# @param [Array<String>] files
|
8
8
|
# A globbed string which should return the files that you want to lint, defaults to nil.
|
9
9
|
# if nil, modified and added files from the diff will be used.
|
10
|
+
# @param scope [Regexp] Scope of check
|
11
|
+
# @param match [Regexp] Pattern to match
|
12
|
+
# @param message [String] Warn message
|
13
|
+
# @param exception [Regexp] Not required. In case you want to get some directories or files out of scope.
|
10
14
|
# @return [void]
|
11
15
|
#
|
12
16
|
class DangerSpecPostfix < Plugin
|
13
|
-
def lint(
|
14
|
-
changed_files.select { |f| f.match?(
|
15
|
-
|
16
|
-
|
17
|
-
.each { |f| warn(warning_generator(f)) }
|
17
|
+
def lint(scope:, match:, message:, exception: nil)
|
18
|
+
wrong_files = changed_files.select { |f| f.match?(scope) }.reject { |f| f.match?(match) }
|
19
|
+
wrong_files = wrong_files.reject { |f| f.match?(exception) } if exception
|
20
|
+
wrong_files.each { |f| warn("#{message}: #{f}") }
|
18
21
|
end
|
19
22
|
|
20
23
|
private
|
@@ -22,9 +25,5 @@ module Danger
|
|
22
25
|
def changed_files
|
23
26
|
(git.modified_files + git.added_files)
|
24
27
|
end
|
25
|
-
|
26
|
-
def warning_generator(file)
|
27
|
-
"Tests should have `_spec` postfix: #{file}"
|
28
|
-
end
|
29
28
|
end
|
30
29
|
end
|
data/spec/spec_postfix_spec.rb
CHANGED
@@ -9,7 +9,21 @@ module Danger
|
|
9
9
|
end
|
10
10
|
|
11
11
|
describe 'with Dangerfile' do
|
12
|
-
|
12
|
+
subject do
|
13
|
+
@spec_postfix.lint(options)
|
14
|
+
@spec_postfix.status_report[:warnings]
|
15
|
+
end
|
16
|
+
|
17
|
+
let(:message) { 'Tests should have `_spec` postfix' }
|
18
|
+
let(:scope) { %r{spec/} }
|
19
|
+
let(:match) { %r{_spec.rb$} }
|
20
|
+
let(:options) do
|
21
|
+
{
|
22
|
+
message: message,
|
23
|
+
scope: scope,
|
24
|
+
match: match
|
25
|
+
}
|
26
|
+
end
|
13
27
|
|
14
28
|
before do
|
15
29
|
@spec_postfix = testing_dangerfile.spec_postfix
|
@@ -18,32 +32,31 @@ module Danger
|
|
18
32
|
allow(@spec_postfix.git).to receive(:modified_files).and_return([file_path])
|
19
33
|
end
|
20
34
|
|
21
|
-
|
22
|
-
|
23
|
-
@spec_postfix.status_report[:warnings]
|
24
|
-
end
|
25
|
-
|
26
|
-
context 'with _spec' do
|
27
|
-
let(:file_path) { 'spec/models/my_test_spec.rb' }
|
35
|
+
context 'when match' do
|
36
|
+
let(:file_path) { 'spec/some_test_spec.rb' }
|
28
37
|
|
29
38
|
it { is_expected.to be_empty }
|
30
39
|
end
|
31
40
|
|
32
|
-
context '
|
33
|
-
let(:file_path) { 'spec/
|
41
|
+
context 'when not match' do
|
42
|
+
let(:file_path) { 'spec/some_test.rb' }
|
34
43
|
|
35
|
-
it { is_expected.to eq(["
|
36
|
-
end
|
44
|
+
it { is_expected.to eq(["#{message}: #{file_path}"]) }
|
37
45
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
46
|
+
context 'with exception' do
|
47
|
+
let(:options) do
|
48
|
+
{
|
49
|
+
message: message,
|
50
|
+
scope: scope,
|
51
|
+
match: match,
|
52
|
+
exception: exception
|
53
|
+
}
|
54
|
+
end
|
55
|
+
let(:file_path) { 'spec/spec_helper.rb' }
|
56
|
+
let(:exception) { Regexp.union(%r{spec/factories}, %r{spec_helper.rb}) }
|
43
57
|
|
44
|
-
|
45
|
-
|
46
|
-
it { is_expected.to be_empty }
|
58
|
+
it { is_expected.to be_empty }
|
59
|
+
end
|
47
60
|
end
|
48
61
|
end
|
49
62
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: danger-spec_postfix
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Igor Udalov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-01-
|
11
|
+
date: 2023-01-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: danger-plugin-api
|
@@ -171,6 +171,7 @@ executables: []
|
|
171
171
|
extensions: []
|
172
172
|
extra_rdoc_files: []
|
173
173
|
files:
|
174
|
+
- ".gitignore"
|
174
175
|
- Gemfile
|
175
176
|
- Gemfile.lock
|
176
177
|
- Guardfile
|
@@ -206,7 +207,7 @@ requirements: []
|
|
206
207
|
rubygems_version: 3.1.6
|
207
208
|
signing_key:
|
208
209
|
specification_version: 4
|
209
|
-
summary: Danger plugin to validate
|
210
|
+
summary: Danger plugin to validate files (or directories) naming.
|
210
211
|
test_files:
|
211
212
|
- spec/spec_helper.rb
|
212
213
|
- spec/spec_postfix_spec.rb
|