danger-spec_postfix 0.0.3 → 0.0.5

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: d7013f18e0074dbc9108182afd4409ee9457760bcf0114a3a107c4fc448ac2a3
4
- data.tar.gz: 4530c9d8fdc42da2af6dc6d68e01f213fbb71b3c4fe536b182859e1f4addcb1c
3
+ metadata.gz: f994553adae976417f7e7b521b26896c1268ea3a84b33a0f194bea84cc3b1575
4
+ data.tar.gz: 8bd8f8b3c83d9f5cb819e8d903034ae60e5327ead7e8b86a3f456c017b4ad1db
5
5
  SHA512:
6
- metadata.gz: 4989e8df6156ddec96e0ec46563fe823a162449de773e6f6a69e3bcde7e2fd2475c26a20ce100cd3fcad8d54025fb7c9bfc78357a13add250c04897fd9f642fe
7
- data.tar.gz: 825eaf57bc666f914692af8879725ab03becca562a71aad50751b8f0a856e7e7b3eff3b60e1bcd7e8966139542cb2bfa6ef26cead6974bbac9b02e4c05336bd1
6
+ metadata.gz: 7896330e819c4184977dc42df31fccfd4e5ca336b99a76be90eaa0a1cd78888e9ae860ba3b6f3fc3ad4e8ffc393cecbb749820011801acbe1ae09dc1c06fd18d
7
+ data.tar.gz: 1e42be75ca36f539a36d73dfc4c40c1237202d0ff38155fdd0beef76f81f606242852b6ddbbb924cafbf74e3445927da1da470fe9c8f1bca2a595c401985d34a
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- danger-spec_postfix (0.0.3)
4
+ danger-spec_postfix (0.0.5)
5
5
  danger-plugin-api (~> 1.0)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -1,26 +1,31 @@
1
- # danger-readme_docs
1
+ # danger-spec_postfix
2
2
 
3
- Danger plugin to validate sub README mention in main README file
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
- ## Usage
9
+ ## Example of usage
10
10
 
11
- Add this to your Dangerfile:
11
+ Add to your Dangerfile:
12
12
 
13
- spec_postfix.lint
13
+ options = {
14
+ message: 'Tests should have `_spec` postfix',
15
+ scope: %r{spec/},
16
+ match: %r{_spec.rb$}
17
+ }
18
+ spec_postfix.lint(options)
14
19
 
15
- ## Configuration
20
+ You can also pass `exceptions` param in order to skip irrelevant files or directories:
16
21
 
17
- By default some of files and folders are out of scope. You can configure your own custom list of exceptions.
18
-
19
- #config/initializers/danger/danger_spec_postfix.rb
20
-
21
- Danger::DangerSpecPostfix.configure do |config|
22
- config.exceptions = ['rails_helper.rb', 'rails_helper.rb']
23
- end
22
+ options = {
23
+ message: 'Tests should have `_spec` postfix',
24
+ scope: %r{spec/},
25
+ match: %r{_spec.rb$}
26
+ exception: Regexp.union(%r{rails_helper.rb}, %r{rails_helper.rb}, %{spec/factories/}, %r{spec/support/})
27
+ }
28
+ spec_postfix.lint(options)
24
29
 
25
30
  ## Development
26
31
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SpecPostfix
4
- VERSION = '0.0.3'
4
+ VERSION = '0.0.5'
5
5
  end
@@ -4,17 +4,20 @@ module Danger
4
4
  # Lints the test files. Will fail if any has no '_spec' postfix.
5
5
  # Generates a `string` with warning.
6
6
  #
7
- # @param [String] files
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 get some directories or files out of scope.
10
14
  # @return [void]
11
15
  #
12
16
  class DangerSpecPostfix < Plugin
13
- def lint(exceptions: [])
14
- changed_files.select { |f| f.match?(%r{^spec/.*rb$}) }
15
- .reject { |f| f.end_with?('_spec.rb') }
16
- .reject { |f| exceptions.any? { |e| f.start_with?(e) } }
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
@@ -9,7 +9,21 @@ module Danger
9
9
  end
10
10
 
11
11
  describe 'with Dangerfile' do
12
- let(:file_path) { nil }
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
- subject do
22
- @spec_postfix.lint
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 'with no _spec' do
33
- let(:file_path) { 'spec/models/my_test.rb' }
41
+ context 'when not match' do
42
+ let(:file_path) { 'spec/some_test.rb' }
34
43
 
35
- it { is_expected.to eq(["Tests should have `_spec` postfix: #{file_path}"]) }
36
- end
44
+ it { is_expected.to eq(["#{message}: #{file_path}"]) }
37
45
 
38
- context 'when is irrelevant (exceptions)' do
39
- subject do
40
- @spec_postfix.lint(exceptions: ['not_tests/'])
41
- @spec_postfix.status_report[:warnings]
42
- end
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
- let(:file_path) { 'not_tests/factory.rb' }
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,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: danger-spec_postfix
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Igor Udalov