rubocop-rspec 2.29.1 → 3.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +92 -3
  3. data/README.md +21 -5
  4. data/config/default.yml +64 -269
  5. data/config/obsoletion.yml +20 -21
  6. data/lib/rubocop/cop/rspec/around_block.rb +2 -4
  7. data/lib/rubocop/cop/rspec/base.rb +0 -1
  8. data/lib/rubocop/cop/rspec/be_eq.rb +1 -1
  9. data/lib/rubocop/cop/rspec/be_eql.rb +1 -1
  10. data/lib/rubocop/cop/rspec/be_nil.rb +4 -0
  11. data/lib/rubocop/cop/rspec/change_by_zero.rb +4 -5
  12. data/lib/rubocop/cop/rspec/contain_exactly.rb +1 -0
  13. data/lib/rubocop/cop/rspec/context_wording.rb +15 -9
  14. data/lib/rubocop/cop/rspec/dialect.rb +13 -0
  15. data/lib/rubocop/cop/rspec/empty_example_group.rb +2 -0
  16. data/lib/rubocop/cop/rspec/empty_metadata.rb +1 -0
  17. data/lib/rubocop/cop/rspec/example_wording.rb +3 -5
  18. data/lib/rubocop/cop/rspec/excessive_docstring_spacing.rb +1 -1
  19. data/lib/rubocop/cop/rspec/expect_actual.rb +3 -3
  20. data/lib/rubocop/cop/rspec/expect_in_hook.rb +1 -1
  21. data/lib/rubocop/cop/rspec/expect_in_let.rb +42 -0
  22. data/lib/rubocop/cop/rspec/focus.rb +14 -16
  23. data/lib/rubocop/cop/rspec/implicit_expect.rb +3 -3
  24. data/lib/rubocop/cop/rspec/implicit_subject.rb +8 -0
  25. data/lib/rubocop/cop/rspec/indexed_let.rb +6 -3
  26. data/lib/rubocop/cop/rspec/leaky_constant_declaration.rb +1 -1
  27. data/lib/rubocop/cop/rspec/match_array.rb +1 -0
  28. data/lib/rubocop/cop/rspec/message_spies.rb +4 -0
  29. data/lib/rubocop/cop/rspec/metadata_style.rb +1 -6
  30. data/lib/rubocop/cop/rspec/missing_expectation_target_method.rb +54 -0
  31. data/lib/rubocop/cop/rspec/mixin/metadata.rb +5 -8
  32. data/lib/rubocop/cop/rspec/mixin/top_level_group.rb +7 -0
  33. data/lib/rubocop/cop/rspec/multiple_describes.rb +1 -1
  34. data/lib/rubocop/cop/rspec/multiple_expectations.rb +4 -4
  35. data/lib/rubocop/cop/rspec/multiple_memoized_helpers.rb +4 -5
  36. data/lib/rubocop/cop/rspec/named_subject.rb +5 -2
  37. data/lib/rubocop/cop/rspec/nested_groups.rb +2 -1
  38. data/lib/rubocop/cop/rspec/pending_without_reason.rb +0 -5
  39. data/lib/rubocop/cop/rspec/predicate_matcher.rb +25 -11
  40. data/lib/rubocop/cop/rspec/remove_const.rb +0 -1
  41. data/lib/rubocop/cop/rspec/repeated_subject_call.rb +1 -0
  42. data/lib/rubocop/cop/rspec/return_from_stub.rb +5 -4
  43. data/lib/rubocop/cop/rspec/scattered_setup.rb +7 -1
  44. data/lib/rubocop/cop/rspec/single_argument_message_chain.rb +3 -4
  45. data/lib/rubocop/cop/rspec/sort_metadata.rb +22 -8
  46. data/lib/rubocop/cop/rspec/stubbed_mock.rb +15 -10
  47. data/lib/rubocop/cop/rspec/subject_stub.rb +2 -2
  48. data/lib/rubocop/cop/rspec/unspecified_exception.rb +21 -14
  49. data/lib/rubocop/cop/rspec/verified_double_reference.rb +14 -53
  50. data/lib/rubocop/cop/rspec/void_expect.rb +6 -1
  51. data/lib/rubocop/cop/rspec_cops.rb +2 -25
  52. data/lib/rubocop/rspec/concept.rb +0 -1
  53. data/lib/rubocop/rspec/config_formatter.rb +4 -32
  54. data/lib/rubocop/rspec/cop/generator.rb +25 -0
  55. data/lib/rubocop/rspec/description_extractor.rb +2 -2
  56. data/lib/rubocop/rspec/hook.rb +1 -1
  57. data/lib/rubocop/rspec/language.rb +0 -1
  58. data/lib/rubocop/rspec/node.rb +1 -1
  59. data/lib/rubocop/rspec/plugin.rb +37 -0
  60. data/lib/rubocop/rspec/shared_contexts/default_rspec_language_config_context.rb +1 -1
  61. data/lib/rubocop/rspec/version.rb +1 -1
  62. data/lib/rubocop/rspec/wording.rb +2 -4
  63. data/lib/rubocop/rspec.rb +0 -7
  64. data/lib/rubocop-rspec.rb +2 -20
  65. metadata +18 -62
  66. data/lib/rubocop/cop/rspec/capybara/current_path_expectation.rb +0 -39
  67. data/lib/rubocop/cop/rspec/capybara/feature_methods.rb +0 -104
  68. data/lib/rubocop/cop/rspec/capybara/match_style.rb +0 -38
  69. data/lib/rubocop/cop/rspec/capybara/negation_matcher.rb +0 -33
  70. data/lib/rubocop/cop/rspec/capybara/specific_actions.rb +0 -29
  71. data/lib/rubocop/cop/rspec/capybara/specific_finders.rb +0 -24
  72. data/lib/rubocop/cop/rspec/capybara/specific_matcher.rb +0 -35
  73. data/lib/rubocop/cop/rspec/capybara/visibility_matcher.rb +0 -36
  74. data/lib/rubocop/cop/rspec/factory_bot/attribute_defined_statically.rb +0 -35
  75. data/lib/rubocop/cop/rspec/factory_bot/consistent_parentheses_style.rb +0 -50
  76. data/lib/rubocop/cop/rspec/factory_bot/create_list.rb +0 -40
  77. data/lib/rubocop/cop/rspec/factory_bot/factory_class_name.rb +0 -29
  78. data/lib/rubocop/cop/rspec/factory_bot/factory_name_style.rb +0 -33
  79. data/lib/rubocop/cop/rspec/factory_bot/syntax_methods.rb +0 -55
  80. data/lib/rubocop/cop/rspec/file_path.rb +0 -179
  81. data/lib/rubocop/cop/rspec/rails/avoid_setup_hook.rb +0 -27
  82. data/lib/rubocop/cop/rspec/rails/have_http_status.rb +0 -35
  83. data/lib/rubocop/cop/rspec/rails/http_status.rb +0 -61
  84. data/lib/rubocop/cop/rspec/rails/inferred_spec_type.rb +0 -62
  85. data/lib/rubocop/cop/rspec/rails/minitest_assertions.rb +0 -39
  86. data/lib/rubocop/cop/rspec/rails/negation_be_valid.rb +0 -39
  87. data/lib/rubocop/cop/rspec/rails/travel_around.rb +0 -34
  88. data/lib/rubocop/rspec/inject.rb +0 -18
  89. data/lib/rubocop/rspec/language/node_pattern.rb +0 -48
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module RSpec
5
+ module Cop
6
+ # Source and spec generator for new cops
7
+ #
8
+ # This generator will take a cop name and generate a source file
9
+ # and spec file when given a valid qualified cop name.
10
+ # @api private
11
+ class Generator < RuboCop::Cop::Generator
12
+ def todo
13
+ <<~TODO
14
+ Do 4 steps:
15
+ 1. Modify the description of #{badge} in config/default.yml
16
+ 2. Implement your new cop in the generated file!
17
+ 3. Add an entry about new cop to CHANGELOG.md
18
+ 4. Commit your new cop with a message such as
19
+ e.g. "Add new `#{badge}` cop"
20
+ TODO
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -62,8 +62,8 @@ module RuboCop
62
62
  end
63
63
 
64
64
  def cop_subclass?
65
- yardoc.superclass.path == RSPEC_COP_CLASS_NAME ||
66
- yardoc.superclass.path == RUBOCOP_COP_CLASS_NAME
65
+ [RSPEC_COP_CLASS_NAME,
66
+ RUBOCOP_COP_CLASS_NAME].include?(yardoc.superclass.path)
67
67
  end
68
68
 
69
69
  def abstract?
@@ -45,7 +45,7 @@ module RuboCop
45
45
  private
46
46
 
47
47
  def valid_scope?(node)
48
- node&.sym_type? && Language::HookScopes.all(node.value)
48
+ node.sym_type? && Language::HookScopes.all(node.value)
49
49
  end
50
50
 
51
51
  def transform_metadata(meta)
@@ -13,7 +13,6 @@ module RuboCop
13
13
  # using the configured aliases.
14
14
  module Language
15
15
  extend RuboCop::NodePattern::Macros
16
- extend NodePattern
17
16
 
18
17
  class << self
19
18
  attr_accessor :config
@@ -9,7 +9,7 @@ module RuboCop
9
9
  def recursive_literal_or_const?
10
10
  case type
11
11
  when :begin, :pair, *AST::Node::COMPOSITE_LITERALS
12
- children.all?(&:recursive_literal_or_const?)
12
+ children.compact.all?(&:recursive_literal_or_const?)
13
13
  else
14
14
  literal? || const_type?
15
15
  end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'lint_roller'
4
+
5
+ module RuboCop
6
+ module RSpec
7
+ # A plugin that integrates RuboCop RSpec with RuboCop's plugin system.
8
+ class Plugin < LintRoller::Plugin
9
+ # :nocov:
10
+ def about
11
+ LintRoller::About.new(
12
+ name: 'rubocop-rspec',
13
+ version: Version::STRING,
14
+ homepage: 'https://github.com/rubocop/rubocop-rspec',
15
+ description: 'Code style checking for RSpec files.'
16
+ )
17
+ end
18
+ # :nocov:
19
+
20
+ def supported?(context)
21
+ context.engine == :rubocop
22
+ end
23
+
24
+ def rules(_context)
25
+ project_root = Pathname.new(__dir__).join('../../..')
26
+
27
+ ConfigObsoletion.files << project_root.join('config', 'obsoletion.yml')
28
+
29
+ LintRoller::Rules.new(
30
+ type: :path,
31
+ config_format: :rubocop,
32
+ value: project_root.join('config/default.yml')
33
+ )
34
+ end
35
+ end
36
+ end
37
+ end
@@ -21,7 +21,7 @@ RSpec.shared_context 'with default RSpec/Language config' do
21
21
  when Array
22
22
  object.map { |item| deep_dup(item) }
23
23
  when Hash
24
- object.transform_values(&method(:deep_dup))
24
+ object.transform_values { |value| deep_dup(value) }
25
25
  else
26
26
  object # only collections undergo modifications and need duping
27
27
  end
@@ -4,7 +4,7 @@ module RuboCop
4
4
  module RSpec
5
5
  # Version information for the RSpec RuboCop plugin.
6
6
  module Version
7
- STRING = '2.29.1'
7
+ STRING = '3.5.0'
8
8
  end
9
9
  end
10
10
  end
@@ -4,10 +4,10 @@ module RuboCop
4
4
  module RSpec
5
5
  # RSpec example wording rewriter
6
6
  class Wording
7
- SHOULDNT_PREFIX = /\Ashould(?:n't| not)\b/i.freeze
7
+ SHOULDNT_PREFIX = /\Ashould(?:n't|n’t| not)\b/i.freeze
8
8
  SHOULDNT_BE_PREFIX = /#{SHOULDNT_PREFIX} be\b/i.freeze
9
9
  WILL_NOT_PREFIX = /\Awill not\b/i.freeze
10
- WONT_PREFIX = /\Awon't\b/i.freeze
10
+ WONT_PREFIX = /\Awo(?:n't|n’t)\b/i.freeze
11
11
  ES_SUFFIX_PATTERN = /(?:o|s|x|ch|sh|z)\z/i.freeze
12
12
  IES_SUFFIX_PATTERN = /[^aeou]y\z/i.freeze
13
13
 
@@ -17,7 +17,6 @@ module RuboCop
17
17
  @replacements = replace
18
18
  end
19
19
 
20
- # rubocop:disable Metrics/MethodLength
21
20
  def rewrite
22
21
  case text
23
22
  when SHOULDNT_BE_PREFIX
@@ -32,7 +31,6 @@ module RuboCop
32
31
  remove_should_and_pluralize
33
32
  end
34
33
  end
35
- # rubocop:enable Metrics/MethodLength
36
34
 
37
35
  private
38
36
 
data/lib/rubocop/rspec.rb CHANGED
@@ -3,12 +3,5 @@
3
3
  module RuboCop
4
4
  # RuboCop RSpec project namespace
5
5
  module RSpec
6
- PROJECT_ROOT = Pathname.new(__dir__).parent.parent.expand_path.freeze
7
- CONFIG_DEFAULT = PROJECT_ROOT.join('config', 'default.yml').freeze
8
-
9
- private_constant(:CONFIG_DEFAULT, :PROJECT_ROOT)
10
-
11
- ::RuboCop::ConfigObsoletion.files << PROJECT_ROOT.join('config',
12
- 'obsoletion.yml')
13
6
  end
14
7
  end
data/lib/rubocop-rspec.rb CHANGED
@@ -4,19 +4,14 @@ require 'pathname'
4
4
  require 'yaml'
5
5
 
6
6
  require 'rubocop'
7
- require 'rubocop-capybara'
8
- require 'rubocop-factory_bot'
9
7
 
10
8
  require_relative 'rubocop/rspec'
11
- require_relative 'rubocop/rspec/inject'
12
- require_relative 'rubocop/rspec/language/node_pattern'
9
+ require_relative 'rubocop/rspec/language'
13
10
  require_relative 'rubocop/rspec/node'
11
+ require_relative 'rubocop/rspec/plugin'
14
12
  require_relative 'rubocop/rspec/version'
15
13
  require_relative 'rubocop/rspec/wording'
16
14
 
17
- # Dependent on `RuboCop::RSpec::Language::NodePattern`.
18
- require_relative 'rubocop/rspec/language'
19
-
20
15
  require_relative 'rubocop/cop/rspec/mixin/file_help'
21
16
  require_relative 'rubocop/cop/rspec/mixin/final_end_location'
22
17
  require_relative 'rubocop/cop/rspec/mixin/inside_example_group'
@@ -39,11 +34,6 @@ require_relative 'rubocop/rspec/example'
39
34
  require_relative 'rubocop/rspec/example_group'
40
35
  require_relative 'rubocop/rspec/hook'
41
36
 
42
- # need after `require 'rubocop/cop/rspec/base'``
43
- require 'rubocop-rspec_rails'
44
-
45
- RuboCop::RSpec::Inject.defaults!
46
-
47
37
  require_relative 'rubocop/cop/rspec_cops'
48
38
 
49
39
  # We have to register our autocorrect incompatibilities in RuboCop's cops
@@ -58,12 +48,4 @@ RuboCop::Cop::Layout::ExtraSpacing.singleton_class.prepend(
58
48
  end
59
49
  )
60
50
 
61
- RuboCop::Cop::Style::TrailingCommaInArguments.singleton_class.prepend(
62
- Module.new do
63
- def autocorrect_incompatible_with
64
- super.push(RuboCop::Cop::RSpec::Capybara::CurrentPathExpectation)
65
- end
66
- end
67
- )
68
-
69
51
  RuboCop::AST::Node.include(RuboCop::RSpec::Node)
metadata CHANGED
@@ -1,73 +1,50 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-rspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.29.1
4
+ version: 3.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Backus
8
8
  - Ian MacLeod
9
9
  - Nils Gemeinhardt
10
- autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2024-04-04 00:00:00.000000000 Z
12
+ date: 2025-02-16 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
- name: rubocop
15
+ name: lint_roller
17
16
  requirement: !ruby/object:Gem::Requirement
18
17
  requirements:
19
18
  - - "~>"
20
19
  - !ruby/object:Gem::Version
21
- version: '1.40'
20
+ version: '1.1'
22
21
  type: :runtime
23
22
  prerelease: false
24
23
  version_requirements: !ruby/object:Gem::Requirement
25
24
  requirements:
26
25
  - - "~>"
27
26
  - !ruby/object:Gem::Version
28
- version: '1.40'
27
+ version: '1.1'
29
28
  - !ruby/object:Gem::Dependency
30
- name: rubocop-capybara
29
+ name: rubocop
31
30
  requirement: !ruby/object:Gem::Requirement
32
31
  requirements:
33
32
  - - "~>"
34
33
  - !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
- - - "~>"
34
+ version: '1.72'
35
+ - - ">="
48
36
  - !ruby/object:Gem::Version
49
- version: '2.22'
37
+ version: 1.72.1
50
38
  type: :runtime
51
39
  prerelease: false
52
40
  version_requirements: !ruby/object:Gem::Requirement
53
41
  requirements:
54
42
  - - "~>"
55
43
  - !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
- - - "~>"
44
+ version: '1.72'
45
+ - - ">="
69
46
  - !ruby/object:Gem::Version
70
- version: '2.28'
47
+ version: 1.72.1
71
48
  description: |
72
49
  Code style checking for RSpec files.
73
50
  A plugin for the RuboCop code style enforcing & linting tool.
@@ -99,14 +76,6 @@ files:
99
76
  - lib/rubocop/cop/rspec/be_eql.rb
100
77
  - lib/rubocop/cop/rspec/be_nil.rb
101
78
  - 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
79
  - lib/rubocop/cop/rspec/change_by_zero.rb
111
80
  - lib/rubocop/cop/rspec/class_check.rb
112
81
  - lib/rubocop/cop/rspec/contain_exactly.rb
@@ -136,14 +105,8 @@ files:
136
105
  - lib/rubocop/cop/rspec/expect_actual.rb
137
106
  - lib/rubocop/cop/rspec/expect_change.rb
138
107
  - lib/rubocop/cop/rspec/expect_in_hook.rb
108
+ - lib/rubocop/cop/rspec/expect_in_let.rb
139
109
  - 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
110
  - lib/rubocop/cop/rspec/focus.rb
148
111
  - lib/rubocop/cop/rspec/hook_argument.rb
149
112
  - lib/rubocop/cop/rspec/hooks_before_examples.rb
@@ -167,6 +130,7 @@ files:
167
130
  - lib/rubocop/cop/rspec/message_spies.rb
168
131
  - lib/rubocop/cop/rspec/metadata_style.rb
169
132
  - lib/rubocop/cop/rspec/missing_example_group_argument.rb
133
+ - lib/rubocop/cop/rspec/missing_expectation_target_method.rb
170
134
  - lib/rubocop/cop/rspec/mixin/comments_help.rb
171
135
  - lib/rubocop/cop/rspec/mixin/empty_line_separation.rb
172
136
  - lib/rubocop/cop/rspec/mixin/file_help.rb
@@ -190,13 +154,6 @@ files:
190
154
  - lib/rubocop/cop/rspec/pending.rb
191
155
  - lib/rubocop/cop/rspec/pending_without_reason.rb
192
156
  - 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
157
  - lib/rubocop/cop/rspec/receive_counts.rb
201
158
  - lib/rubocop/cop/rspec/receive_messages.rb
202
159
  - lib/rubocop/cop/rspec/receive_never.rb
@@ -235,15 +192,15 @@ files:
235
192
  - lib/rubocop/rspec/align_let_brace.rb
236
193
  - lib/rubocop/rspec/concept.rb
237
194
  - lib/rubocop/rspec/config_formatter.rb
195
+ - lib/rubocop/rspec/cop/generator.rb
238
196
  - lib/rubocop/rspec/corrector/move_node.rb
239
197
  - lib/rubocop/rspec/description_extractor.rb
240
198
  - lib/rubocop/rspec/example.rb
241
199
  - lib/rubocop/rspec/example_group.rb
242
200
  - lib/rubocop/rspec/hook.rb
243
- - lib/rubocop/rspec/inject.rb
244
201
  - lib/rubocop/rspec/language.rb
245
- - lib/rubocop/rspec/language/node_pattern.rb
246
202
  - lib/rubocop/rspec/node.rb
203
+ - lib/rubocop/rspec/plugin.rb
247
204
  - lib/rubocop/rspec/shared_contexts/default_rspec_language_config_context.rb
248
205
  - lib/rubocop/rspec/version.rb
249
206
  - lib/rubocop/rspec/wording.rb
@@ -254,7 +211,7 @@ metadata:
254
211
  changelog_uri: https://github.com/rubocop/rubocop-rspec/blob/master/CHANGELOG.md
255
212
  documentation_uri: https://docs.rubocop.org/rubocop-rspec/
256
213
  rubygems_mfa_required: 'true'
257
- post_install_message:
214
+ default_lint_roller_plugin: RuboCop::RSpec::Plugin
258
215
  rdoc_options: []
259
216
  require_paths:
260
217
  - lib
@@ -269,8 +226,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
269
226
  - !ruby/object:Gem::Version
270
227
  version: '0'
271
228
  requirements: []
272
- rubygems_version: 3.5.3
273
- signing_key:
229
+ rubygems_version: 3.6.2
274
230
  specification_version: 4
275
231
  summary: Code style checking for RSpec files
276
232
  test_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