rubocop-rspec 2.29.2 → 3.0.5

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.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +50 -0
  3. data/README.md +14 -1
  4. data/config/default.yml +62 -264
  5. data/config/obsoletion.yml +15 -21
  6. data/lib/rubocop/cop/rspec/base.rb +0 -1
  7. data/lib/rubocop/cop/rspec/dialect.rb +13 -0
  8. data/lib/rubocop/cop/rspec/example_wording.rb +2 -2
  9. data/lib/rubocop/cop/rspec/expect_actual.rb +1 -1
  10. data/lib/rubocop/cop/rspec/expect_in_hook.rb +1 -1
  11. data/lib/rubocop/cop/rspec/expect_in_let.rb +42 -0
  12. data/lib/rubocop/cop/rspec/indexed_let.rb +4 -3
  13. data/lib/rubocop/cop/rspec/leaky_constant_declaration.rb +1 -1
  14. data/lib/rubocop/cop/rspec/metadata_style.rb +1 -6
  15. data/lib/rubocop/cop/rspec/missing_expectation_target_method.rb +54 -0
  16. data/lib/rubocop/cop/rspec/multiple_describes.rb +1 -1
  17. data/lib/rubocop/cop/rspec/multiple_expectations.rb +4 -4
  18. data/lib/rubocop/cop/rspec/multiple_memoized_helpers.rb +4 -5
  19. data/lib/rubocop/cop/rspec/named_subject.rb +5 -2
  20. data/lib/rubocop/cop/rspec/nested_groups.rb +2 -1
  21. data/lib/rubocop/cop/rspec/predicate_matcher.rb +8 -4
  22. data/lib/rubocop/cop/rspec/remove_const.rb +0 -1
  23. data/lib/rubocop/cop/rspec/scattered_setup.rb +7 -1
  24. data/lib/rubocop/cop/rspec/sort_metadata.rb +1 -1
  25. data/lib/rubocop/cop/rspec/stubbed_mock.rb +3 -1
  26. data/lib/rubocop/cop/rspec/subject_stub.rb +2 -2
  27. data/lib/rubocop/cop/rspec/unspecified_exception.rb +20 -15
  28. data/lib/rubocop/cop/rspec_cops.rb +2 -25
  29. data/lib/rubocop/rspec/concept.rb +0 -1
  30. data/lib/rubocop/rspec/config_formatter.rb +1 -24
  31. data/lib/rubocop/rspec/cop/generator.rb +25 -0
  32. data/lib/rubocop/rspec/language.rb +0 -1
  33. data/lib/rubocop/rspec/shared_contexts/default_rspec_language_config_context.rb +1 -1
  34. data/lib/rubocop/rspec/version.rb +1 -1
  35. data/lib/rubocop/rspec/wording.rb +2 -2
  36. data/lib/rubocop-rspec.rb +1 -17
  37. metadata +8 -70
  38. data/lib/rubocop/cop/rspec/capybara/current_path_expectation.rb +0 -39
  39. data/lib/rubocop/cop/rspec/capybara/feature_methods.rb +0 -104
  40. data/lib/rubocop/cop/rspec/capybara/match_style.rb +0 -38
  41. data/lib/rubocop/cop/rspec/capybara/negation_matcher.rb +0 -33
  42. data/lib/rubocop/cop/rspec/capybara/specific_actions.rb +0 -29
  43. data/lib/rubocop/cop/rspec/capybara/specific_finders.rb +0 -24
  44. data/lib/rubocop/cop/rspec/capybara/specific_matcher.rb +0 -35
  45. data/lib/rubocop/cop/rspec/capybara/visibility_matcher.rb +0 -36
  46. data/lib/rubocop/cop/rspec/factory_bot/attribute_defined_statically.rb +0 -35
  47. data/lib/rubocop/cop/rspec/factory_bot/consistent_parentheses_style.rb +0 -50
  48. data/lib/rubocop/cop/rspec/factory_bot/create_list.rb +0 -40
  49. data/lib/rubocop/cop/rspec/factory_bot/factory_class_name.rb +0 -29
  50. data/lib/rubocop/cop/rspec/factory_bot/factory_name_style.rb +0 -33
  51. data/lib/rubocop/cop/rspec/factory_bot/syntax_methods.rb +0 -55
  52. data/lib/rubocop/cop/rspec/file_path.rb +0 -179
  53. data/lib/rubocop/cop/rspec/rails/avoid_setup_hook.rb +0 -27
  54. data/lib/rubocop/cop/rspec/rails/have_http_status.rb +0 -35
  55. data/lib/rubocop/cop/rspec/rails/http_status.rb +0 -61
  56. data/lib/rubocop/cop/rspec/rails/inferred_spec_type.rb +0 -62
  57. data/lib/rubocop/cop/rspec/rails/minitest_assertions.rb +0 -39
  58. data/lib/rubocop/cop/rspec/rails/negation_be_valid.rb +0 -39
  59. data/lib/rubocop/cop/rspec/rails/travel_around.rb +0 -34
  60. data/lib/rubocop/rspec/language/node_pattern.rb +0 -48
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-rspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.29.2
4
+ version: 3.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Backus
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2024-05-02 00:00:00.000000000 Z
13
+ date: 2024-09-07 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rubocop
@@ -18,56 +18,14 @@ dependencies:
18
18
  requirements:
19
19
  - - "~>"
20
20
  - !ruby/object:Gem::Version
21
- version: '1.40'
21
+ version: '1.61'
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
26
  - - "~>"
27
27
  - !ruby/object:Gem::Version
28
- version: '1.40'
29
- - !ruby/object:Gem::Dependency
30
- name: rubocop-capybara
31
- requirement: !ruby/object:Gem::Requirement
32
- requirements:
33
- - - "~>"
34
- - !ruby/object:Gem::Version
35
- version: '2.17'
36
- type: :runtime
37
- prerelease: false
38
- version_requirements: !ruby/object:Gem::Requirement
39
- requirements:
40
- - - "~>"
41
- - !ruby/object:Gem::Version
42
- version: '2.17'
43
- - !ruby/object:Gem::Dependency
44
- name: rubocop-factory_bot
45
- requirement: !ruby/object:Gem::Requirement
46
- requirements:
47
- - - "~>"
48
- - !ruby/object:Gem::Version
49
- version: '2.22'
50
- type: :runtime
51
- prerelease: false
52
- version_requirements: !ruby/object:Gem::Requirement
53
- requirements:
54
- - - "~>"
55
- - !ruby/object:Gem::Version
56
- version: '2.22'
57
- - !ruby/object:Gem::Dependency
58
- name: rubocop-rspec_rails
59
- requirement: !ruby/object:Gem::Requirement
60
- requirements:
61
- - - "~>"
62
- - !ruby/object:Gem::Version
63
- version: '2.28'
64
- type: :runtime
65
- prerelease: false
66
- version_requirements: !ruby/object:Gem::Requirement
67
- requirements:
68
- - - "~>"
69
- - !ruby/object:Gem::Version
70
- version: '2.28'
28
+ version: '1.61'
71
29
  description: |
72
30
  Code style checking for RSpec files.
73
31
  A plugin for the RuboCop code style enforcing & linting tool.
@@ -99,14 +57,6 @@ files:
99
57
  - lib/rubocop/cop/rspec/be_eql.rb
100
58
  - lib/rubocop/cop/rspec/be_nil.rb
101
59
  - lib/rubocop/cop/rspec/before_after_all.rb
102
- - lib/rubocop/cop/rspec/capybara/current_path_expectation.rb
103
- - lib/rubocop/cop/rspec/capybara/feature_methods.rb
104
- - lib/rubocop/cop/rspec/capybara/match_style.rb
105
- - lib/rubocop/cop/rspec/capybara/negation_matcher.rb
106
- - lib/rubocop/cop/rspec/capybara/specific_actions.rb
107
- - lib/rubocop/cop/rspec/capybara/specific_finders.rb
108
- - lib/rubocop/cop/rspec/capybara/specific_matcher.rb
109
- - lib/rubocop/cop/rspec/capybara/visibility_matcher.rb
110
60
  - lib/rubocop/cop/rspec/change_by_zero.rb
111
61
  - lib/rubocop/cop/rspec/class_check.rb
112
62
  - lib/rubocop/cop/rspec/contain_exactly.rb
@@ -136,14 +86,8 @@ files:
136
86
  - lib/rubocop/cop/rspec/expect_actual.rb
137
87
  - lib/rubocop/cop/rspec/expect_change.rb
138
88
  - lib/rubocop/cop/rspec/expect_in_hook.rb
89
+ - lib/rubocop/cop/rspec/expect_in_let.rb
139
90
  - lib/rubocop/cop/rspec/expect_output.rb
140
- - lib/rubocop/cop/rspec/factory_bot/attribute_defined_statically.rb
141
- - lib/rubocop/cop/rspec/factory_bot/consistent_parentheses_style.rb
142
- - lib/rubocop/cop/rspec/factory_bot/create_list.rb
143
- - lib/rubocop/cop/rspec/factory_bot/factory_class_name.rb
144
- - lib/rubocop/cop/rspec/factory_bot/factory_name_style.rb
145
- - lib/rubocop/cop/rspec/factory_bot/syntax_methods.rb
146
- - lib/rubocop/cop/rspec/file_path.rb
147
91
  - lib/rubocop/cop/rspec/focus.rb
148
92
  - lib/rubocop/cop/rspec/hook_argument.rb
149
93
  - lib/rubocop/cop/rspec/hooks_before_examples.rb
@@ -167,6 +111,7 @@ files:
167
111
  - lib/rubocop/cop/rspec/message_spies.rb
168
112
  - lib/rubocop/cop/rspec/metadata_style.rb
169
113
  - lib/rubocop/cop/rspec/missing_example_group_argument.rb
114
+ - lib/rubocop/cop/rspec/missing_expectation_target_method.rb
170
115
  - lib/rubocop/cop/rspec/mixin/comments_help.rb
171
116
  - lib/rubocop/cop/rspec/mixin/empty_line_separation.rb
172
117
  - lib/rubocop/cop/rspec/mixin/file_help.rb
@@ -190,13 +135,6 @@ files:
190
135
  - lib/rubocop/cop/rspec/pending.rb
191
136
  - lib/rubocop/cop/rspec/pending_without_reason.rb
192
137
  - lib/rubocop/cop/rspec/predicate_matcher.rb
193
- - lib/rubocop/cop/rspec/rails/avoid_setup_hook.rb
194
- - lib/rubocop/cop/rspec/rails/have_http_status.rb
195
- - lib/rubocop/cop/rspec/rails/http_status.rb
196
- - lib/rubocop/cop/rspec/rails/inferred_spec_type.rb
197
- - lib/rubocop/cop/rspec/rails/minitest_assertions.rb
198
- - lib/rubocop/cop/rspec/rails/negation_be_valid.rb
199
- - lib/rubocop/cop/rspec/rails/travel_around.rb
200
138
  - lib/rubocop/cop/rspec/receive_counts.rb
201
139
  - lib/rubocop/cop/rspec/receive_messages.rb
202
140
  - lib/rubocop/cop/rspec/receive_never.rb
@@ -235,6 +173,7 @@ files:
235
173
  - lib/rubocop/rspec/align_let_brace.rb
236
174
  - lib/rubocop/rspec/concept.rb
237
175
  - lib/rubocop/rspec/config_formatter.rb
176
+ - lib/rubocop/rspec/cop/generator.rb
238
177
  - lib/rubocop/rspec/corrector/move_node.rb
239
178
  - lib/rubocop/rspec/description_extractor.rb
240
179
  - lib/rubocop/rspec/example.rb
@@ -242,7 +181,6 @@ files:
242
181
  - lib/rubocop/rspec/hook.rb
243
182
  - lib/rubocop/rspec/inject.rb
244
183
  - lib/rubocop/rspec/language.rb
245
- - lib/rubocop/rspec/language/node_pattern.rb
246
184
  - lib/rubocop/rspec/node.rb
247
185
  - lib/rubocop/rspec/shared_contexts/default_rspec_language_config_context.rb
248
186
  - lib/rubocop/rspec/version.rb
@@ -269,7 +207,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
269
207
  - !ruby/object:Gem::Version
270
208
  version: '0'
271
209
  requirements: []
272
- rubygems_version: 3.5.9
210
+ rubygems_version: 3.5.16
273
211
  signing_key:
274
212
  specification_version: 4
275
213
  summary: Code style checking for RSpec files
@@ -1,39 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RuboCop
4
- module Cop
5
- module RSpec
6
- module Capybara
7
- # @!parse
8
- # # Checks that no expectations are set on Capybara's `current_path`.
9
- # #
10
- # # The
11
- # # https://www.rubydoc.info/github/teamcapybara/capybara/master/Capybara/RSpecMatchers#have_current_path-instance_method[`have_current_path` matcher]
12
- # # should be used on `page` to set expectations on Capybara's
13
- # # current path, since it uses
14
- # # https://github.com/teamcapybara/capybara/blob/master/README.md#asynchronous-javascript-ajax-and-friends[Capybara's waiting functionality]
15
- # # which ensures that preceding actions (like `click_link`) have
16
- # # completed.
17
- # #
18
- # # This cop does not support autocorrection in some cases.
19
- # #
20
- # # @example
21
- # # # bad
22
- # # expect(current_path).to eq('/callback')
23
- # #
24
- # # # good
25
- # # expect(page).to have_current_path('/callback')
26
- # #
27
- # # # bad (does not support autocorrection)
28
- # # expect(page.current_path).to match(variable)
29
- # #
30
- # # # good
31
- # # expect(page).to have_current_path('/callback')
32
- # #
33
- # class CurrentPathExpectation < ::RuboCop::Cop::Base; end
34
- CurrentPathExpectation =
35
- ::RuboCop::Cop::Capybara::CurrentPathExpectation
36
- end
37
- end
38
- end
39
- end
@@ -1,104 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RuboCop
4
- module Cop
5
- module RSpec
6
- module Capybara
7
- # Checks for consistent method usage in feature specs.
8
- #
9
- # By default, the cop disables all Capybara-specific methods that have
10
- # the same native RSpec method (e.g. are just aliases). Some teams
11
- # however may prefer using some of the Capybara methods (like `feature`)
12
- # to make it obvious that the test uses Capybara, while still disable
13
- # the rest of the methods, like `given` (alias for `let`), `background`
14
- # (alias for `before`), etc. You can configure which of the methods to
15
- # be enabled by using the EnabledMethods configuration option.
16
- #
17
- # @example
18
- # # bad
19
- # feature 'User logs in' do
20
- # given(:user) { User.new }
21
- #
22
- # background do
23
- # visit new_session_path
24
- # end
25
- #
26
- # scenario 'with OAuth' do
27
- # # ...
28
- # end
29
- # end
30
- #
31
- # # good
32
- # describe 'User logs in' do
33
- # let(:user) { User.new }
34
- #
35
- # before do
36
- # visit new_session_path
37
- # end
38
- #
39
- # it 'with OAuth' do
40
- # # ...
41
- # end
42
- # end
43
- #
44
- class FeatureMethods < Base
45
- extend AutoCorrector
46
- include InsideExampleGroup
47
-
48
- MSG = 'Use `%<replacement>s` instead of `%<method>s`.'
49
-
50
- # https://github.com/teamcapybara/capybara/blob/e283c1aeaa72441f5403963577e16333bf111a81/lib/capybara/rspec/features.rb#L31-L36
51
- MAP = {
52
- background: :before,
53
- scenario: :it,
54
- xscenario: :xit,
55
- given: :let,
56
- given!: :let!,
57
- feature: :describe
58
- }.freeze
59
-
60
- # @!method capybara_speak(node)
61
- def_node_matcher :capybara_speak, <<~PATTERN
62
- {#{MAP.keys.map(&:inspect).join(' ')}}
63
- PATTERN
64
-
65
- # @!method feature_method(node)
66
- def_node_matcher :feature_method, <<~PATTERN
67
- (block
68
- $(send #rspec? $#capybara_speak ...)
69
- ...)
70
- PATTERN
71
-
72
- def on_block(node) # rubocop:disable InternalAffairs/NumblockHandler
73
- return unless inside_example_group?(node)
74
-
75
- feature_method(node) do |send_node, match|
76
- next if enabled?(match)
77
-
78
- add_offense(send_node.loc.selector) do |corrector|
79
- corrector.replace(send_node.loc.selector, MAP[match].to_s)
80
- end
81
- end
82
- end
83
-
84
- def message(range)
85
- name = range.source.to_sym
86
- format(MSG, method: name, replacement: MAP[name])
87
- end
88
-
89
- private
90
-
91
- def enabled?(method_name)
92
- enabled_methods.include?(method_name)
93
- end
94
-
95
- def enabled_methods
96
- cop_config
97
- .fetch('EnabledMethods', [])
98
- .map(&:to_sym)
99
- end
100
- end
101
- end
102
- end
103
- end
104
- end
@@ -1,38 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RuboCop
4
- module Cop
5
- module RSpec
6
- module Capybara
7
- # @!parse
8
- # # Checks for usage of deprecated style methods.
9
- # #
10
- # # @example when using `assert_style`
11
- # # # bad
12
- # # page.find(:css, '#first').assert_style(display: 'block')
13
- # #
14
- # # # good
15
- # # page.find(:css, '#first').assert_matches_style(display: 'block')
16
- # #
17
- # # @example when using `has_style?`
18
- # # # bad
19
- # # expect(page.find(:css, 'first')
20
- # # .has_style?(display: 'block')).to be true
21
- # #
22
- # # # good
23
- # # expect(page.find(:css, 'first')
24
- # # .matches_style?(display: 'block')).to be true
25
- # #
26
- # # @example when using `have_style`
27
- # # # bad
28
- # # expect(page).to have_style(display: 'block')
29
- # #
30
- # # # good
31
- # # expect(page).to match_style(display: 'block')
32
- # #
33
- # class MatchStyle < ::RuboCop::Cop::Base; end
34
- MatchStyle = ::RuboCop::Cop::Capybara::MatchStyle
35
- end
36
- end
37
- end
38
- end
@@ -1,33 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RuboCop
4
- module Cop
5
- module RSpec
6
- module Capybara
7
- # @!parse
8
- # # Enforces use of `have_no_*` or `not_to` for negated expectations.
9
- # #
10
- # # @example EnforcedStyle: not_to (default)
11
- # # # bad
12
- # # expect(page).to have_no_selector
13
- # # expect(page).to have_no_css('a')
14
- # #
15
- # # # good
16
- # # expect(page).not_to have_selector
17
- # # expect(page).not_to have_css('a')
18
- # #
19
- # # @example EnforcedStyle: have_no
20
- # # # bad
21
- # # expect(page).not_to have_selector
22
- # # expect(page).not_to have_css('a')
23
- # #
24
- # # # good
25
- # # expect(page).to have_no_selector
26
- # # expect(page).to have_no_css('a')
27
- # #
28
- # class NegationMatcher < ::RuboCop::Cop::Base; end
29
- NegationMatcher = ::RuboCop::Cop::Capybara::NegationMatcher
30
- end
31
- end
32
- end
33
- end
@@ -1,29 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RuboCop
4
- module Cop
5
- module RSpec
6
- module Capybara
7
- # @!parse
8
- # # Checks for there is a more specific actions offered by Capybara.
9
- # #
10
- # # @example
11
- # #
12
- # # # bad
13
- # # find('a').click
14
- # # find('button.cls').click
15
- # # find('a', exact_text: 'foo').click
16
- # # find('div button').click
17
- # #
18
- # # # good
19
- # # click_link
20
- # # click_button(class: 'cls')
21
- # # click_link(exact_text: 'foo')
22
- # # find('div').click_button
23
- # #
24
- # class SpecificActions < ::RuboCop::Cop::Base; end
25
- SpecificActions = ::RuboCop::Cop::Capybara::SpecificActions
26
- end
27
- end
28
- end
29
- end
@@ -1,24 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RuboCop
4
- module Cop
5
- module RSpec
6
- module Capybara
7
- # @!parse
8
- # # Checks if there is a more specific finder offered by Capybara.
9
- # #
10
- # # @example
11
- # # # bad
12
- # # find('#some-id')
13
- # # find('[visible][id=some-id]')
14
- # #
15
- # # # good
16
- # # find_by_id('some-id')
17
- # # find_by_id('some-id', visible: true)
18
- # #
19
- # class SpecificFinders < ::RuboCop::Cop::Base; end
20
- SpecificFinders = ::RuboCop::Cop::Capybara::SpecificFinders
21
- end
22
- end
23
- end
24
- end
@@ -1,35 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RuboCop
4
- module Cop
5
- module RSpec
6
- module Capybara
7
- # @!parse
8
- # # Checks for there is a more specific matcher offered by Capybara.
9
- # #
10
- # # @example
11
- # #
12
- # # # bad
13
- # # expect(page).to have_selector('button')
14
- # # expect(page).to have_no_selector('button.cls')
15
- # # expect(page).to have_css('button')
16
- # # expect(page).to have_no_css('a.cls', href: 'http://example.com')
17
- # # expect(page).to have_css('table.cls')
18
- # # expect(page).to have_css('select')
19
- # # expect(page).to have_css('input', exact_text: 'foo')
20
- # #
21
- # # # good
22
- # # expect(page).to have_button
23
- # # expect(page).to have_no_button(class: 'cls')
24
- # # expect(page).to have_button
25
- # # expect(page).to have_no_link('foo', class: 'cls', href: 'http://example.com')
26
- # # expect(page).to have_table(class: 'cls')
27
- # # expect(page).to have_select
28
- # # expect(page).to have_field('foo')
29
- # #
30
- # class SpecificMatcher < ::RuboCop::Cop::Base; end
31
- SpecificMatcher = ::RuboCop::Cop::Capybara::SpecificMatcher
32
- end
33
- end
34
- end
35
- end
@@ -1,36 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RuboCop
4
- module Cop
5
- module RSpec
6
- module Capybara
7
- # @!parse
8
- # # Checks for boolean visibility in Capybara finders.
9
- # #
10
- # # Capybara lets you find elements that match a certain visibility
11
- # # using the `:visible` option. `:visible` accepts both boolean and
12
- # # symbols as values, however using booleans can have unwanted
13
- # # effects. `visible: false` does not find just invisible elements,
14
- # # but both visible and invisible elements. For expressiveness and
15
- # # clarity, use one of the # symbol values, `:all`, `:hidden` or
16
- # # `:visible`.
17
- # # Read more in
18
- # # https://www.rubydoc.info/gems/capybara/Capybara%2FNode%2FFinders:all[the documentation].
19
- # #
20
- # # @example
21
- # # # bad
22
- # # expect(page).to have_selector('.foo', visible: false)
23
- # # expect(page).to have_css('.foo', visible: true)
24
- # # expect(page).to have_link('my link', visible: false)
25
- # #
26
- # # # good
27
- # # expect(page).to have_selector('.foo', visible: :visible)
28
- # # expect(page).to have_css('.foo', visible: :all)
29
- # # expect(page).to have_link('my link', visible: :hidden)
30
- # #
31
- # class VisibilityMatcher < ::RuboCop::Cop::Base; end
32
- VisibilityMatcher = ::RuboCop::Cop::Capybara::VisibilityMatcher
33
- end
34
- end
35
- end
36
- end
@@ -1,35 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RuboCop
4
- module Cop
5
- module RSpec
6
- module FactoryBot
7
- # @!parse
8
- # # Always declare attribute values as blocks.
9
- # #
10
- # # @example
11
- # # # bad
12
- # # kind [:active, :rejected].sample
13
- # #
14
- # # # good
15
- # # kind { [:active, :rejected].sample }
16
- # #
17
- # # # bad
18
- # # closed_at 1.day.from_now
19
- # #
20
- # # # good
21
- # # closed_at { 1.day.from_now }
22
- # #
23
- # # # bad
24
- # # count 1
25
- # #
26
- # # # good
27
- # # count { 1 }
28
- # #
29
- # class AttributeDefinedStatically < ::RuboCop::Cop::Base; end
30
- AttributeDefinedStatically =
31
- ::RuboCop::Cop::FactoryBot::AttributeDefinedStatically
32
- end
33
- end
34
- end
35
- end
@@ -1,50 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RuboCop
4
- module Cop
5
- module RSpec
6
- module FactoryBot
7
- # @!parse
8
- # # Use a consistent style for parentheses in factory bot calls.
9
- # #
10
- # # @example
11
- # #
12
- # # # bad
13
- # # create :user
14
- # # build(:user)
15
- # # create(:login)
16
- # # create :login
17
- # #
18
- # # @example `EnforcedStyle: require_parentheses` (default)
19
- # #
20
- # # # good
21
- # # create(:user)
22
- # # create(:user)
23
- # # create(:login)
24
- # # build(:login)
25
- # #
26
- # # @example `EnforcedStyle: omit_parentheses`
27
- # #
28
- # # # good
29
- # # create :user
30
- # # build :user
31
- # # create :login
32
- # # create :login
33
- # #
34
- # # # also good
35
- # # # when method name and first argument are not on same line
36
- # # create(
37
- # # :user
38
- # # )
39
- # # build(
40
- # # :user,
41
- # # name: 'foo'
42
- # # )
43
- # #
44
- # class ConsistentParenthesesStyle < ::RuboCop::Cop::Base; end
45
- ConsistentParenthesesStyle =
46
- ::RuboCop::Cop::FactoryBot::ConsistentParenthesesStyle
47
- end
48
- end
49
- end
50
- end
@@ -1,40 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RuboCop
4
- module Cop
5
- module RSpec
6
- module FactoryBot
7
- # @!parse
8
- # # Checks for create_list usage.
9
- # #
10
- # # This cop can be configured using the `EnforcedStyle` option
11
- # #
12
- # # @example `EnforcedStyle: create_list` (default)
13
- # # # bad
14
- # # 3.times { create :user }
15
- # #
16
- # # # good
17
- # # create_list :user, 3
18
- # #
19
- # # # bad
20
- # # 3.times { create :user, age: 18 }
21
- # #
22
- # # # good - index is used to alter the created models attributes
23
- # # 3.times { |n| create :user, age: n }
24
- # #
25
- # # # good - contains a method call, may return different values
26
- # # 3.times { create :user, age: rand }
27
- # #
28
- # # @example `EnforcedStyle: n_times`
29
- # # # bad
30
- # # create_list :user, 3
31
- # #
32
- # # # good
33
- # # 3.times { create :user }
34
- # #
35
- # class CreateList < ::RuboCop::Cop::Base; end
36
- CreateList = ::RuboCop::Cop::FactoryBot::CreateList
37
- end
38
- end
39
- end
40
- end
@@ -1,29 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RuboCop
4
- module Cop
5
- module RSpec
6
- module FactoryBot
7
- # @!parse
8
- # # Use string value when setting the class attribute explicitly.
9
- # #
10
- # # This cop would promote faster tests by lazy-loading of
11
- # # application files. Also, this could help you suppress potential
12
- # # bugs in combination with external libraries by avoiding a preload
13
- # # of application files from the factory files.
14
- # #
15
- # # @example
16
- # # # bad
17
- # # factory :foo, class: Foo do
18
- # # end
19
- # #
20
- # # # good
21
- # # factory :foo, class: 'Foo' do
22
- # # end
23
- # #
24
- # class FactoryClassName < ::RuboCop::Cop::Base; end
25
- FactoryClassName = ::RuboCop::Cop::FactoryBot::FactoryClassName
26
- end
27
- end
28
- end
29
- end
@@ -1,33 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RuboCop
4
- module Cop
5
- module RSpec
6
- module FactoryBot
7
- # @!parse
8
- # # Checks for name style for argument of FactoryBot::Syntax::Methods.
9
- # #
10
- # # @example EnforcedStyle: symbol (default)
11
- # # # bad
12
- # # create('user')
13
- # # build "user", username: "NAME"
14
- # #
15
- # # # good
16
- # # create(:user)
17
- # # build :user, username: "NAME"
18
- # #
19
- # # @example EnforcedStyle: string
20
- # # # bad
21
- # # create(:user)
22
- # # build :user, username: "NAME"
23
- # #
24
- # # # good
25
- # # create('user')
26
- # # build "user", username: "NAME"
27
- # #
28
- # class FactoryNameStyle < ::RuboCop::Cop::Base; end
29
- FactoryNameStyle = ::RuboCop::Cop::FactoryBot::FactoryNameStyle
30
- end
31
- end
32
- end
33
- end