rubocop-rspec 1.32.0 → 1.33.0

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 (162) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +11 -0
  3. data/Gemfile +2 -0
  4. data/Rakefile +2 -0
  5. data/config/default.yml +6 -0
  6. data/lib/rubocop-rspec.rb +3 -0
  7. data/lib/rubocop/cop/rspec/align_left_let_brace.rb +1 -1
  8. data/lib/rubocop/cop/rspec/align_right_let_brace.rb +1 -1
  9. data/lib/rubocop/cop/rspec/any_instance.rb +3 -1
  10. data/lib/rubocop/cop/rspec/around_block.rb +4 -2
  11. data/lib/rubocop/cop/rspec/be.rb +4 -2
  12. data/lib/rubocop/cop/rspec/be_eql.rb +3 -1
  13. data/lib/rubocop/cop/rspec/before_after_all.rb +1 -1
  14. data/lib/rubocop/cop/rspec/capybara/current_path_expectation.rb +5 -3
  15. data/lib/rubocop/cop/rspec/capybara/feature_methods.rb +3 -3
  16. data/lib/rubocop/cop/rspec/context_wording.rb +2 -2
  17. data/lib/rubocop/cop/rspec/describe_class.rb +4 -4
  18. data/lib/rubocop/cop/rspec/describe_method.rb +2 -2
  19. data/lib/rubocop/cop/rspec/describe_symbol.rb +2 -2
  20. data/lib/rubocop/cop/rspec/described_class.rb +3 -3
  21. data/lib/rubocop/cop/rspec/dialect.rb +76 -0
  22. data/lib/rubocop/cop/rspec/empty_example_group.rb +1 -1
  23. data/lib/rubocop/cop/rspec/empty_line_after_example_group.rb +1 -1
  24. data/lib/rubocop/cop/rspec/empty_line_after_final_let.rb +1 -1
  25. data/lib/rubocop/cop/rspec/empty_line_after_hook.rb +1 -1
  26. data/lib/rubocop/cop/rspec/empty_line_after_subject.rb +1 -1
  27. data/lib/rubocop/cop/rspec/example_length.rb +1 -1
  28. data/lib/rubocop/cop/rspec/example_without_description.rb +2 -2
  29. data/lib/rubocop/cop/rspec/example_wording.rb +2 -2
  30. data/lib/rubocop/cop/rspec/expect_actual.rb +1 -1
  31. data/lib/rubocop/cop/rspec/expect_change.rb +2 -2
  32. data/lib/rubocop/cop/rspec/expect_in_hook.rb +1 -1
  33. data/lib/rubocop/cop/rspec/expect_output.rb +1 -1
  34. data/lib/rubocop/cop/rspec/factory_bot/attribute_defined_statically.rb +21 -40
  35. data/lib/rubocop/cop/rspec/factory_bot/create_list.rb +2 -2
  36. data/lib/rubocop/cop/rspec/file_path.rb +2 -2
  37. data/lib/rubocop/cop/rspec/focus.rb +3 -3
  38. data/lib/rubocop/cop/rspec/hook_argument.rb +4 -6
  39. data/lib/rubocop/cop/rspec/hooks_before_examples.rb +2 -5
  40. data/lib/rubocop/cop/rspec/implicit_expect.rb +2 -2
  41. data/lib/rubocop/cop/rspec/implicit_subject.rb +1 -1
  42. data/lib/rubocop/cop/rspec/instance_spy.rb +1 -1
  43. data/lib/rubocop/cop/rspec/instance_variable.rb +1 -1
  44. data/lib/rubocop/cop/rspec/invalid_predicate_matcher.rb +4 -2
  45. data/lib/rubocop/cop/rspec/it_behaves_like.rb +1 -1
  46. data/lib/rubocop/cop/rspec/iterated_expectation.rb +3 -1
  47. data/lib/rubocop/cop/rspec/leading_subject.rb +1 -2
  48. data/lib/rubocop/cop/rspec/let_before_examples.rb +2 -5
  49. data/lib/rubocop/cop/rspec/let_setup.rb +1 -1
  50. data/lib/rubocop/cop/rspec/message_chain.rb +3 -1
  51. data/lib/rubocop/cop/rspec/message_expectation.rb +1 -1
  52. data/lib/rubocop/cop/rspec/message_spies.rb +3 -4
  53. data/lib/rubocop/cop/rspec/missing_example_group_argument.rb +1 -1
  54. data/lib/rubocop/cop/rspec/multiple_describes.rb +1 -1
  55. data/lib/rubocop/cop/rspec/multiple_expectations.rb +1 -1
  56. data/lib/rubocop/cop/rspec/multiple_subjects.rb +6 -2
  57. data/lib/rubocop/cop/rspec/named_subject.rb +1 -1
  58. data/lib/rubocop/cop/rspec/nested_groups.rb +3 -4
  59. data/lib/rubocop/cop/rspec/not_to_not.rb +3 -1
  60. data/lib/rubocop/cop/rspec/overwriting_setup.rb +1 -1
  61. data/lib/rubocop/cop/rspec/pending.rb +3 -3
  62. data/lib/rubocop/cop/rspec/predicate_matcher.rb +17 -14
  63. data/lib/rubocop/cop/rspec/rails/http_status.rb +2 -2
  64. data/lib/rubocop/cop/rspec/receive_counts.rb +5 -6
  65. data/lib/rubocop/cop/rspec/receive_never.rb +4 -7
  66. data/lib/rubocop/cop/rspec/repeated_description.rb +3 -1
  67. data/lib/rubocop/cop/rspec/repeated_example.rb +3 -1
  68. data/lib/rubocop/cop/rspec/return_from_stub.rb +2 -2
  69. data/lib/rubocop/cop/rspec/scattered_let.rb +1 -1
  70. data/lib/rubocop/cop/rspec/scattered_setup.rb +1 -1
  71. data/lib/rubocop/cop/rspec/shared_context.rb +2 -2
  72. data/lib/rubocop/cop/rspec/shared_examples.rb +7 -7
  73. data/lib/rubocop/cop/rspec/single_argument_message_chain.rb +3 -1
  74. data/lib/rubocop/cop/rspec/subject_stub.rb +1 -1
  75. data/lib/rubocop/cop/rspec/unspecified_exception.rb +5 -3
  76. data/lib/rubocop/cop/rspec/verified_doubles.rb +2 -2
  77. data/lib/rubocop/cop/rspec/void_expect.rb +1 -1
  78. data/lib/rubocop/cop/rspec/yield.rb +2 -4
  79. data/lib/rubocop/cop/rspec_cops.rb +3 -0
  80. data/lib/rubocop/rspec.rb +2 -0
  81. data/lib/rubocop/rspec/blank_line_separation.rb +3 -1
  82. data/lib/rubocop/rspec/config_formatter.rb +3 -1
  83. data/lib/rubocop/rspec/description_extractor.rb +3 -1
  84. data/lib/rubocop/rspec/factory_bot.rb +58 -0
  85. data/lib/rubocop/rspec/final_end_location.rb +2 -0
  86. data/lib/rubocop/rspec/inject.rb +2 -0
  87. data/lib/rubocop/rspec/language.rb +9 -2
  88. data/lib/rubocop/rspec/top_level_describe.rb +2 -0
  89. data/lib/rubocop/rspec/version.rb +1 -1
  90. data/rubocop-rspec.gemspec +3 -1
  91. data/spec/project/changelog_spec.rb +2 -0
  92. data/spec/project/default_config_spec.rb +2 -0
  93. data/spec/project/project_requires_spec.rb +2 -0
  94. data/spec/rubocop/cop/rspec/align_left_let_brace_spec.rb +22 -37
  95. data/spec/rubocop/cop/rspec/align_right_let_brace_spec.rb +21 -36
  96. data/spec/rubocop/cop/rspec/any_instance_spec.rb +2 -0
  97. data/spec/rubocop/cop/rspec/around_block_spec.rb +2 -0
  98. data/spec/rubocop/cop/rspec/be_eql_spec.rb +25 -4
  99. data/spec/rubocop/cop/rspec/be_spec.rb +2 -0
  100. data/spec/rubocop/cop/rspec/before_after_all_spec.rb +2 -0
  101. data/spec/rubocop/cop/rspec/capybara/current_path_expectation_spec.rb +2 -0
  102. data/spec/rubocop/cop/rspec/capybara/feature_methods_spec.rb +2 -0
  103. data/spec/rubocop/cop/rspec/context_wording_spec.rb +32 -0
  104. data/spec/rubocop/cop/rspec/describe_class_spec.rb +2 -0
  105. data/spec/rubocop/cop/rspec/describe_method_spec.rb +2 -0
  106. data/spec/rubocop/cop/rspec/describe_symbol_spec.rb +2 -0
  107. data/spec/rubocop/cop/rspec/described_class_spec.rb +4 -1
  108. data/spec/rubocop/cop/rspec/dialect_spec.rb +78 -0
  109. data/spec/rubocop/cop/rspec/empty_line_after_example_group_spec.rb +40 -21
  110. data/spec/rubocop/cop/rspec/empty_line_after_final_let_spec.rb +77 -69
  111. data/spec/rubocop/cop/rspec/empty_line_after_hook_spec.rb +24 -19
  112. data/spec/rubocop/cop/rspec/empty_line_after_subject_spec.rb +16 -19
  113. data/spec/rubocop/cop/rspec/example_length_spec.rb +2 -0
  114. data/spec/rubocop/cop/rspec/example_without_description_spec.rb +2 -0
  115. data/spec/rubocop/cop/rspec/example_wording_spec.rb +45 -24
  116. data/spec/rubocop/cop/rspec/expect_change_spec.rb +22 -14
  117. data/spec/rubocop/cop/rspec/factory_bot/attribute_defined_statically_spec.rb +36 -0
  118. data/spec/rubocop/cop/rspec/factory_bot/create_list_spec.rb +2 -0
  119. data/spec/rubocop/cop/rspec/file_path_spec.rb +2 -0
  120. data/spec/rubocop/cop/rspec/focus_spec.rb +2 -2
  121. data/spec/rubocop/cop/rspec/hook_argument_spec.rb +2 -0
  122. data/spec/rubocop/cop/rspec/hooks_before_examples_spec.rb +47 -32
  123. data/spec/rubocop/cop/rspec/implicit_expect_spec.rb +20 -19
  124. data/spec/rubocop/cop/rspec/implicit_subject_spec.rb +56 -68
  125. data/spec/rubocop/cop/rspec/instance_spy_spec.rb +16 -15
  126. data/spec/rubocop/cop/rspec/instance_variable_spec.rb +2 -0
  127. data/spec/rubocop/cop/rspec/invalid_predicate_matcher_spec.rb +2 -0
  128. data/spec/rubocop/cop/rspec/it_behaves_like_spec.rb +10 -12
  129. data/spec/rubocop/cop/rspec/iterated_expectation_spec.rb +2 -0
  130. data/spec/rubocop/cop/rspec/leading_subject_spec.rb +31 -47
  131. data/spec/rubocop/cop/rspec/let_before_examples_spec.rb +27 -26
  132. data/spec/rubocop/cop/rspec/message_chain_spec.rb +2 -0
  133. data/spec/rubocop/cop/rspec/missing_example_group_argument_spec.rb +2 -0
  134. data/spec/rubocop/cop/rspec/multiple_describes_spec.rb +2 -0
  135. data/spec/rubocop/cop/rspec/multiple_subjects_spec.rb +24 -37
  136. data/spec/rubocop/cop/rspec/not_to_not_spec.rb +22 -32
  137. data/spec/rubocop/cop/rspec/overwriting_setup_spec.rb +2 -0
  138. data/spec/rubocop/cop/rspec/pending_spec.rb +2 -0
  139. data/spec/rubocop/cop/rspec/predicate_matcher_spec.rb +2 -0
  140. data/spec/rubocop/cop/rspec/receive_counts_spec.rb +47 -8
  141. data/spec/rubocop/cop/rspec/receive_never_spec.rb +16 -4
  142. data/spec/rubocop/cop/rspec/return_from_stub_spec.rb +95 -72
  143. data/spec/rubocop/cop/rspec/scattered_let_spec.rb +2 -0
  144. data/spec/rubocop/cop/rspec/scattered_setup_spec.rb +2 -0
  145. data/spec/rubocop/cop/rspec/shared_context_spec.rb +29 -34
  146. data/spec/rubocop/cop/rspec/shared_examples_spec.rb +16 -34
  147. data/spec/rubocop/cop/rspec/single_argument_message_chain_spec.rb +44 -48
  148. data/spec/rubocop/cop/rspec/unspecified_exception_spec.rb +2 -0
  149. data/spec/rubocop/cop/rspec/verified_doubles_spec.rb +2 -0
  150. data/spec/rubocop/cop/rspec/void_expect_spec.rb +2 -0
  151. data/spec/rubocop/cop/rspec/yield_spec.rb +22 -21
  152. data/spec/rubocop/rspec/config_formatter_spec.rb +2 -0
  153. data/spec/rubocop/rspec/description_extractor_spec.rb +2 -0
  154. data/spec/rubocop/rspec/language/selector_set_spec.rb +2 -0
  155. data/spec/rubocop/rspec/util/one_spec.rb +2 -0
  156. data/spec/rubocop/rspec/wording_spec.rb +2 -0
  157. data/spec/shared/autocorrect_behavior.rb +2 -0
  158. data/spec/shared/detects_style_behavior.rb +2 -0
  159. data/spec/shared/smoke_test_examples.rb +2 -0
  160. data/spec/spec_helper.rb +2 -0
  161. data/spec/support/expect_offense.rb +3 -1
  162. metadata +8 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c0fcdb4a1fb882713a667ae92edf352ee496300bd20cbd44c79ec0c79773691f
4
- data.tar.gz: 22ed75baf52c414c530edef39ba1a2b361c4e2060711775c093585c7a10ffe53
3
+ metadata.gz: 53e671fa54f485f07186b567e9e44f7522db1e9508f5f723549c1f50f467ef68
4
+ data.tar.gz: 5f842a528fb62843a686e9674d4b94f5a44008afbc602c9babfb91ddf90ef4df
5
5
  SHA512:
6
- metadata.gz: 597bacb5b6c60657a33532a1d625008030338e16f8fca2e42d1a9b0dc4bf76a6e9296d8fb2948ad0947bb522212bc53ef997fc4155168c89e76c66fda4e6ef87
7
- data.tar.gz: 9ecac64a0f6cccba7a794125e0e4bd0bd47722f8e5d2a3efed8828709fdc8c682ca09794a74c33d92f6feec90d70b856d2bf1f544d13c51fc4f63d7c398568e1
6
+ metadata.gz: 1e03a650246098cb4498448db4e91846bb25643ea3673ec54db68678dbe80acefecbc69f20ca484addbea5f8a97a7dd84e3d21205b14da21cc74de45d8048501
7
+ data.tar.gz: 1d3cfdc4b32495be01056e6435bebaf1c1575bb37bda80973c31095ec4ce2f3556ce90ad9360e81102522869fa57c1f0eb6d005d670820b75df00c70e689131e
data/CHANGELOG.md CHANGED
@@ -2,6 +2,15 @@
2
2
 
3
3
  ## Master (Unreleased)
4
4
 
5
+ ## 1.33.0 (2019-05-13)
6
+
7
+ * Let `RSpec/DescribedClass` pass `Struct` instantiation closures. ([@schmijos][])
8
+ * Fixed `RSpec/ContextWording` missing `context`s with metadata. ([@pirj][])
9
+ * Fix `FactoryBot/AttributeDefinedStatically` not working with an explicit receiver. ([@composerinteralia][])
10
+ * Add `RSpec/Dialect` enforces custom RSpec dialects. ([@gsamokovarov][])
11
+ * Fix redundant blank lines in `RSpec/MultipleSubjects`'s autocorrect. ([@pirj][])
12
+ * Drop support for ruby `2.2`. ([@bquorning][])
13
+
5
14
  ## 1.32.0 (2019-01-27)
6
15
 
7
16
  * Add `RSpec/Yield` cop, suggesting using the `and_yield` method when stubbing a method, accepting a block. ([@Darhazer][])
@@ -407,3 +416,5 @@ Compatibility release so users can upgrade RuboCop to 0.51.0. No new features.
407
416
  [@RST-J]: https://github.com/RST-J
408
417
  [@ypresto]: https://github.com/ypresto
409
418
  [@mkenyon]: https://github.com/mkenyon
419
+ [@gsamokovarov]: https://github.com/gsamokovarov
420
+ [@schmijos]: https://github.com/schmijos
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  gemspec
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'open3'
2
4
 
3
5
  require 'bundler'
data/config/default.yml CHANGED
@@ -83,6 +83,12 @@ RSpec/DescribedClass:
83
83
  - explicit
84
84
  StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/DescribedClass
85
85
 
86
+ RSpec/Dialect:
87
+ Description: This cop enforces custom RSpec dialects.
88
+ Enabled: false
89
+ PreferredMethods: {}
90
+ StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Dialect
91
+
86
92
  RSpec/EmptyExampleGroup:
87
93
  Description: Checks if an example group does not include any tests.
88
94
  Enabled: true
data/lib/rubocop-rspec.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'pathname'
2
4
  require 'yaml'
3
5
 
@@ -18,6 +20,7 @@ require_relative 'rubocop/rspec/example'
18
20
  require_relative 'rubocop/rspec/hook'
19
21
  require_relative 'rubocop/cop/rspec/cop'
20
22
  require_relative 'rubocop/rspec/align_let_brace'
23
+ require_relative 'rubocop/rspec/factory_bot'
21
24
  require_relative 'rubocop/rspec/final_end_location'
22
25
  require_relative 'rubocop/rspec/blank_line_separation'
23
26
 
@@ -18,7 +18,7 @@ module RuboCop
18
18
  # let(:a) { b }
19
19
  #
20
20
  class AlignLeftLetBrace < Cop
21
- MSG = 'Align left let brace'.freeze
21
+ MSG = 'Align left let brace'
22
22
 
23
23
  def self.autocorrect_incompatible_with
24
24
  [Layout::ExtraSpacing]
@@ -18,7 +18,7 @@ module RuboCop
18
18
  # let(:a) { b }
19
19
  #
20
20
  class AlignRightLetBrace < Cop
21
- MSG = 'Align right let brace'.freeze
21
+ MSG = 'Align right let brace'
22
22
 
23
23
  def self.autocorrect_incompatible_with
24
24
  [Layout::ExtraSpacing]
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RuboCop
2
4
  module Cop
3
5
  module RSpec
@@ -21,7 +23,7 @@ module RuboCop
21
23
  # end
22
24
  # end
23
25
  class AnyInstance < Cop
24
- MSG = 'Avoid stubbing using `%<method>s`.'.freeze
26
+ MSG = 'Avoid stubbing using `%<method>s`.'
25
27
 
26
28
  def_node_matcher :disallowed_stub, <<-PATTERN
27
29
  (send _ ${:any_instance :allow_any_instance_of :expect_any_instance_of} ...)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RuboCop
2
4
  module Cop
3
5
  module RSpec
@@ -24,9 +26,9 @@ module RuboCop
24
26
  # test.run
25
27
  # end
26
28
  class AroundBlock < Cop
27
- MSG_NO_ARG = 'Test object should be passed to around block.'.freeze
29
+ MSG_NO_ARG = 'Test object should be passed to around block.'
28
30
  MSG_UNUSED_ARG = 'You should call `%<arg>s.call` '\
29
- 'or `%<arg>s.run`.'.freeze
31
+ 'or `%<arg>s.run`.'
30
32
 
31
33
  def_node_matcher :hook, <<-PATTERN
32
34
  (block {(send nil? :around) (send nil? :around sym)} (args $...) ...)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RuboCop
2
4
  module Cop
3
5
  module RSpec
@@ -18,10 +20,10 @@ module RuboCop
18
20
  # expect(foo).to be(true)
19
21
  #
20
22
  class Be < Cop
21
- MSG = 'Don\'t use `be` without an argument.'.freeze
23
+ MSG = 'Don\'t use `be` without an argument.'
22
24
 
23
25
  def_node_matcher :be_without_args, <<-PATTERN
24
- (send _ {:to :not_to :to_not} $(send nil? :be))
26
+ (send _ #{Runners::ALL.node_pattern_union} $(send nil? :be))
25
27
  PATTERN
26
28
 
27
29
  def on_send(node)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RuboCop
2
4
  module Cop
3
5
  module RSpec
@@ -34,7 +36,7 @@ module RuboCop
34
36
  # coerce objects for comparison.
35
37
  #
36
38
  class BeEql < Cop
37
- MSG = 'Prefer `be` over `eql`.'.freeze
39
+ MSG = 'Prefer `be` over `eql`.'
38
40
 
39
41
  def_node_matcher :eql_type_with_identity, <<-PATTERN
40
42
  (send _ :to $(send nil? :eql {true false int float sym nil_type?}))
@@ -27,7 +27,7 @@ module RuboCop
27
27
  MSG = 'Beware of using `%<hook>s` as it may cause state to leak '\
28
28
  'between tests. If you are using `rspec-rails`, and '\
29
29
  '`use_transactional_fixtures` is enabled, then records created '\
30
- 'in `%<hook>s` are not automatically rolled back.'.freeze
30
+ 'in `%<hook>s` are not automatically rolled back.'
31
31
 
32
32
  def_node_matcher :before_or_after_all, <<-PATTERN
33
33
  $(send _ {:before :after} (sym {:all :context}))
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RuboCop
2
4
  module Cop
3
5
  module RSpec
@@ -24,7 +26,7 @@ module RuboCop
24
26
  class CurrentPathExpectation < Cop
25
27
  MSG = 'Do not set an RSpec expectation on `current_path` in ' \
26
28
  'Capybara feature specs - instead, use the ' \
27
- '`have_current_path` matcher on `page`'.freeze
29
+ '`have_current_path` matcher on `page`'
28
30
 
29
31
  def_node_matcher :expectation_set_on_current_path, <<-PATTERN
30
32
  (send nil? :expect (send {(send nil? :page) nil?} :current_path))
@@ -33,13 +35,13 @@ module RuboCop
33
35
  # Supported matchers: eq(...) / match(/regexp/) / match('regexp')
34
36
  def_node_matcher :as_is_matcher, <<-PATTERN
35
37
  (send
36
- #expectation_set_on_current_path ${:to :not_to :to_not}
38
+ #expectation_set_on_current_path $#{Runners::ALL.node_pattern_union}
37
39
  ${(send nil? :eq ...) (send nil? :match (regexp ...))})
38
40
  PATTERN
39
41
 
40
42
  def_node_matcher :regexp_str_matcher, <<-PATTERN
41
43
  (send
42
- #expectation_set_on_current_path ${:to :not_to :to_not}
44
+ #expectation_set_on_current_path $#{Runners::ALL.node_pattern_union}
43
45
  $(send nil? :match (str $_)))
44
46
  PATTERN
45
47
 
@@ -41,7 +41,7 @@ module RuboCop
41
41
  # end
42
42
  # end
43
43
  class FeatureMethods < Cop
44
- MSG = 'Use `%<replacement>s` instead of `%<method>s`.'.freeze
44
+ MSG = 'Use `%<replacement>s` instead of `%<method>s`.'
45
45
 
46
46
  # https://git.io/v7Kwr
47
47
  MAP = {
@@ -55,13 +55,13 @@ module RuboCop
55
55
 
56
56
  def_node_matcher :spec?, <<-PATTERN
57
57
  (block
58
- (send {(const nil? :RSpec) nil?} {:describe :feature} ...)
58
+ (send #{RSPEC} {:describe :feature} ...)
59
59
  ...)
60
60
  PATTERN
61
61
 
62
62
  def_node_matcher :feature_method, <<-PATTERN
63
63
  (block
64
- $(send {(const nil? :RSpec) nil?} ${#{MAP.keys.map(&:inspect).join(' ')}} ...)
64
+ $(send #{RSPEC} ${#{MAP.keys.map(&:inspect).join(' ')}} ...)
65
65
  ...)
66
66
  PATTERN
67
67
 
@@ -27,10 +27,10 @@ module RuboCop
27
27
  # # ...
28
28
  # end
29
29
  class ContextWording < Cop
30
- MSG = 'Start context description with %<prefixes>s.'.freeze
30
+ MSG = 'Start context description with %<prefixes>s.'
31
31
 
32
32
  def_node_matcher :context_wording, <<-PATTERN
33
- (block (send _ { :context :shared_context } $(str #bad_prefix?)) ...)
33
+ (block (send #{RSPEC} { :context :shared_context } $(str #bad_prefix?) ...) ...)
34
34
  PATTERN
35
35
 
36
36
  def on_block(node)
@@ -20,17 +20,17 @@ module RuboCop
20
20
  include RuboCop::RSpec::TopLevelDescribe
21
21
 
22
22
  MSG = 'The first argument to describe should be '\
23
- 'the class or module being tested.'.freeze
23
+ 'the class or module being tested.'
24
24
 
25
25
  def_node_matcher :valid_describe?, <<-PATTERN
26
26
  {
27
- (send {(const nil? :RSpec) nil?} :describe const ...)
28
- (send {(const nil? :RSpec) nil?} :describe)
27
+ (send #{RSPEC} :describe const ...)
28
+ (send #{RSPEC} :describe)
29
29
  }
30
30
  PATTERN
31
31
 
32
32
  def_node_matcher :describe_with_metadata, <<-PATTERN
33
- (send {(const nil? :RSpec) nil?} :describe
33
+ (send #{RSPEC} :describe
34
34
  !const
35
35
  ...
36
36
  (hash $...))
@@ -21,10 +21,10 @@ module RuboCop
21
21
  include RuboCop::RSpec::Util
22
22
 
23
23
  MSG = 'The second argument to describe should be the method '\
24
- "being tested. '#instance' or '.class'.".freeze
24
+ "being tested. '#instance' or '.class'."
25
25
 
26
26
  def on_top_level_describe(_node, (_, second_arg))
27
- return unless second_arg && second_arg.str_type?
27
+ return unless second_arg&.str_type?
28
28
  return if second_arg.str_content.start_with?('#', '.')
29
29
 
30
30
  add_offense(second_arg, location: :expression)
@@ -18,10 +18,10 @@ module RuboCop
18
18
  #
19
19
  # @see https://github.com/rspec/rspec-core/issues/1610
20
20
  class DescribeSymbol < Cop
21
- MSG = 'Avoid describing symbols.'.freeze
21
+ MSG = 'Avoid describing symbols.'
22
22
 
23
23
  def_node_matcher :describe_symbol?, <<-PATTERN
24
- (send {(const nil? :RSpec) nil?} :describe $sym ...)
24
+ (send #{RSPEC} :describe $sym ...)
25
25
  PATTERN
26
26
 
27
27
  def on_send(node)
@@ -36,11 +36,11 @@ module RuboCop
36
36
  include RuboCop::RSpec::TopLevelDescribe
37
37
  include ConfigurableEnforcedStyle
38
38
 
39
- DESCRIBED_CLASS = 'described_class'.freeze
40
- MSG = 'Use `%<replacement>s` instead of `%<src>s`.'.freeze
39
+ DESCRIBED_CLASS = 'described_class'
40
+ MSG = 'Use `%<replacement>s` instead of `%<src>s`.'
41
41
 
42
42
  def_node_matcher :common_instance_exec_closure?, <<-PATTERN
43
- (block (send (const nil? {:Class :Module}) :new ...) ...)
43
+ (block (send (const nil? {:Class :Module :Struct}) :new ...) ...)
44
44
  PATTERN
45
45
 
46
46
  def_node_matcher :rspec_block?,
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module RSpec
6
+ # This cop enforces custom RSpec dialects.
7
+ #
8
+ # A dialect can be based on the following RSpec methods:
9
+ #
10
+ # - describe, context, feature, example_group
11
+ # - xdescribe, xcontext, xfeature
12
+ # - fdescribe, fcontext, ffeature
13
+ # - shared_examples, shared_examples_for, shared_context
14
+ # - it, specify, example, scenario, its
15
+ # - fit, fspecify, fexample, fscenario, focus
16
+ # - xit, xspecify, xexample, xscenario, skip
17
+ # - pending
18
+ # - prepend_before, before, append_before,
19
+ # - around
20
+ # - prepend_after, after, append_after
21
+ # - let, let!
22
+ # - subject, subject!
23
+ # - expect, is_expected, expect_any_instance_of
24
+ #
25
+ # By default all of the RSpec methods and aliases are allowed. By setting
26
+ # a config like:
27
+ #
28
+ # RSpec/Dialect:
29
+ # PreferredMethods:
30
+ # context: describe
31
+ #
32
+ # You can expect the following behavior:
33
+ #
34
+ # @example
35
+ # # bad
36
+ # context 'display name presence' do
37
+ # # ...
38
+ # end
39
+ #
40
+ # # good
41
+ # describe 'display name presence' do
42
+ # # ...
43
+ # end
44
+ class Dialect < Cop
45
+ include MethodPreference
46
+
47
+ MSG = 'Prefer `%<prefer>s` over `%<current>s`.'
48
+
49
+ def_node_matcher :rspec_method?, ALL.send_pattern
50
+
51
+ def on_send(node)
52
+ return unless rspec_method?(node)
53
+ return unless preferred_methods[node.method_name]
54
+
55
+ add_offense(node)
56
+ end
57
+
58
+ def autocorrect(node)
59
+ lambda do |corrector|
60
+ current = node.loc.selector
61
+ preferred = preferred_method(current.source)
62
+
63
+ corrector.replace(current, preferred)
64
+ end
65
+ end
66
+
67
+ private
68
+
69
+ def message(node)
70
+ format(MSG, prefer: preferred_method(node.method_name),
71
+ current: node.method_name)
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
@@ -58,7 +58,7 @@ module RuboCop
58
58
  # end
59
59
  #
60
60
  class EmptyExampleGroup < Cop
61
- MSG = 'Empty example group detected.'.freeze
61
+ MSG = 'Empty example group detected.'
62
62
 
63
63
  def_node_search :contains_example?, <<-PATTERN
64
64
  {
@@ -26,7 +26,7 @@ module RuboCop
26
26
  class EmptyLineAfterExampleGroup < Cop
27
27
  include RuboCop::RSpec::BlankLineSeparation
28
28
 
29
- MSG = 'Add an empty line after `%<example_group>s`.'.freeze
29
+ MSG = 'Add an empty line after `%<example_group>s`.'
30
30
 
31
31
  def on_block(node)
32
32
  return unless example_group?(node)
@@ -19,7 +19,7 @@ module RuboCop
19
19
  class EmptyLineAfterFinalLet < Cop
20
20
  include RuboCop::RSpec::BlankLineSeparation
21
21
 
22
- MSG = 'Add an empty line after the last `let` block.'.freeze
22
+ MSG = 'Add an empty line after the last `let` block.'
23
23
 
24
24
  def on_block(node)
25
25
  return unless example_group_with_body?(node)
@@ -36,7 +36,7 @@ module RuboCop
36
36
  class EmptyLineAfterHook < Cop
37
37
  include RuboCop::RSpec::BlankLineSeparation
38
38
 
39
- MSG = 'Add an empty line after `%<hook>s`.'.freeze
39
+ MSG = 'Add an empty line after `%<hook>s`.'
40
40
 
41
41
  def on_block(node)
42
42
  return unless hook?(node)
@@ -17,7 +17,7 @@ module RuboCop
17
17
  class EmptyLineAfterSubject < Cop
18
18
  include RuboCop::RSpec::BlankLineSeparation
19
19
 
20
- MSG = 'Add empty line after `subject`.'.freeze
20
+ MSG = 'Add empty line after `subject`.'
21
21
 
22
22
  def on_block(node)
23
23
  return unless subject?(node) && !in_spec_block?(node)