rubocop-rspec 2.31.0 → 3.0.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.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +19 -0
  3. data/README.md +1 -1
  4. data/config/default.yml +39 -261
  5. data/config/obsoletion.yml +11 -0
  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/expect_actual.rb +1 -1
  9. data/lib/rubocop/cop/rspec/expect_in_hook.rb +1 -1
  10. data/lib/rubocop/cop/rspec/expect_in_let.rb +1 -3
  11. data/lib/rubocop/cop/rspec/leaky_constant_declaration.rb +1 -1
  12. data/lib/rubocop/cop/rspec/missing_expectation_target_method.rb +54 -0
  13. data/lib/rubocop/cop/rspec/multiple_describes.rb +1 -1
  14. data/lib/rubocop/cop/rspec/multiple_expectations.rb +2 -2
  15. data/lib/rubocop/cop/rspec/multiple_memoized_helpers.rb +2 -4
  16. data/lib/rubocop/cop/rspec/named_subject.rb +5 -2
  17. data/lib/rubocop/cop/rspec/predicate_matcher.rb +1 -1
  18. data/lib/rubocop/cop/rspec/remove_const.rb +0 -1
  19. data/lib/rubocop/cop/rspec/scattered_setup.rb +1 -1
  20. data/lib/rubocop/cop/rspec/sort_metadata.rb +1 -1
  21. data/lib/rubocop/cop/rspec/stubbed_mock.rb +3 -1
  22. data/lib/rubocop/cop/rspec/subject_stub.rb +2 -2
  23. data/lib/rubocop/cop/rspec_cops.rb +1 -25
  24. data/lib/rubocop/rspec/concept.rb +0 -1
  25. data/lib/rubocop/rspec/config_formatter.rb +1 -24
  26. data/lib/rubocop/rspec/cop/generator.rb +25 -0
  27. data/lib/rubocop/rspec/language.rb +0 -1
  28. data/lib/rubocop/rspec/shared_contexts/default_rspec_language_config_context.rb +1 -1
  29. data/lib/rubocop/rspec/version.rb +1 -1
  30. data/lib/rubocop-rspec.rb +1 -17
  31. metadata +6 -69
  32. data/lib/rubocop/cop/rspec/capybara/current_path_expectation.rb +0 -39
  33. data/lib/rubocop/cop/rspec/capybara/feature_methods.rb +0 -104
  34. data/lib/rubocop/cop/rspec/capybara/match_style.rb +0 -38
  35. data/lib/rubocop/cop/rspec/capybara/negation_matcher.rb +0 -33
  36. data/lib/rubocop/cop/rspec/capybara/specific_actions.rb +0 -29
  37. data/lib/rubocop/cop/rspec/capybara/specific_finders.rb +0 -24
  38. data/lib/rubocop/cop/rspec/capybara/specific_matcher.rb +0 -35
  39. data/lib/rubocop/cop/rspec/capybara/visibility_matcher.rb +0 -36
  40. data/lib/rubocop/cop/rspec/factory_bot/attribute_defined_statically.rb +0 -35
  41. data/lib/rubocop/cop/rspec/factory_bot/consistent_parentheses_style.rb +0 -50
  42. data/lib/rubocop/cop/rspec/factory_bot/create_list.rb +0 -40
  43. data/lib/rubocop/cop/rspec/factory_bot/factory_class_name.rb +0 -29
  44. data/lib/rubocop/cop/rspec/factory_bot/factory_name_style.rb +0 -33
  45. data/lib/rubocop/cop/rspec/factory_bot/syntax_methods.rb +0 -55
  46. data/lib/rubocop/cop/rspec/file_path.rb +0 -179
  47. data/lib/rubocop/cop/rspec/rails/avoid_setup_hook.rb +0 -27
  48. data/lib/rubocop/cop/rspec/rails/have_http_status.rb +0 -35
  49. data/lib/rubocop/cop/rspec/rails/http_status.rb +0 -61
  50. data/lib/rubocop/cop/rspec/rails/inferred_spec_type.rb +0 -62
  51. data/lib/rubocop/cop/rspec/rails/minitest_assertions.rb +0 -39
  52. data/lib/rubocop/cop/rspec/rails/negation_be_valid.rb +0 -39
  53. data/lib/rubocop/cop/rspec/rails/travel_around.rb +0 -34
  54. data/lib/rubocop/rspec/language/node_pattern.rb +0 -48
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module RSpec
6
+ # Checks if `.to`, `not_to` or `to_not` are used.
7
+ #
8
+ # The RSpec::Expectations::ExpectationTarget must use `to`, `not_to` or
9
+ # `to_not` to run. Therefore, this cop checks if other methods are used.
10
+ #
11
+ # @example
12
+ # # bad
13
+ # expect(something).kind_of? Foo
14
+ # is_expected == 42
15
+ # expect{something}.eq? BarError
16
+ #
17
+ # # good
18
+ # expect(something).to be_a Foo
19
+ # is_expected.to eq 42
20
+ # expect{something}.to raise_error BarError
21
+ #
22
+ class MissingExpectationTargetMethod < Base
23
+ MSG = 'Use `.to`, `.not_to` or `.to_not` to set an expectation.'
24
+ RESTRICT_ON_SEND = %i[expect is_expected].freeze
25
+
26
+ # @!method expect?(node)
27
+ def_node_matcher :expect?, <<~PATTERN
28
+ {
29
+ (send nil? :expect ...)
30
+ (send nil? :is_expected)
31
+ }
32
+ PATTERN
33
+
34
+ # @!method expect_block?(node)
35
+ def_node_matcher :expect_block?, <<~PATTERN
36
+ (block #expect? (args) _body)
37
+ PATTERN
38
+
39
+ # @!method expectation_without_runner?(node)
40
+ def_node_matcher :expectation_without_runner?, <<~PATTERN
41
+ (send {#expect? #expect_block?} !#Runners.all ...)
42
+ PATTERN
43
+
44
+ def on_send(node)
45
+ node = node.parent if node.parent&.block_type?
46
+
47
+ expectation_without_runner?(node.parent) do
48
+ add_offense(node.parent.loc.selector)
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -30,7 +30,7 @@ module RuboCop
30
30
 
31
31
  def on_top_level_group(node)
32
32
  top_level_example_groups =
33
- top_level_groups.select(&method(:example_group?))
33
+ top_level_groups.select { |group| example_group?(group) }
34
34
 
35
35
  return if top_level_example_groups.one?
36
36
  return unless top_level_example_groups.first.equal?(node)
@@ -72,7 +72,7 @@ module RuboCop
72
72
  MSG = 'Example has too many expectations [%<total>d/%<max>d].'
73
73
 
74
74
  ANYTHING = ->(_node) { true }
75
- TRUE = lambda(&:true_type?)
75
+ TRUE_NODE = lambda(&:true_type?)
76
76
 
77
77
  # @!method aggregate_failures?(node)
78
78
  def_node_matcher :aggregate_failures?, <<~PATTERN
@@ -110,7 +110,7 @@ module RuboCop
110
110
  node_with_aggregate_failures = find_aggregate_failures(example_node)
111
111
  return false unless node_with_aggregate_failures
112
112
 
113
- aggregate_failures?(node_with_aggregate_failures, TRUE)
113
+ aggregate_failures?(node_with_aggregate_failures, TRUE_NODE)
114
114
  end
115
115
 
116
116
  def find_aggregate_failures(example_node)
@@ -108,10 +108,8 @@ module RuboCop
108
108
  attr_reader :example_group_memoized_helpers
109
109
 
110
110
  def all_helpers(node)
111
- [
112
- *helpers(node),
113
- *node.each_ancestor(:block).flat_map(&method(:helpers))
114
- ]
111
+ helpers(node) +
112
+ node.each_ancestor(:block).flat_map { |ancestor| helpers(ancestor) }
115
113
  end
116
114
 
117
115
  def helpers(node)
@@ -107,8 +107,11 @@ module RuboCop
107
107
  private
108
108
 
109
109
  def ignored_shared_example?(node)
110
- cop_config['IgnoreSharedExamples'] &&
111
- node.each_ancestor(:block).any?(&method(:shared_example?))
110
+ return false unless cop_config['IgnoreSharedExamples']
111
+
112
+ node.each_ancestor(:block).any? do |ancestor|
113
+ shared_example?(ancestor)
114
+ end
112
115
  end
113
116
 
114
117
  def check_explicit_subject(node)
@@ -174,7 +174,7 @@ module RuboCop
174
174
 
175
175
  def heredoc_argument?(matcher)
176
176
  matcher.arguments.select do |arg|
177
- %i[str dstr xstr].include?(arg.type)
177
+ arg.str_type? || arg.dstr_type? || arg.xstr_type?
178
178
  end.any?(&:heredoc?)
179
179
  end
180
180
 
@@ -17,7 +17,6 @@ module RuboCop
17
17
  #
18
18
  class RemoveConst < Base
19
19
  include RuboCop::RSpec::Language
20
- extend RuboCop::RSpec::Language::NodePattern
21
20
 
22
21
  MSG = 'Do not use remove_const in specs. ' \
23
22
  'Consider using e.g. `stub_const`.'
@@ -76,7 +76,7 @@ module RuboCop
76
76
  return if first_occurrence == occurrence || !first_occurrence.body
77
77
 
78
78
  corrector.insert_after(first_occurrence.body,
79
- "\n#{occurrence.body.source}")
79
+ "\n#{occurrence.body&.source}")
80
80
  corrector.remove(range_by_whole_lines(occurrence.source_range,
81
81
  include_final_newline: true))
82
82
  end
@@ -58,7 +58,7 @@ module RuboCop
58
58
 
59
59
  def sort_symbols(symbols)
60
60
  symbols.sort_by do |symbol|
61
- if %i[str sym].include?(symbol.type)
61
+ if symbol.str_type? || symbol.sym_type?
62
62
  symbol.value.to_s.downcase
63
63
  else
64
64
  symbol.source.downcase
@@ -136,7 +136,9 @@ module RuboCop
136
136
  RESTRICT_ON_SEND = %i[to].freeze
137
137
 
138
138
  def on_send(node)
139
- expectation(node, &method(:on_expectation))
139
+ expectation(node) do |expectation, method_name, matcher|
140
+ on_expectation(expectation, method_name, matcher)
141
+ end
140
142
  end
141
143
 
142
144
  private
@@ -113,8 +113,8 @@ module RuboCop
113
113
  PATTERN
114
114
 
115
115
  def on_top_level_group(node)
116
- @explicit_subjects = find_all_explicit(node, &method(:subject?))
117
- @subject_overrides = find_all_explicit(node, &method(:let?))
116
+ @explicit_subjects = find_all_explicit(node) { |n| subject?(n) }
117
+ @subject_overrides = find_all_explicit(node) { |n| let?(n) }
118
118
 
119
119
  find_subject_expectations(node) do |stub|
120
120
  add_offense(stub)
@@ -1,29 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'rspec/capybara/current_path_expectation'
4
- require_relative 'rspec/capybara/feature_methods'
5
- require_relative 'rspec/capybara/match_style'
6
- require_relative 'rspec/capybara/negation_matcher'
7
- require_relative 'rspec/capybara/specific_actions'
8
- require_relative 'rspec/capybara/specific_finders'
9
- require_relative 'rspec/capybara/specific_matcher'
10
- require_relative 'rspec/capybara/visibility_matcher'
11
-
12
- require_relative 'rspec/factory_bot/attribute_defined_statically'
13
- require_relative 'rspec/factory_bot/consistent_parentheses_style'
14
- require_relative 'rspec/factory_bot/create_list'
15
- require_relative 'rspec/factory_bot/factory_class_name'
16
- require_relative 'rspec/factory_bot/factory_name_style'
17
- require_relative 'rspec/factory_bot/syntax_methods'
18
-
19
- require_relative 'rspec/rails/avoid_setup_hook'
20
- require_relative 'rspec/rails/have_http_status'
21
- require_relative 'rspec/rails/http_status'
22
- require_relative 'rspec/rails/inferred_spec_type'
23
- require_relative 'rspec/rails/minitest_assertions'
24
- require_relative 'rspec/rails/negation_be_valid'
25
- require_relative 'rspec/rails/travel_around'
26
-
27
3
  require_relative 'rspec/align_left_let_brace'
28
4
  require_relative 'rspec/align_right_let_brace'
29
5
  require_relative 'rspec/any_instance'
@@ -65,7 +41,6 @@ require_relative 'rspec/expect_change'
65
41
  require_relative 'rspec/expect_in_hook'
66
42
  require_relative 'rspec/expect_in_let'
67
43
  require_relative 'rspec/expect_output'
68
- require_relative 'rspec/file_path'
69
44
  require_relative 'rspec/focus'
70
45
  require_relative 'rspec/hook_argument'
71
46
  require_relative 'rspec/hooks_before_examples'
@@ -89,6 +64,7 @@ require_relative 'rspec/message_expectation'
89
64
  require_relative 'rspec/message_spies'
90
65
  require_relative 'rspec/metadata_style'
91
66
  require_relative 'rspec/missing_example_group_argument'
67
+ require_relative 'rspec/missing_expectation_target_method'
92
68
  require_relative 'rspec/multiple_describes'
93
69
  require_relative 'rspec/multiple_expectations'
94
70
  require_relative 'rspec/multiple_memoized_helpers'
@@ -5,7 +5,6 @@ module RuboCop
5
5
  # Wrapper for RSpec DSL methods
6
6
  class Concept
7
7
  extend RuboCop::NodePattern::Macros
8
- extend Language::NodePattern
9
8
  include Language
10
9
 
11
10
  def initialize(node)
@@ -7,29 +7,7 @@ module RuboCop
7
7
  # Builds a YAML config file from two config hashes
8
8
  class ConfigFormatter
9
9
  EXTENSION_ROOT_DEPARTMENT = %r{^(RSpec/)}.freeze
10
- SUBDEPARTMENTS = %(RSpec/Capybara RSpec/FactoryBot RSpec/Rails)
11
- EXTRACTED_COPS = %(
12
- RSpec/Capybara/CurrentPathExpectation
13
- RSpec/Capybara/MatchStyle
14
- RSpec/Capybara/NegationMatcher
15
- RSpec/Capybara/SpecificActions
16
- RSpec/Capybara/SpecificFinders
17
- RSpec/Capybara/SpecificMatcher
18
- RSpec/Capybara/VisibilityMatcher
19
- RSpec/FactoryBot/AttributeDefinedStatically
20
- RSpec/FactoryBot/ConsistentParenthesesStyle
21
- RSpec/FactoryBot/CreateList
22
- RSpec/FactoryBot/FactoryClassName
23
- RSpec/FactoryBot/FactoryNameStyle
24
- RSpec/FactoryBot/SyntaxMethods
25
- RSpec/Rails/AvoidSetupHook
26
- RSpec/Rails/HaveHttpStatus
27
- RSpec/Rails/HttpStatus
28
- RSpec/Rails/InferredSpecType
29
- RSpec/Rails/MinitestAssertions
30
- RSpec/Rails/NegationBeValid
31
- RSpec/Rails/TravelAround
32
- )
10
+ SUBDEPARTMENTS = [].freeze
33
11
  AMENDMENTS = %(Metrics/BlockLength)
34
12
  COP_DOC_BASE_URL = 'https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/'
35
13
 
@@ -51,7 +29,6 @@ module RuboCop
51
29
  def unified_config
52
30
  cops.each_with_object(config.dup) do |cop, unified|
53
31
  next if SUBDEPARTMENTS.include?(cop) || AMENDMENTS.include?(cop)
54
- next if EXTRACTED_COPS.include?(cop)
55
32
 
56
33
  replace_nil(unified[cop])
57
34
  unified[cop].merge!(descriptions.fetch(cop))
@@ -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
@@ -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
@@ -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.31.0'
7
+ STRING = '3.0.1'
8
8
  end
9
9
  end
10
10
  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
9
  require_relative 'rubocop/rspec/inject'
12
- require_relative 'rubocop/rspec/language/node_pattern'
10
+ require_relative 'rubocop/rspec/language'
13
11
  require_relative 'rubocop/rspec/node'
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,9 +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
37
  RuboCop::RSpec::Inject.defaults!
46
38
 
47
39
  require_relative 'rubocop/cop/rspec_cops'
@@ -58,12 +50,4 @@ RuboCop::Cop::Layout::ExtraSpacing.singleton_class.prepend(
58
50
  end
59
51
  )
60
52
 
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
53
  RuboCop::AST::Node.include(RuboCop::RSpec::Node)
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.31.0
4
+ version: 3.0.1
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-06-07 00:00:00.000000000 Z
13
+ date: 2024-06-11 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
@@ -138,13 +88,6 @@ files:
138
88
  - lib/rubocop/cop/rspec/expect_in_hook.rb
139
89
  - lib/rubocop/cop/rspec/expect_in_let.rb
140
90
  - lib/rubocop/cop/rspec/expect_output.rb
141
- - lib/rubocop/cop/rspec/factory_bot/attribute_defined_statically.rb
142
- - lib/rubocop/cop/rspec/factory_bot/consistent_parentheses_style.rb
143
- - lib/rubocop/cop/rspec/factory_bot/create_list.rb
144
- - lib/rubocop/cop/rspec/factory_bot/factory_class_name.rb
145
- - lib/rubocop/cop/rspec/factory_bot/factory_name_style.rb
146
- - lib/rubocop/cop/rspec/factory_bot/syntax_methods.rb
147
- - lib/rubocop/cop/rspec/file_path.rb
148
91
  - lib/rubocop/cop/rspec/focus.rb
149
92
  - lib/rubocop/cop/rspec/hook_argument.rb
150
93
  - lib/rubocop/cop/rspec/hooks_before_examples.rb
@@ -168,6 +111,7 @@ files:
168
111
  - lib/rubocop/cop/rspec/message_spies.rb
169
112
  - lib/rubocop/cop/rspec/metadata_style.rb
170
113
  - lib/rubocop/cop/rspec/missing_example_group_argument.rb
114
+ - lib/rubocop/cop/rspec/missing_expectation_target_method.rb
171
115
  - lib/rubocop/cop/rspec/mixin/comments_help.rb
172
116
  - lib/rubocop/cop/rspec/mixin/empty_line_separation.rb
173
117
  - lib/rubocop/cop/rspec/mixin/file_help.rb
@@ -191,13 +135,6 @@ files:
191
135
  - lib/rubocop/cop/rspec/pending.rb
192
136
  - lib/rubocop/cop/rspec/pending_without_reason.rb
193
137
  - lib/rubocop/cop/rspec/predicate_matcher.rb
194
- - lib/rubocop/cop/rspec/rails/avoid_setup_hook.rb
195
- - lib/rubocop/cop/rspec/rails/have_http_status.rb
196
- - lib/rubocop/cop/rspec/rails/http_status.rb
197
- - lib/rubocop/cop/rspec/rails/inferred_spec_type.rb
198
- - lib/rubocop/cop/rspec/rails/minitest_assertions.rb
199
- - lib/rubocop/cop/rspec/rails/negation_be_valid.rb
200
- - lib/rubocop/cop/rspec/rails/travel_around.rb
201
138
  - lib/rubocop/cop/rspec/receive_counts.rb
202
139
  - lib/rubocop/cop/rspec/receive_messages.rb
203
140
  - lib/rubocop/cop/rspec/receive_never.rb
@@ -236,6 +173,7 @@ files:
236
173
  - lib/rubocop/rspec/align_let_brace.rb
237
174
  - lib/rubocop/rspec/concept.rb
238
175
  - lib/rubocop/rspec/config_formatter.rb
176
+ - lib/rubocop/rspec/cop/generator.rb
239
177
  - lib/rubocop/rspec/corrector/move_node.rb
240
178
  - lib/rubocop/rspec/description_extractor.rb
241
179
  - lib/rubocop/rspec/example.rb
@@ -243,7 +181,6 @@ files:
243
181
  - lib/rubocop/rspec/hook.rb
244
182
  - lib/rubocop/rspec/inject.rb
245
183
  - lib/rubocop/rspec/language.rb
246
- - lib/rubocop/rspec/language/node_pattern.rb
247
184
  - lib/rubocop/rspec/node.rb
248
185
  - lib/rubocop/rspec/shared_contexts/default_rspec_language_config_context.rb
249
186
  - lib/rubocop/rspec/version.rb
@@ -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