rubocop-config-captive 2.2.1 → 2.3.1
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.
- checksums.yaml +4 -4
- data/Gemfile +4 -0
- data/config/__private__/rubocop-lint.yml +1 -1
- data/config/rubocop-captive.yml +16 -0
- data/lib/rubocop/captive/version.rb +1 -1
- data/lib/rubocop/cop/captive/rspec/no_db_in_unit_specs.rb +66 -0
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0c8513544ecc3a95a4dd8315e0b9096386168107c8acf6dd03705748ff69eb69
|
|
4
|
+
data.tar.gz: 80beab80c12d93db9d69652be8dd48a0c631beb87abbcd11f4d5fcf8526c76d4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6e1fdab22010877255fa49451feee1502974f520c6e9d450b3d5e087c86fb53339e553a6a2bb2c07600fe18e127f7a31cfd2f862b340db0c54a9afd9fd757a06
|
|
7
|
+
data.tar.gz: 573648923949ed27dfc0fa32b979ef66ccbc218bf9353724616ddd584a1d5e10b270e67c616befbb192f8d70428f28260a7d18a5606be49c25fc49430fcaee51
|
data/Gemfile
CHANGED
data/config/rubocop-captive.yml
CHANGED
|
@@ -4,6 +4,7 @@ require:
|
|
|
4
4
|
- ../lib/rubocop/cop/captive/translation/rails_i18n_presence.rb
|
|
5
5
|
- ../lib/rubocop/cop/captive/translation/kaminari_i18n_presence.rb
|
|
6
6
|
- ../lib/rubocop/cop/captive/rspec/specify_before_parameter.rb
|
|
7
|
+
- ../lib/rubocop/cop/captive/rspec/no_db_in_unit_specs.rb
|
|
7
8
|
- ../lib/rubocop/cop/captive/rails/after_commit_not_allowed.rb
|
|
8
9
|
- ../lib/rubocop/cop/captive/rails/force_ssl_enabled_in_production.rb
|
|
9
10
|
- ../lib/rubocop/cop/captive/rails/migration_methods.rb
|
|
@@ -43,6 +44,21 @@ Captive/RSpec/SpecifyBeforeParameter:
|
|
|
43
44
|
Include:
|
|
44
45
|
- 'spec/**/*'
|
|
45
46
|
|
|
47
|
+
Captive/RSpec/NoDbInUnitSpecs:
|
|
48
|
+
Description: 'Do not hit the database in unit tests. Use `instance_double` or `Model.new` instead. If testing a scope, move to spec/integration.'
|
|
49
|
+
Enabled: true
|
|
50
|
+
Include:
|
|
51
|
+
- 'spec/**/*'
|
|
52
|
+
AllowedPaths:
|
|
53
|
+
- 'spec/requests'
|
|
54
|
+
- 'spec/system'
|
|
55
|
+
- 'spec/features'
|
|
56
|
+
- 'spec/integration'
|
|
57
|
+
- 'spec/factories'
|
|
58
|
+
- 'spec/services'
|
|
59
|
+
- 'spec/jobs'
|
|
60
|
+
- 'spec/support'
|
|
61
|
+
|
|
46
62
|
# Rails
|
|
47
63
|
Captive/Rails/AfterCommitNotAllowed:
|
|
48
64
|
Description: "Interdit l'utilisation de `after_commit` dans les modèles Rails."
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module RuboCop
|
|
4
|
+
module Cop
|
|
5
|
+
module Captive
|
|
6
|
+
module RSpec
|
|
7
|
+
# Do not create database records in unit tests.
|
|
8
|
+
# Use `build`, `instance_double`, or stubs instead.
|
|
9
|
+
class NoDbInUnitSpecs < Base
|
|
10
|
+
MSG =
|
|
11
|
+
"Do not hit the database in unit tests. " \
|
|
12
|
+
"Use `instance_double` or `Model.new` instead. " \
|
|
13
|
+
"If testing a scope, move to spec/integration."
|
|
14
|
+
|
|
15
|
+
DEFAULT_ALLOWED_PATHS = %w[
|
|
16
|
+
spec/requests spec/system spec/features spec/integration
|
|
17
|
+
spec/factories spec/services spec/jobs spec/support
|
|
18
|
+
].freeze
|
|
19
|
+
|
|
20
|
+
def_node_matcher :factory_bot_db?, <<~PATTERN
|
|
21
|
+
(send (const nil? :FactoryBot) {:create :create_list :create_pair :build :build_list :build_pair :build_stubbed :build_stubbed_list} ...)
|
|
22
|
+
PATTERN
|
|
23
|
+
|
|
24
|
+
def_node_matcher :standalone_factory_bot_db?, <<~PATTERN
|
|
25
|
+
(send nil? {:create :create_list :create_pair :build :build_list :build_pair :build_stubbed :build_stubbed_list} ...)
|
|
26
|
+
PATTERN
|
|
27
|
+
|
|
28
|
+
def_node_matcher :ar_create?, <<~PATTERN
|
|
29
|
+
(send (const nil? _) {:create :create!} ...)
|
|
30
|
+
PATTERN
|
|
31
|
+
|
|
32
|
+
def_node_matcher :ar_save?, <<~PATTERN
|
|
33
|
+
(send _ {:save :save!} ...)
|
|
34
|
+
PATTERN
|
|
35
|
+
|
|
36
|
+
def on_send(node)
|
|
37
|
+
return unless unit_spec?
|
|
38
|
+
return unless db_creation?(node)
|
|
39
|
+
|
|
40
|
+
add_offense(node)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
private
|
|
44
|
+
|
|
45
|
+
def unit_spec?
|
|
46
|
+
path = processed_source.path
|
|
47
|
+
return false unless path&.include?("spec/")
|
|
48
|
+
|
|
49
|
+
allowed_paths.none? { |allowed| path.include?(allowed) }
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def allowed_paths
|
|
53
|
+
cop_config.fetch("AllowedPaths", DEFAULT_ALLOWED_PATHS)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def db_creation?(node)
|
|
57
|
+
factory_bot_db?(node) ||
|
|
58
|
+
standalone_factory_bot_db?(node) ||
|
|
59
|
+
ar_create?(node) ||
|
|
60
|
+
ar_save?(node)
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rubocop-config-captive
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.
|
|
4
|
+
version: 2.3.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Captive
|
|
@@ -202,6 +202,7 @@ files:
|
|
|
202
202
|
- lib/rubocop/cop/captive/rails/no_find_by_in_scope.rb
|
|
203
203
|
- lib/rubocop/cop/captive/rails/no_float_price_columns.rb
|
|
204
204
|
- lib/rubocop/cop/captive/rails/no_has_many_attached.rb
|
|
205
|
+
- lib/rubocop/cop/captive/rspec/no_db_in_unit_specs.rb
|
|
205
206
|
- lib/rubocop/cop/captive/rspec/specify_before_parameter.rb
|
|
206
207
|
- lib/rubocop/cop/captive/string_where_in_scope.rb
|
|
207
208
|
- lib/rubocop/cop/captive/translation/devise_i18n_presence.rb
|