danger-spec_postfix 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 15c7d8c52818ceb68184f56d5cd1ec453d54b074d31b002861ec124fc2bf09d0
4
+ data.tar.gz: be8b28379ac2001acc446ca49481c70ea3e812aba5dc0c1bb3213cfe7f863ec4
5
+ SHA512:
6
+ metadata.gz: e8129452944e17e50dd6821a47ec71adf77b9796cd896c5a9eb86540838dcb37586c0dd80961a5bf7a7cb95632a31799b0d393c6d996a9b89e1813d6114372a8
7
+ data.tar.gz: 2ba88f4ccc36da3eff3902f2e0c85bb72899b331ca5dbf4d9d88b74518a41679cbf2f4071bc6395f348a558c957723e46e0ef412bdcfcc10cc697a9641a82ae1
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in danger-spec_postfix.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,183 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ danger-spec_postfix (0.0.1)
5
+ danger-plugin-api (~> 1.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activesupport (7.0.4)
11
+ concurrent-ruby (~> 1.0, >= 1.0.2)
12
+ i18n (>= 1.6, < 2)
13
+ minitest (>= 5.1)
14
+ tzinfo (~> 2.0)
15
+ addressable (2.8.1)
16
+ public_suffix (>= 2.0.2, < 6.0)
17
+ ast (2.4.2)
18
+ claide (1.1.0)
19
+ claide-plugins (0.9.2)
20
+ cork
21
+ nap
22
+ open4 (~> 1.3)
23
+ coderay (1.1.3)
24
+ colored2 (3.1.2)
25
+ concurrent-ruby (1.1.10)
26
+ cork (0.3.0)
27
+ colored2 (~> 3.1)
28
+ danger (9.1.0)
29
+ claide (~> 1.0)
30
+ claide-plugins (>= 0.9.2)
31
+ colored2 (~> 3.1)
32
+ cork (~> 0.1)
33
+ faraday (>= 0.9.0, < 2.0)
34
+ faraday-http-cache (~> 2.0)
35
+ git (~> 1.7)
36
+ kramdown (~> 2.3)
37
+ kramdown-parser-gfm (~> 1.0)
38
+ no_proxy_fix
39
+ octokit (~> 5.0)
40
+ terminal-table (>= 1, < 4)
41
+ danger-plugin-api (1.0.0)
42
+ danger (> 2.0)
43
+ diff-lcs (1.5.0)
44
+ faraday (1.10.2)
45
+ faraday-em_http (~> 1.0)
46
+ faraday-em_synchrony (~> 1.0)
47
+ faraday-excon (~> 1.1)
48
+ faraday-httpclient (~> 1.0)
49
+ faraday-multipart (~> 1.0)
50
+ faraday-net_http (~> 1.0)
51
+ faraday-net_http_persistent (~> 1.0)
52
+ faraday-patron (~> 1.0)
53
+ faraday-rack (~> 1.0)
54
+ faraday-retry (~> 1.0)
55
+ ruby2_keywords (>= 0.0.4)
56
+ faraday-em_http (1.0.0)
57
+ faraday-em_synchrony (1.0.0)
58
+ faraday-excon (1.1.0)
59
+ faraday-http-cache (2.4.1)
60
+ faraday (>= 0.8)
61
+ faraday-httpclient (1.0.1)
62
+ faraday-multipart (1.0.4)
63
+ multipart-post (~> 2)
64
+ faraday-net_http (1.0.1)
65
+ faraday-net_http_persistent (1.2.0)
66
+ faraday-patron (1.0.0)
67
+ faraday-rack (1.0.0)
68
+ faraday-retry (1.0.3)
69
+ ffi (1.15.5)
70
+ formatador (1.1.0)
71
+ git (1.13.1)
72
+ addressable (~> 2.8)
73
+ rchardet (~> 1.8)
74
+ guard (2.18.0)
75
+ formatador (>= 0.2.4)
76
+ listen (>= 2.7, < 4.0)
77
+ lumberjack (>= 1.0.12, < 2.0)
78
+ nenv (~> 0.1)
79
+ notiffany (~> 0.0)
80
+ pry (>= 0.13.0)
81
+ shellany (~> 0.0)
82
+ thor (>= 0.18.1)
83
+ guard-compat (1.2.1)
84
+ guard-rspec (4.7.3)
85
+ guard (~> 2.1)
86
+ guard-compat (~> 1.1)
87
+ rspec (>= 2.99.0, < 4.0)
88
+ i18n (1.12.0)
89
+ concurrent-ruby (~> 1.0)
90
+ kramdown (2.4.0)
91
+ rexml
92
+ kramdown-parser-gfm (1.1.0)
93
+ kramdown (~> 2.0)
94
+ listen (3.0.7)
95
+ rb-fsevent (>= 0.9.3)
96
+ rb-inotify (>= 0.9.7)
97
+ lumberjack (1.2.8)
98
+ method_source (1.0.0)
99
+ minitest (5.16.3)
100
+ multipart-post (2.2.3)
101
+ nap (1.1.0)
102
+ nenv (0.3.0)
103
+ no_proxy_fix (0.1.2)
104
+ notiffany (0.1.3)
105
+ nenv (~> 0.1)
106
+ shellany (~> 0.0)
107
+ octokit (5.6.1)
108
+ faraday (>= 1, < 3)
109
+ sawyer (~> 0.9)
110
+ open4 (1.3.4)
111
+ parallel (1.22.1)
112
+ parser (3.2.0.0)
113
+ ast (~> 2.4.1)
114
+ pry (0.14.2)
115
+ coderay (~> 1.1)
116
+ method_source (~> 1.0)
117
+ public_suffix (5.0.1)
118
+ rainbow (3.1.1)
119
+ rake (10.5.0)
120
+ rb-fsevent (0.11.2)
121
+ rb-inotify (0.10.1)
122
+ ffi (~> 1.0)
123
+ rchardet (1.8.0)
124
+ regexp_parser (2.6.1)
125
+ rexml (3.2.5)
126
+ rspec (3.12.0)
127
+ rspec-core (~> 3.12.0)
128
+ rspec-expectations (~> 3.12.0)
129
+ rspec-mocks (~> 3.12.0)
130
+ rspec-core (3.12.0)
131
+ rspec-support (~> 3.12.0)
132
+ rspec-expectations (3.12.2)
133
+ diff-lcs (>= 1.2.0, < 2.0)
134
+ rspec-support (~> 3.12.0)
135
+ rspec-mocks (3.12.2)
136
+ diff-lcs (>= 1.2.0, < 2.0)
137
+ rspec-support (~> 3.12.0)
138
+ rspec-support (3.12.0)
139
+ rubocop (1.12.1)
140
+ parallel (~> 1.10)
141
+ parser (>= 3.0.0.0)
142
+ rainbow (>= 2.2.2, < 4.0)
143
+ regexp_parser (>= 1.8, < 3.0)
144
+ rexml
145
+ rubocop-ast (>= 1.2.0, < 2.0)
146
+ ruby-progressbar (~> 1.7)
147
+ unicode-display_width (>= 1.4.0, < 3.0)
148
+ rubocop-ast (1.24.1)
149
+ parser (>= 3.1.1.0)
150
+ ruby-progressbar (1.11.0)
151
+ ruby2_keywords (0.0.5)
152
+ sawyer (0.9.2)
153
+ addressable (>= 2.3.5)
154
+ faraday (>= 0.17.3, < 3)
155
+ shellany (0.0.1)
156
+ terminal-table (3.0.2)
157
+ unicode-display_width (>= 1.1.1, < 3)
158
+ thor (1.2.1)
159
+ tzinfo (2.0.5)
160
+ concurrent-ruby (~> 1.0)
161
+ unicode-display_width (2.4.2)
162
+ webrick (1.7.0)
163
+ yard (0.9.28)
164
+ webrick (~> 1.7.0)
165
+
166
+ PLATFORMS
167
+ x86_64-darwin-21
168
+
169
+ DEPENDENCIES
170
+ activesupport
171
+ bundler (~> 2.0)
172
+ danger-spec_postfix!
173
+ guard (~> 2.14)
174
+ guard-rspec (~> 4.7)
175
+ listen (= 3.0.7)
176
+ pry (~> 0.14.0)
177
+ rake (~> 10.0)
178
+ rspec (~> 3.4)
179
+ rubocop (~> 1.12.0)
180
+ yard (~> 0.9.26)
181
+
182
+ BUNDLED WITH
183
+ 2.3.12
data/Guardfile ADDED
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ # A guardfile for making Danger Plugins
4
+ # For more info see https://github.com/guard/guard#readme
5
+
6
+ # To run, use `bundle exec guard`.
7
+
8
+ guard :rspec, cmd: 'bundle exec rspec' do
9
+ require 'guard/rspec/dsl'
10
+ dsl = Guard::RSpec::Dsl.new(self)
11
+
12
+ # RSpec files
13
+ rspec = dsl.rspec
14
+ watch(rspec.spec_helper) { rspec.spec_dir }
15
+ watch(rspec.spec_support) { rspec.spec_dir }
16
+ watch(rspec.spec_files)
17
+
18
+ # Ruby files
19
+ ruby = dsl.ruby
20
+ dsl.watch_spec_files_for(ruby.lib_files)
21
+ end
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Rambler Digital Solutions
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2021 Mikhail Georgievskiy <m.georgievskiy@rambler-co.ru>
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # danger-readme_docs
2
+
3
+ Danger plugin to validate sub README mention in main README file
4
+
5
+ ## Installation
6
+
7
+ $ gem install danger-spec_postfix
8
+
9
+ ## Usage
10
+
11
+ Add this to your Dangerfile:
12
+
13
+ spec_postfix.lint
14
+
15
+ ## Configuration
16
+
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
24
+
25
+ ## Development
26
+
27
+ 1. Clone this repo
28
+ 2. Run `bundle install` to setup dependencies.
29
+ 3. Run `bundle exec rake spec` to run the tests.
30
+ 4. Use `bundle exec guard` to automatically have tests run as you make changes.
31
+ 5. Make your changes.
data/Rakefile ADDED
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+ require 'rubocop/rake_task'
6
+
7
+ RSpec::Core::RakeTask.new(:specs)
8
+
9
+ task default: :specs
10
+
11
+ task spec: :environment do
12
+ Rake::Task['specs'].invoke
13
+ Rake::Task['rubocop'].invoke
14
+ Rake::Task['spec_docs'].invoke
15
+ end
16
+
17
+ desc 'Run RuboCop on the lib/specs directory'
18
+ RuboCop::RakeTask.new(:rubocop) do |task|
19
+ task.patterns = ['lib/**/*.rb', 'spec/**/*.rb']
20
+ end
21
+
22
+ desc 'Ensure that the plugin passes `danger plugins lint`'
23
+ task spec_docs: :environment do
24
+ sh 'bundle exec danger plugins lint'
25
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'spec_postfix/gem_version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'danger-spec_postfix'
9
+ spec.version = SpecPostfix::VERSION
10
+ spec.authors = ['Igor Udalov']
11
+ spec.email = ['i.udalov@rambler-co.ru']
12
+ spec.summary = "Danger plugin to validate '_spec' postfix in tests"
13
+ spec.homepage = 'https://github.com/rambler-digital-solutions/danger-spec_postfix'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.required_ruby_version = '>= 2.6'
22
+
23
+ spec.add_runtime_dependency 'danger-plugin-api', '~> 1.0'
24
+
25
+ # General ruby development
26
+ spec.add_development_dependency 'bundler', '~> 2.0'
27
+ spec.add_development_dependency 'rake', '~> 10.0'
28
+
29
+ # Testing support
30
+ spec.add_development_dependency 'rspec', '~> 3.4'
31
+
32
+ # Linting code and docs
33
+ spec.add_development_dependency 'rubocop', '~> 1.12.0'
34
+ spec.add_development_dependency 'yard', '~> 0.9.26'
35
+
36
+ # Makes testing easy via `bundle exec guard`
37
+ spec.add_development_dependency 'guard', '~> 2.14'
38
+ spec.add_development_dependency 'guard-rspec', '~> 4.7'
39
+
40
+ # If you want to work on older builds of ruby
41
+ spec.add_development_dependency 'listen', '3.0.7'
42
+
43
+ spec.add_development_dependency 'activesupport'
44
+ # This gives you the chance to run a REPL inside your tests
45
+ # via:
46
+ #
47
+ # require 'pry'
48
+ # binding.pry
49
+ #
50
+ # This will stop test execution and let you inspect the results
51
+ spec.add_development_dependency 'pry', '~> 0.14.0'
52
+ end
data/danger_plugin.rb ADDED
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_postfix/plugin'
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_postfix/gem_version'
data/gem_version.rb ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SpecPostfix
4
+ VERSION = '0.0.1'
5
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_postfix/plugin'
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_postfix/gem_version'
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SpecPostfix
4
+ VERSION = '0.0.1'
5
+ end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support/configurable'
4
+
5
+ module Danger
6
+ # Check that all test files in spec/ folder have `_spec` postfix.
7
+ # Results are passed out as a string with warning.
8
+ #
9
+ # @example Running linter
10
+ #
11
+ # # Runs a linter
12
+ # spec_postfix.lint
13
+ #
14
+ class DangerSpecPostfix < Plugin
15
+ # Lints the test files. Will fail if any has no '_spec' postfix.
16
+ # Generates a `string` with warning.
17
+ #
18
+ # @param [String] files
19
+ # A globbed string which should return the files that you want to lint, defaults to nil.
20
+ # if nil, modified and added files from the diff will be used.
21
+ # @return [void]
22
+ #
23
+ def self.configuration
24
+ @configuration ||= Configuration.new
25
+ end
26
+
27
+ def self.configure
28
+ yield configuration
29
+ end
30
+
31
+ def lint
32
+ changed_files.select { |f| f.match?(%r{^spec/.*rb$}) }
33
+ .reject { |f| f.end_with?('_spec.rb') }
34
+ .reject { |f| DangerSpecPostfix.configuration.exceptions.any? { |e| f.start_with?(e) } }
35
+ .each { |f| warn(warning_generator(f)) }
36
+ end
37
+
38
+ private
39
+
40
+ def changed_files
41
+ (git.modified_files + git.added_files)
42
+ end
43
+
44
+ def warning_generator(file)
45
+ "Tests should have `_spec` postfix: #{file}"
46
+ end
47
+ end
48
+
49
+ class DangerSpecPostfix::Configuration
50
+ include ::ActiveSupport::Configurable
51
+
52
+ config_accessor(:exceptions) { ['spec/shared_examples/', 'spec/factories/', 'spec/support/', 'spec/rails_helper.rb', 'spec/spec_helper.rb'] }
53
+ end
54
+ end
data/plugin.rb ADDED
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support/configurable'
4
+
5
+ module Danger
6
+ # Check that all test files in spec/ folder have `_spec` postfix.
7
+ # Results are passed out as a string with warning.
8
+ #
9
+ # @example Running linter
10
+ #
11
+ # # Runs a linter
12
+ # spec_postfix.lint
13
+ #
14
+ class DangerSpecPostfix < Plugin
15
+ # Lints the test files. Will fail if any has no '_spec' postfix.
16
+ # Generates a `string` with warning.
17
+ #
18
+ # @param [String] files
19
+ # A globbed string which should return the files that you want to lint, defaults to nil.
20
+ # if nil, modified and added files from the diff will be used.
21
+ # @return [void]
22
+ #
23
+ def self.configuration
24
+ @configuration ||= Configuration.new
25
+ end
26
+
27
+ def self.configure
28
+ yield configuration
29
+ end
30
+
31
+ def lint
32
+ changed_files.select { |f| f.match?(%r{^spec/.*rb$}) }
33
+ .reject { |f| f.end_with?('_spec.rb') }
34
+ .reject { |f| DangerSpecPostfix.configuration.exceptions.any? { |e| f.start_with?(e) } }
35
+ .each { |f| warn(warning_generator(f)) }
36
+ end
37
+
38
+ private
39
+
40
+ def changed_files
41
+ (git.modified_files + git.added_files)
42
+ end
43
+
44
+ def warning_generator(file)
45
+ "Tests should have `_spec` postfix: #{file}"
46
+ end
47
+ end
48
+
49
+ class DangerSpecPostfix::Configuration
50
+ include ::ActiveSupport::Configurable
51
+
52
+ config_accessor(:exceptions) { ['spec/shared_examples/', 'spec/factories/', 'spec/support/', 'spec/rails_helper.rb', 'spec/spec_helper.rb'] }
53
+ end
54
+ end
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'pathname'
4
+ ROOT = Pathname.new(File.expand_path('..', __dir__))
5
+ $:.unshift("#{ROOT}lib")
6
+ $:.unshift("#{ROOT}spec")
7
+
8
+ require 'bundler/setup'
9
+ require 'pry'
10
+
11
+ require 'rspec'
12
+ require 'danger'
13
+
14
+ if `git remote -v` == ''
15
+ puts 'You cannot run tests without setting a local git remote on this repo'
16
+ puts "It's a weird side-effect of Danger's internals."
17
+ exit(0)
18
+ end
19
+
20
+ # Use coloured output, it's the best.
21
+ RSpec.configure do |config|
22
+ config.filter_gems_from_backtrace 'bundler'
23
+ config.color = true
24
+ config.tty = true
25
+ end
26
+
27
+ require 'danger_plugin'
28
+
29
+ # These functions are a subset of https://github.com/danger/danger/blob/master/spec/spec_helper.rb
30
+ # If you are expanding these files, see if it's already been done ^.
31
+
32
+ # A silent version of the user interface,
33
+ # it comes with an extra function `.string` which will
34
+ # strip all ANSI colours from the string.
35
+
36
+ # rubocop:disable Lint/NestedMethodDefinition
37
+ def testing_ui
38
+ @output = StringIO.new
39
+ def @output.winsize
40
+ [20, 9999]
41
+ end
42
+
43
+ cork = Cork::Board.new(out: @output)
44
+ def cork.string
45
+ out.string.gsub(/\e\[([;\d]+)?m/, '')
46
+ end
47
+ cork
48
+ end
49
+ # rubocop:enable Lint/NestedMethodDefinition
50
+
51
+ # Example environment (ENV) that would come from
52
+ # running a PR on TravisCI
53
+ def testing_env
54
+ {
55
+ 'HAS_JOSH_K_SEAL_OF_APPROVAL' => 'true',
56
+ 'TRAVIS_PULL_REQUEST' => '800',
57
+ 'TRAVIS_REPO_SLUG' => 'artsy/eigen',
58
+ 'TRAVIS_COMMIT_RANGE' => '759adcbd0d8f...13c4dc8bb61d',
59
+ 'DANGER_GITHUB_API_TOKEN' => '123sbdq54erfsd3422gdfio'
60
+ }
61
+ end
62
+
63
+ # A stubbed out Dangerfile for use in tests
64
+ def testing_dangerfile
65
+ env = Danger::EnvironmentManager.new(testing_env)
66
+ Danger::Dangerfile.new(env, testing_ui)
67
+ end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ require File.expand_path('spec_helper', __dir__)
4
+
5
+ module Danger
6
+ describe Danger::DangerSpecPostfix do
7
+ it 'is a plugin' do
8
+ expect(described_class.new(nil)).to be_a Danger::Plugin
9
+ end
10
+
11
+ describe 'with Dangerfile' do
12
+ let(:file_path) { nil }
13
+
14
+ before do
15
+ @spec_postfix = testing_dangerfile.spec_postfix
16
+
17
+ allow(@spec_postfix.git).to receive(:added_files).and_return([])
18
+ allow(@spec_postfix.git).to receive(:modified_files).and_return([file_path])
19
+ end
20
+
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' }
28
+
29
+ it { is_expected.to be_empty }
30
+ end
31
+
32
+ context 'with no _spec' do
33
+ let(:file_path) { 'spec/models/my_test.rb' }
34
+
35
+ it { is_expected.to eq(["Tests should have `_spec` postfix: #{file_path}"]) }
36
+ end
37
+
38
+ context 'when is irrelevant (exceptions)' do
39
+ before do
40
+ described_class.configure do |config|
41
+ config.exceptions = 'not_tests/'
42
+ end
43
+ end
44
+
45
+ let(:file_path) { 'not_tests/factory.rb' }
46
+
47
+ it { is_expected.to be_empty }
48
+ end
49
+ end
50
+ end
51
+ end
data/spec_helper.rb ADDED
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'pathname'
4
+ ROOT = Pathname.new(File.expand_path('..', __dir__))
5
+ $:.unshift("#{ROOT}lib")
6
+ $:.unshift("#{ROOT}spec")
7
+
8
+ require 'bundler/setup'
9
+ require 'pry'
10
+
11
+ require 'rspec'
12
+ require 'danger'
13
+
14
+ if `git remote -v` == ''
15
+ puts 'You cannot run tests without setting a local git remote on this repo'
16
+ puts "It's a weird side-effect of Danger's internals."
17
+ exit(0)
18
+ end
19
+
20
+ # Use coloured output, it's the best.
21
+ RSpec.configure do |config|
22
+ config.filter_gems_from_backtrace 'bundler'
23
+ config.color = true
24
+ config.tty = true
25
+ end
26
+
27
+ require 'danger_plugin'
28
+
29
+ # These functions are a subset of https://github.com/danger/danger/blob/master/spec/spec_helper.rb
30
+ # If you are expanding these files, see if it's already been done ^.
31
+
32
+ # A silent version of the user interface,
33
+ # it comes with an extra function `.string` which will
34
+ # strip all ANSI colours from the string.
35
+
36
+ # rubocop:disable Lint/NestedMethodDefinition
37
+ def testing_ui
38
+ @output = StringIO.new
39
+ def @output.winsize
40
+ [20, 9999]
41
+ end
42
+
43
+ cork = Cork::Board.new(out: @output)
44
+ def cork.string
45
+ out.string.gsub(/\e\[([;\d]+)?m/, '')
46
+ end
47
+ cork
48
+ end
49
+ # rubocop:enable Lint/NestedMethodDefinition
50
+
51
+ # Example environment (ENV) that would come from
52
+ # running a PR on TravisCI
53
+ def testing_env
54
+ {
55
+ 'HAS_JOSH_K_SEAL_OF_APPROVAL' => 'true',
56
+ 'TRAVIS_PULL_REQUEST' => '800',
57
+ 'TRAVIS_REPO_SLUG' => 'artsy/eigen',
58
+ 'TRAVIS_COMMIT_RANGE' => '759adcbd0d8f...13c4dc8bb61d',
59
+ 'DANGER_GITHUB_API_TOKEN' => '123sbdq54erfsd3422gdfio'
60
+ }
61
+ end
62
+
63
+ # A stubbed out Dangerfile for use in tests
64
+ def testing_dangerfile
65
+ env = Danger::EnvironmentManager.new(testing_env)
66
+ Danger::Dangerfile.new(env, testing_ui)
67
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SpecPostfix
4
+ VERSION = '0.0.1'
5
+ end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support/configurable'
4
+
5
+ module Danger
6
+ # Check that all test files in spec/ folder have `_spec` postfix.
7
+ # Results are passed out as a string with warning.
8
+ #
9
+ # @example Running linter
10
+ #
11
+ # # Runs a linter
12
+ # spec_postfix.lint
13
+ #
14
+ class DangerSpecPostfix < Plugin
15
+ # Lints the test files. Will fail if any has no '_spec' postfix.
16
+ # Generates a `string` with warning.
17
+ #
18
+ # @param [String] files
19
+ # A globbed string which should return the files that you want to lint, defaults to nil.
20
+ # if nil, modified and added files from the diff will be used.
21
+ # @return [void]
22
+ #
23
+ def self.configuration
24
+ @configuration ||= Configuration.new
25
+ end
26
+
27
+ def self.configure
28
+ yield configuration
29
+ end
30
+
31
+ def lint
32
+ changed_files.select { |f| f.match?(%r{^spec/.*rb$}) }
33
+ .reject { |f| f.end_with?('_spec.rb') }
34
+ .reject { |f| DangerSpecPostfix.configuration.exceptions.any? { |e| f.start_with?(e) } }
35
+ .each { |f| warn(warning_generator(f)) }
36
+ end
37
+
38
+ private
39
+
40
+ def changed_files
41
+ (git.modified_files + git.added_files)
42
+ end
43
+
44
+ def warning_generator(file)
45
+ "Tests should have `_spec` postfix: #{file}"
46
+ end
47
+ end
48
+
49
+ class DangerSpecPostfix::Configuration
50
+ include ::ActiveSupport::Configurable
51
+
52
+ config_accessor(:exceptions) { ['spec/shared_examples/', 'spec/factories/', 'spec/support/', 'spec/rails_helper.rb', 'spec/spec_helper.rb'] }
53
+ end
54
+ end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ require File.expand_path('spec_helper', __dir__)
4
+
5
+ module Danger
6
+ describe Danger::DangerSpecPostfix do
7
+ it 'is a plugin' do
8
+ expect(described_class.new(nil)).to be_a Danger::Plugin
9
+ end
10
+
11
+ describe 'with Dangerfile' do
12
+ let(:file_path) { nil }
13
+
14
+ before do
15
+ @spec_postfix = testing_dangerfile.spec_postfix
16
+
17
+ allow(@spec_postfix.git).to receive(:added_files).and_return([])
18
+ allow(@spec_postfix.git).to receive(:modified_files).and_return([file_path])
19
+ end
20
+
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' }
28
+
29
+ it { is_expected.to be_empty }
30
+ end
31
+
32
+ context 'with no _spec' do
33
+ let(:file_path) { 'spec/models/my_test.rb' }
34
+
35
+ it { is_expected.to eq(["Tests should have `_spec` postfix: #{file_path}"]) }
36
+ end
37
+
38
+ context 'when is irrelevant (exceptions)' do
39
+ before do
40
+ described_class.configure do |config|
41
+ config.exceptions = 'not_tests/'
42
+ end
43
+ end
44
+
45
+ let(:file_path) { 'not_tests/factory.rb' }
46
+
47
+ it { is_expected.to be_empty }
48
+ end
49
+ end
50
+ end
51
+ end
metadata ADDED
@@ -0,0 +1,221 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: danger-spec_postfix
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Igor Udalov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-01-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: danger-plugin-api
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.4'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.4'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 1.12.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 1.12.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: yard
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.9.26
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.9.26
97
+ - !ruby/object:Gem::Dependency
98
+ name: guard
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '2.14'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '2.14'
111
+ - !ruby/object:Gem::Dependency
112
+ name: guard-rspec
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '4.7'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '4.7'
125
+ - !ruby/object:Gem::Dependency
126
+ name: listen
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - '='
130
+ - !ruby/object:Gem::Version
131
+ version: 3.0.7
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - '='
137
+ - !ruby/object:Gem::Version
138
+ version: 3.0.7
139
+ - !ruby/object:Gem::Dependency
140
+ name: activesupport
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: pry
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: 0.14.0
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: 0.14.0
167
+ description:
168
+ email:
169
+ - i.udalov@rambler-co.ru
170
+ executables: []
171
+ extensions: []
172
+ extra_rdoc_files: []
173
+ files:
174
+ - Gemfile
175
+ - Gemfile.lock
176
+ - Guardfile
177
+ - LICENSE
178
+ - LICENSE.txt
179
+ - README.md
180
+ - Rakefile
181
+ - danger-spec_postfix.gemspec
182
+ - danger_plugin.rb
183
+ - danger_spec_postfix.rb
184
+ - gem_version.rb
185
+ - lib/danger_plugin.rb
186
+ - lib/danger_spec_postfix.rb
187
+ - lib/spec_postfix/gem_version.rb
188
+ - lib/spec_postfix/plugin.rb
189
+ - plugin.rb
190
+ - spec/spec_helper.rb
191
+ - spec/spec_postfix_spec.rb
192
+ - spec_helper.rb
193
+ - spec_postfix/gem_version.rb
194
+ - spec_postfix/plugin.rb
195
+ - spec_postfix_spec.rb
196
+ homepage: https://github.com/rambler-digital-solutions/danger-spec_postfix
197
+ licenses:
198
+ - MIT
199
+ metadata: {}
200
+ post_install_message:
201
+ rdoc_options: []
202
+ require_paths:
203
+ - lib
204
+ required_ruby_version: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - ">="
207
+ - !ruby/object:Gem::Version
208
+ version: '2.6'
209
+ required_rubygems_version: !ruby/object:Gem::Requirement
210
+ requirements:
211
+ - - ">="
212
+ - !ruby/object:Gem::Version
213
+ version: '0'
214
+ requirements: []
215
+ rubygems_version: 3.1.6
216
+ signing_key:
217
+ specification_version: 4
218
+ summary: Danger plugin to validate '_spec' postfix in tests
219
+ test_files:
220
+ - spec/spec_helper.rb
221
+ - spec/spec_postfix_spec.rb