rubocop-rspec 2.0.0 → 2.4.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.
- checksums.yaml +4 -4
 - data/CHANGELOG.md +39 -0
 - data/README.md +3 -3
 - data/config/default.yml +141 -125
 - data/lib/rubocop-rspec.rb +1 -0
 - data/lib/rubocop/cop/rspec/any_instance.rb +6 -10
 - data/lib/rubocop/cop/rspec/around_block.rb +3 -1
 - data/lib/rubocop/cop/rspec/be.rb +2 -1
 - data/lib/rubocop/cop/rspec/be_eql.rb +2 -0
 - data/lib/rubocop/cop/rspec/before_after_all.rb +6 -3
 - data/lib/rubocop/cop/rspec/capybara/current_path_expectation.rb +5 -0
 - data/lib/rubocop/cop/rspec/capybara/feature_methods.rb +3 -0
 - data/lib/rubocop/cop/rspec/capybara/visibility_matcher.rb +4 -0
 - data/lib/rubocop/cop/rspec/context_method.rb +1 -0
 - data/lib/rubocop/cop/rspec/context_wording.rb +7 -1
 - data/lib/rubocop/cop/rspec/describe_class.rb +4 -1
 - data/lib/rubocop/cop/rspec/describe_method.rb +2 -1
 - data/lib/rubocop/cop/rspec/describe_symbol.rb +2 -0
 - data/lib/rubocop/cop/rspec/described_class.rb +6 -1
 - data/lib/rubocop/cop/rspec/described_class_module_wrapping.rb +2 -1
 - data/lib/rubocop/cop/rspec/dialect.rb +1 -0
 - data/lib/rubocop/cop/rspec/empty_hook.rb +1 -0
 - data/lib/rubocop/cop/rspec/example_length.rb +26 -12
 - data/lib/rubocop/cop/rspec/example_without_description.rb +1 -0
 - data/lib/rubocop/cop/rspec/example_wording.rb +1 -0
 - data/lib/rubocop/cop/rspec/expect_actual.rb +2 -0
 - data/lib/rubocop/cop/rspec/expect_change.rb +6 -3
 - data/lib/rubocop/cop/rspec/expect_in_hook.rb +1 -0
 - data/lib/rubocop/cop/rspec/expect_output.rb +1 -1
 - data/lib/rubocop/cop/rspec/factory_bot/attribute_defined_statically.rb +3 -0
 - data/lib/rubocop/cop/rspec/factory_bot/create_list.rb +4 -0
 - data/lib/rubocop/cop/rspec/factory_bot/factory_class_name.rb +2 -0
 - data/lib/rubocop/cop/rspec/file_path.rb +31 -20
 - data/lib/rubocop/cop/rspec/focus.rb +33 -1
 - data/lib/rubocop/cop/rspec/hook_argument.rb +2 -0
 - data/lib/rubocop/cop/rspec/hooks_before_examples.rb +1 -0
 - data/lib/rubocop/cop/rspec/identical_equality_assertion.rb +38 -0
 - data/lib/rubocop/cop/rspec/implicit_block_expectation.rb +4 -0
 - data/lib/rubocop/cop/rspec/implicit_expect.rb +1 -0
 - data/lib/rubocop/cop/rspec/implicit_subject.rb +19 -1
 - data/lib/rubocop/cop/rspec/instance_spy.rb +3 -1
 - data/lib/rubocop/cop/rspec/instance_variable.rb +4 -0
 - data/lib/rubocop/cop/rspec/it_behaves_like.rb +3 -1
 - data/lib/rubocop/cop/rspec/iterated_expectation.rb +3 -1
 - data/lib/rubocop/cop/rspec/let_before_examples.rb +1 -0
 - data/lib/rubocop/cop/rspec/let_setup.rb +3 -0
 - data/lib/rubocop/cop/rspec/message_chain.rb +4 -10
 - data/lib/rubocop/cop/rspec/message_expectation.rb +3 -0
 - data/lib/rubocop/cop/rspec/message_spies.rb +4 -2
 - data/lib/rubocop/cop/rspec/mixin/comments_help.rb +38 -0
 - data/lib/rubocop/cop/rspec/mixin/variable.rb +1 -0
 - data/lib/rubocop/cop/rspec/multiple_describes.rb +1 -2
 - data/lib/rubocop/cop/rspec/multiple_expectations.rb +3 -0
 - data/lib/rubocop/cop/rspec/named_subject.rb +3 -0
 - data/lib/rubocop/cop/rspec/not_to_not.rb +2 -0
 - data/lib/rubocop/cop/rspec/overwriting_setup.rb +2 -0
 - data/lib/rubocop/cop/rspec/pending.rb +4 -0
 - data/lib/rubocop/cop/rspec/predicate_matcher.rb +5 -0
 - data/lib/rubocop/cop/rspec/rails/avoid_setup_hook.rb +44 -0
 - data/lib/rubocop/cop/rspec/rails/http_status.rb +2 -0
 - data/lib/rubocop/cop/rspec/receive_counts.rb +4 -0
 - data/lib/rubocop/cop/rspec/receive_never.rb +2 -0
 - data/lib/rubocop/cop/rspec/repeated_example_group_body.rb +8 -1
 - data/lib/rubocop/cop/rspec/repeated_example_group_description.rb +4 -0
 - data/lib/rubocop/cop/rspec/repeated_include_example.rb +3 -0
 - data/lib/rubocop/cop/rspec/return_from_stub.rb +6 -0
 - data/lib/rubocop/cop/rspec/scattered_setup.rb +1 -1
 - data/lib/rubocop/cop/rspec/shared_context.rb +6 -5
 - data/lib/rubocop/cop/rspec/shared_examples.rb +1 -0
 - data/lib/rubocop/cop/rspec/single_argument_message_chain.rb +4 -1
 - data/lib/rubocop/cop/rspec/stubbed_mock.rb +1 -0
 - data/lib/rubocop/cop/rspec/subject_stub.rb +15 -4
 - data/lib/rubocop/cop/rspec/unspecified_exception.rb +2 -0
 - data/lib/rubocop/cop/rspec/verified_doubles.rb +2 -0
 - data/lib/rubocop/cop/rspec/void_expect.rb +3 -0
 - data/lib/rubocop/cop/rspec/yield.rb +3 -0
 - data/lib/rubocop/cop/rspec_cops.rb +2 -0
 - data/lib/rubocop/rspec/config_formatter.rb +3 -1
 - data/lib/rubocop/rspec/corrector/move_node.rb +6 -9
 - data/lib/rubocop/rspec/example.rb +5 -0
 - data/lib/rubocop/rspec/hook.rb +1 -0
 - data/lib/rubocop/rspec/language.rb +10 -0
 - data/lib/rubocop/rspec/node.rb +1 -1
 - data/lib/rubocop/rspec/version.rb +1 -1
 - metadata +9 -6
 
    
        data/lib/rubocop-rspec.rb
    CHANGED
    
    | 
         @@ -15,6 +15,7 @@ require_relative 'rubocop/rspec/language' 
     | 
|
| 
       15 
15 
     | 
    
         
             
            require_relative 'rubocop/cop/rspec/mixin/top_level_group'
         
     | 
| 
       16 
16 
     | 
    
         
             
            require_relative 'rubocop/cop/rspec/mixin/variable'
         
     | 
| 
       17 
17 
     | 
    
         
             
            require_relative 'rubocop/cop/rspec/mixin/final_end_location'
         
     | 
| 
      
 18 
     | 
    
         
            +
            require_relative 'rubocop/cop/rspec/mixin/comments_help'
         
     | 
| 
       18 
19 
     | 
    
         
             
            require_relative 'rubocop/cop/rspec/mixin/empty_line_separation'
         
     | 
| 
       19 
20 
     | 
    
         | 
| 
       20 
21 
     | 
    
         
             
            require_relative 'rubocop/rspec/concept'
         
     | 
| 
         @@ -24,18 +24,14 @@ module RuboCop 
     | 
|
| 
       24 
24 
     | 
    
         
             
                  #   end
         
     | 
| 
       25 
25 
     | 
    
         
             
                  class AnyInstance < Base
         
     | 
| 
       26 
26 
     | 
    
         
             
                    MSG = 'Avoid stubbing using `%<method>s`.'
         
     | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
       28 
     | 
    
         
            -
             
     | 
| 
       29 
     | 
    
         
            -
                       
     | 
| 
       30 
     | 
    
         
            -
             
     | 
| 
      
 27 
     | 
    
         
            +
                    RESTRICT_ON_SEND = %i[
         
     | 
| 
      
 28 
     | 
    
         
            +
                      any_instance
         
     | 
| 
      
 29 
     | 
    
         
            +
                      allow_any_instance_of
         
     | 
| 
      
 30 
     | 
    
         
            +
                      expect_any_instance_of
         
     | 
| 
      
 31 
     | 
    
         
            +
                    ].freeze
         
     | 
| 
       31 
32 
     | 
    
         | 
| 
       32 
33 
     | 
    
         
             
                    def on_send(node)
         
     | 
| 
       33 
     | 
    
         
            -
                       
     | 
| 
       34 
     | 
    
         
            -
                        add_offense(
         
     | 
| 
       35 
     | 
    
         
            -
                          node,
         
     | 
| 
       36 
     | 
    
         
            -
                          message: format(MSG, method: method)
         
     | 
| 
       37 
     | 
    
         
            -
                        )
         
     | 
| 
       38 
     | 
    
         
            -
                      end
         
     | 
| 
      
 34 
     | 
    
         
            +
                      add_offense(node, message: format(MSG, method: node.method_name))
         
     | 
| 
       39 
35 
     | 
    
         
             
                    end
         
     | 
| 
       40 
36 
     | 
    
         
             
                  end
         
     | 
| 
       41 
37 
     | 
    
         
             
                end
         
     | 
| 
         @@ -27,13 +27,15 @@ module RuboCop 
     | 
|
| 
       27 
27 
     | 
    
         
             
                  #   end
         
     | 
| 
       28 
28 
     | 
    
         
             
                  class AroundBlock < Base
         
     | 
| 
       29 
29 
     | 
    
         
             
                    MSG_NO_ARG     = 'Test object should be passed to around block.'
         
     | 
| 
       30 
     | 
    
         
            -
                    MSG_UNUSED_ARG = 'You should call `%<arg>s.call` '\
         
     | 
| 
      
 30 
     | 
    
         
            +
                    MSG_UNUSED_ARG = 'You should call `%<arg>s.call` ' \
         
     | 
| 
       31 
31 
     | 
    
         
             
                                     'or `%<arg>s.run`.'
         
     | 
| 
       32 
32 
     | 
    
         | 
| 
      
 33 
     | 
    
         
            +
                    # @!method hook(node)
         
     | 
| 
       33 
34 
     | 
    
         
             
                    def_node_matcher :hook, <<-PATTERN
         
     | 
| 
       34 
35 
     | 
    
         
             
                      (block (send nil? :around sym ?) (args $...) ...)
         
     | 
| 
       35 
36 
     | 
    
         
             
                    PATTERN
         
     | 
| 
       36 
37 
     | 
    
         | 
| 
      
 38 
     | 
    
         
            +
                    # @!method find_arg_usage(node)
         
     | 
| 
       37 
39 
     | 
    
         
             
                    def_node_search :find_arg_usage, <<-PATTERN
         
     | 
| 
       38 
40 
     | 
    
         
             
                      {(send $... {:call :run}) (send _ _ $...) (yield $...) (block-pass $...)}
         
     | 
| 
       39 
41 
     | 
    
         
             
                    PATTERN
         
     | 
    
        data/lib/rubocop/cop/rspec/be.rb
    CHANGED
    
    | 
         @@ -20,8 +20,9 @@ module RuboCop 
     | 
|
| 
       20 
20 
     | 
    
         
             
                  #   expect(foo).to be(true)
         
     | 
| 
       21 
21 
     | 
    
         
             
                  #
         
     | 
| 
       22 
22 
     | 
    
         
             
                  class Be < Base
         
     | 
| 
       23 
     | 
    
         
            -
                    MSG =  
     | 
| 
      
 23 
     | 
    
         
            +
                    MSG = "Don't use `be` without an argument."
         
     | 
| 
       24 
24 
     | 
    
         | 
| 
      
 25 
     | 
    
         
            +
                    # @!method be_without_args(node)
         
     | 
| 
       25 
26 
     | 
    
         
             
                    def_node_matcher :be_without_args, <<-PATTERN
         
     | 
| 
       26 
27 
     | 
    
         
             
                      (send _ #Runners.all $(send nil? :be))
         
     | 
| 
       27 
28 
     | 
    
         
             
                    PATTERN
         
     | 
| 
         @@ -39,7 +39,9 @@ module RuboCop 
     | 
|
| 
       39 
39 
     | 
    
         
             
                    extend AutoCorrector
         
     | 
| 
       40 
40 
     | 
    
         | 
| 
       41 
41 
     | 
    
         
             
                    MSG = 'Prefer `be` over `eql`.'
         
     | 
| 
      
 42 
     | 
    
         
            +
                    RESTRICT_ON_SEND = %i[to].freeze
         
     | 
| 
       42 
43 
     | 
    
         | 
| 
      
 44 
     | 
    
         
            +
                    # @!method eql_type_with_identity(node)
         
     | 
| 
       43 
45 
     | 
    
         
             
                    def_node_matcher :eql_type_with_identity, <<-PATTERN
         
     | 
| 
       44 
46 
     | 
    
         
             
                      (send _ :to $(send nil? :eql {true false int float sym nil_type?}))
         
     | 
| 
       45 
47 
     | 
    
         
             
                    PATTERN
         
     | 
| 
         @@ -24,11 +24,14 @@ module RuboCop 
     | 
|
| 
       24 
24 
     | 
    
         
             
                  #     after(:each) { Widget.delete_all }
         
     | 
| 
       25 
25 
     | 
    
         
             
                  #   end
         
     | 
| 
       26 
26 
     | 
    
         
             
                  class BeforeAfterAll < Base
         
     | 
| 
       27 
     | 
    
         
            -
                    MSG = 'Beware of using `%<hook>s` as it may cause state to leak '\
         
     | 
| 
       28 
     | 
    
         
            -
                          'between tests. If you are using `rspec-rails`, and '\
         
     | 
| 
       29 
     | 
    
         
            -
                          '`use_transactional_fixtures` is enabled, then records created '\
         
     | 
| 
      
 27 
     | 
    
         
            +
                    MSG = 'Beware of using `%<hook>s` as it may cause state to leak ' \
         
     | 
| 
      
 28 
     | 
    
         
            +
                          'between tests. If you are using `rspec-rails`, and ' \
         
     | 
| 
      
 29 
     | 
    
         
            +
                          '`use_transactional_fixtures` is enabled, then records created ' \
         
     | 
| 
       30 
30 
     | 
    
         
             
                          'in `%<hook>s` are not automatically rolled back.'
         
     | 
| 
       31 
31 
     | 
    
         | 
| 
      
 32 
     | 
    
         
            +
                    RESTRICT_ON_SEND = %i[before after].freeze
         
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
      
 34 
     | 
    
         
            +
                    # @!method before_or_after_all(node)
         
     | 
| 
       32 
35 
     | 
    
         
             
                    def_node_matcher :before_or_after_all, <<-PATTERN
         
     | 
| 
       33 
36 
     | 
    
         
             
                      $(send _ {:before :after} (sym {:all :context}))
         
     | 
| 
       34 
37 
     | 
    
         
             
                    PATTERN
         
     | 
| 
         @@ -30,17 +30,22 @@ module RuboCop 
     | 
|
| 
       30 
30 
     | 
    
         
             
                            'Capybara feature specs - instead, use the ' \
         
     | 
| 
       31 
31 
     | 
    
         
             
                            '`have_current_path` matcher on `page`'
         
     | 
| 
       32 
32 
     | 
    
         | 
| 
      
 33 
     | 
    
         
            +
                      RESTRICT_ON_SEND = %i[expect].freeze
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
      
 35 
     | 
    
         
            +
                      # @!method expectation_set_on_current_path(node)
         
     | 
| 
       33 
36 
     | 
    
         
             
                      def_node_matcher :expectation_set_on_current_path, <<-PATTERN
         
     | 
| 
       34 
37 
     | 
    
         
             
                        (send nil? :expect (send {(send nil? :page) nil?} :current_path))
         
     | 
| 
       35 
38 
     | 
    
         
             
                      PATTERN
         
     | 
| 
       36 
39 
     | 
    
         | 
| 
       37 
40 
     | 
    
         
             
                      # Supported matchers: eq(...) / match(/regexp/) / match('regexp')
         
     | 
| 
      
 41 
     | 
    
         
            +
                      # @!method as_is_matcher(node)
         
     | 
| 
       38 
42 
     | 
    
         
             
                      def_node_matcher :as_is_matcher, <<-PATTERN
         
     | 
| 
       39 
43 
     | 
    
         
             
                        (send
         
     | 
| 
       40 
44 
     | 
    
         
             
                          #expectation_set_on_current_path $#Runners.all
         
     | 
| 
       41 
45 
     | 
    
         
             
                          ${(send nil? :eq ...) (send nil? :match (regexp ...))})
         
     | 
| 
       42 
46 
     | 
    
         
             
                      PATTERN
         
     | 
| 
       43 
47 
     | 
    
         | 
| 
      
 48 
     | 
    
         
            +
                      # @!method regexp_str_matcher(node)
         
     | 
| 
       44 
49 
     | 
    
         
             
                      def_node_matcher :regexp_str_matcher, <<-PATTERN
         
     | 
| 
       45 
50 
     | 
    
         
             
                        (send
         
     | 
| 
       46 
51 
     | 
    
         
             
                          #expectation_set_on_current_path $#Runners.all
         
     | 
| 
         @@ -55,16 +55,19 @@ module RuboCop 
     | 
|
| 
       55 
55 
     | 
    
         
             
                        feature:    :describe
         
     | 
| 
       56 
56 
     | 
    
         
             
                      }.freeze
         
     | 
| 
       57 
57 
     | 
    
         | 
| 
      
 58 
     | 
    
         
            +
                      # @!method capybara_speak(node)
         
     | 
| 
       58 
59 
     | 
    
         
             
                      def_node_matcher :capybara_speak, <<-PATTERN
         
     | 
| 
       59 
60 
     | 
    
         
             
                        {#{MAP.keys.map(&:inspect).join(' ')}}
         
     | 
| 
       60 
61 
     | 
    
         
             
                      PATTERN
         
     | 
| 
       61 
62 
     | 
    
         | 
| 
      
 63 
     | 
    
         
            +
                      # @!method spec?(node)
         
     | 
| 
       62 
64 
     | 
    
         
             
                      def_node_matcher :spec?, <<-PATTERN
         
     | 
| 
       63 
65 
     | 
    
         
             
                        (block
         
     | 
| 
       64 
66 
     | 
    
         
             
                          (send #rspec? {:describe :feature} ...)
         
     | 
| 
       65 
67 
     | 
    
         
             
                        ...)
         
     | 
| 
       66 
68 
     | 
    
         
             
                      PATTERN
         
     | 
| 
       67 
69 
     | 
    
         | 
| 
      
 70 
     | 
    
         
            +
                      # @!method feature_method(node)
         
     | 
| 
       68 
71 
     | 
    
         
             
                      def_node_matcher :feature_method, <<-PATTERN
         
     | 
| 
       69 
72 
     | 
    
         
             
                        (block
         
     | 
| 
       70 
73 
     | 
    
         
             
                          $(send #rspec? $#capybara_speak ...)
         
     | 
| 
         @@ -44,10 +44,14 @@ module RuboCop 
     | 
|
| 
       44 
44 
     | 
    
         
             
                        have_content
         
     | 
| 
       45 
45 
     | 
    
         
             
                      ].freeze
         
     | 
| 
       46 
46 
     | 
    
         | 
| 
      
 47 
     | 
    
         
            +
                      RESTRICT_ON_SEND = CAPYBARA_MATCHER_METHODS
         
     | 
| 
      
 48 
     | 
    
         
            +
             
     | 
| 
      
 49 
     | 
    
         
            +
                      # @!method visible_true?(node)
         
     | 
| 
       47 
50 
     | 
    
         
             
                      def_node_matcher :visible_true?, <<~PATTERN
         
     | 
| 
       48 
51 
     | 
    
         
             
                        (send nil? #capybara_matcher? ... (hash <$(pair (sym :visible) true) ...>))
         
     | 
| 
       49 
52 
     | 
    
         
             
                      PATTERN
         
     | 
| 
       50 
53 
     | 
    
         | 
| 
      
 54 
     | 
    
         
            +
                      # @!method visible_false?(node)
         
     | 
| 
       51 
55 
     | 
    
         
             
                      def_node_matcher :visible_false?, <<~PATTERN
         
     | 
| 
       52 
56 
     | 
    
         
             
                        (send nil? #capybara_matcher? ... (hash <$(pair (sym :visible) false) ...>))
         
     | 
| 
       53 
57 
     | 
    
         
             
                      PATTERN
         
     | 
| 
         @@ -8,6 +8,7 @@ module RuboCop 
     | 
|
| 
       8 
8 
     | 
    
         
             
                  # The default list of prefixes is minimal. Users are encouraged to tailor
         
     | 
| 
       9 
9 
     | 
    
         
             
                  # the configuration to meet project needs. Other acceptable prefixes may
         
     | 
| 
       10 
10 
     | 
    
         
             
                  # include `if`, `unless`, `for`, `before`, `after`, or `during`.
         
     | 
| 
      
 11 
     | 
    
         
            +
                  # They may consist of multiple words if desired.
         
     | 
| 
       11 
12 
     | 
    
         
             
                  #
         
     | 
| 
       12 
13 
     | 
    
         
             
                  # @see https://rspec.rubystyle.guide/#context-descriptions
         
     | 
| 
       13 
14 
     | 
    
         
             
                  # @see http://www.betterspecs.org/#contexts
         
     | 
| 
         @@ -37,6 +38,7 @@ module RuboCop 
     | 
|
| 
       37 
38 
     | 
    
         
             
                  class ContextWording < Base
         
     | 
| 
       38 
39 
     | 
    
         
             
                    MSG = 'Start context description with %<prefixes>s.'
         
     | 
| 
       39 
40 
     | 
    
         | 
| 
      
 41 
     | 
    
         
            +
                    # @!method context_wording(node)
         
     | 
| 
       40 
42 
     | 
    
         
             
                    def_node_matcher :context_wording, <<-PATTERN
         
     | 
| 
       41 
43 
     | 
    
         
             
                      (block (send #rspec? { :context :shared_context } $(str #bad_prefix?) ...) ...)
         
     | 
| 
       42 
44 
     | 
    
         
             
                    PATTERN
         
     | 
| 
         @@ -51,7 +53,7 @@ module RuboCop 
     | 
|
| 
       51 
53 
     | 
    
         
             
                    private
         
     | 
| 
       52 
54 
     | 
    
         | 
| 
       53 
55 
     | 
    
         
             
                    def bad_prefix?(description)
         
     | 
| 
       54 
     | 
    
         
            -
                      ! 
     | 
| 
      
 56 
     | 
    
         
            +
                      !prefix_regex.match?(description)
         
     | 
| 
       55 
57 
     | 
    
         
             
                    end
         
     | 
| 
       56 
58 
     | 
    
         | 
| 
       57 
59 
     | 
    
         
             
                    def joined_prefixes
         
     | 
| 
         @@ -65,6 +67,10 @@ module RuboCop 
     | 
|
| 
       65 
67 
     | 
    
         
             
                    def prefixes
         
     | 
| 
       66 
68 
     | 
    
         
             
                      cop_config['Prefixes'] || []
         
     | 
| 
       67 
69 
     | 
    
         
             
                    end
         
     | 
| 
      
 70 
     | 
    
         
            +
             
     | 
| 
      
 71 
     | 
    
         
            +
                    def prefix_regex
         
     | 
| 
      
 72 
     | 
    
         
            +
                      /^#{Regexp.union(prefixes)}\b/
         
     | 
| 
      
 73 
     | 
    
         
            +
                    end
         
     | 
| 
       68 
74 
     | 
    
         
             
                  end
         
     | 
| 
       69 
75 
     | 
    
         
             
                end
         
     | 
| 
       70 
76 
     | 
    
         
             
              end
         
     | 
| 
         @@ -37,17 +37,20 @@ module RuboCop 
     | 
|
| 
       37 
37 
     | 
    
         
             
                  class DescribeClass < Base
         
     | 
| 
       38 
38 
     | 
    
         
             
                    include TopLevelGroup
         
     | 
| 
       39 
39 
     | 
    
         | 
| 
       40 
     | 
    
         
            -
                    MSG = 'The first argument to describe should be '\
         
     | 
| 
      
 40 
     | 
    
         
            +
                    MSG = 'The first argument to describe should be ' \
         
     | 
| 
       41 
41 
     | 
    
         
             
                          'the class or module being tested.'
         
     | 
| 
       42 
42 
     | 
    
         | 
| 
      
 43 
     | 
    
         
            +
                    # @!method example_group_with_ignored_metadata?(node)
         
     | 
| 
       43 
44 
     | 
    
         
             
                    def_node_matcher :example_group_with_ignored_metadata?, <<~PATTERN
         
     | 
| 
       44 
45 
     | 
    
         
             
                      (send #rspec? :describe ... (hash <#ignored_metadata? ...>))
         
     | 
| 
       45 
46 
     | 
    
         
             
                    PATTERN
         
     | 
| 
       46 
47 
     | 
    
         | 
| 
      
 48 
     | 
    
         
            +
                    # @!method not_a_const_described(node)
         
     | 
| 
       47 
49 
     | 
    
         
             
                    def_node_matcher :not_a_const_described, <<~PATTERN
         
     | 
| 
       48 
50 
     | 
    
         
             
                      (send #rspec? :describe $[!const !#string_constant?] ...)
         
     | 
| 
       49 
51 
     | 
    
         
             
                    PATTERN
         
     | 
| 
       50 
52 
     | 
    
         | 
| 
      
 53 
     | 
    
         
            +
                    # @!method sym_pair(node)
         
     | 
| 
       51 
54 
     | 
    
         
             
                    def_node_matcher :sym_pair, <<~PATTERN
         
     | 
| 
       52 
55 
     | 
    
         
             
                      (pair $sym $sym)
         
     | 
| 
       53 
56 
     | 
    
         
             
                    PATTERN
         
     | 
| 
         @@ -19,9 +19,10 @@ module RuboCop 
     | 
|
| 
       19 
19 
     | 
    
         
             
                  class DescribeMethod < Base
         
     | 
| 
       20 
20 
     | 
    
         
             
                    include TopLevelGroup
         
     | 
| 
       21 
21 
     | 
    
         | 
| 
       22 
     | 
    
         
            -
                    MSG = 'The second argument to describe should be the method '\
         
     | 
| 
      
 22 
     | 
    
         
            +
                    MSG = 'The second argument to describe should be the method ' \
         
     | 
| 
       23 
23 
     | 
    
         
             
                          "being tested. '#instance' or '.class'."
         
     | 
| 
       24 
24 
     | 
    
         | 
| 
      
 25 
     | 
    
         
            +
                    # @!method second_argument(node)
         
     | 
| 
       25 
26 
     | 
    
         
             
                    def_node_matcher :second_argument, <<~PATTERN
         
     | 
| 
       26 
27 
     | 
    
         
             
                      (block
         
     | 
| 
       27 
28 
     | 
    
         
             
                        (send #rspec? :describe _first_argument $(str _) ...) ...
         
     | 
| 
         @@ -19,7 +19,9 @@ module RuboCop 
     | 
|
| 
       19 
19 
     | 
    
         
             
                  # @see https://github.com/rspec/rspec-core/issues/1610
         
     | 
| 
       20 
20 
     | 
    
         
             
                  class DescribeSymbol < Base
         
     | 
| 
       21 
21 
     | 
    
         
             
                    MSG = 'Avoid describing symbols.'
         
     | 
| 
      
 22 
     | 
    
         
            +
                    RESTRICT_ON_SEND = %i[describe].freeze
         
     | 
| 
       22 
23 
     | 
    
         | 
| 
      
 24 
     | 
    
         
            +
                    # @!method describe_symbol?(node)
         
     | 
| 
       23 
25 
     | 
    
         
             
                    def_node_matcher :describe_symbol?, <<-PATTERN
         
     | 
| 
       24 
26 
     | 
    
         
             
                      (send #rspec? :describe $sym ...)
         
     | 
| 
       25 
27 
     | 
    
         
             
                    PATTERN
         
     | 
| 
         @@ -61,18 +61,23 @@ module RuboCop 
     | 
|
| 
       61 
61 
     | 
    
         
             
                    DESCRIBED_CLASS = 'described_class'
         
     | 
| 
       62 
62 
     | 
    
         
             
                    MSG             = 'Use `%<replacement>s` instead of `%<src>s`.'
         
     | 
| 
       63 
63 
     | 
    
         | 
| 
      
 64 
     | 
    
         
            +
                    # @!method common_instance_exec_closure?(node)
         
     | 
| 
       64 
65 
     | 
    
         
             
                    def_node_matcher :common_instance_exec_closure?, <<-PATTERN
         
     | 
| 
       65 
66 
     | 
    
         
             
                      (block (send (const nil? {:Class :Module :Struct}) :new ...) ...)
         
     | 
| 
       66 
67 
     | 
    
         
             
                    PATTERN
         
     | 
| 
       67 
68 
     | 
    
         | 
| 
      
 69 
     | 
    
         
            +
                    # @!method rspec_block?(node)
         
     | 
| 
       68 
70 
     | 
    
         
             
                    def_node_matcher :rspec_block?, block_pattern('#ALL.all')
         
     | 
| 
       69 
71 
     | 
    
         | 
| 
      
 72 
     | 
    
         
            +
                    # @!method scope_changing_syntax?(node)
         
     | 
| 
       70 
73 
     | 
    
         
             
                    def_node_matcher :scope_changing_syntax?, '{def class module}'
         
     | 
| 
       71 
74 
     | 
    
         | 
| 
      
 75 
     | 
    
         
            +
                    # @!method described_constant(node)
         
     | 
| 
       72 
76 
     | 
    
         
             
                    def_node_matcher :described_constant, <<-PATTERN
         
     | 
| 
       73 
77 
     | 
    
         
             
                      (block (send _ :describe $(const ...) ...) (args) $_)
         
     | 
| 
       74 
78 
     | 
    
         
             
                    PATTERN
         
     | 
| 
       75 
79 
     | 
    
         | 
| 
      
 80 
     | 
    
         
            +
                    # @!method contains_described_class?(node)
         
     | 
| 
       76 
81 
     | 
    
         
             
                    def_node_search :contains_described_class?, <<-PATTERN
         
     | 
| 
       77 
82 
     | 
    
         
             
                      (send nil? :described_class)
         
     | 
| 
       78 
83 
     | 
    
         
             
                    PATTERN
         
     | 
| 
         @@ -198,7 +203,7 @@ module RuboCop 
     | 
|
| 
       198 
203 
     | 
    
         
             
                        [name]
         
     | 
| 
       199 
204 
     | 
    
         
             
                      elsif namespace.const_type?
         
     | 
| 
       200 
205 
     | 
    
         
             
                        [*const_name(namespace), name]
         
     | 
| 
       201 
     | 
    
         
            -
                      elsif  
     | 
| 
      
 206 
     | 
    
         
            +
                      elsif %i[lvar cbase send].include?(namespace.type)
         
     | 
| 
       202 
207 
     | 
    
         
             
                        [nil, name]
         
     | 
| 
       203 
208 
     | 
    
         
             
                      end
         
     | 
| 
       204 
209 
     | 
    
         
             
                    end
         
     | 
| 
         @@ -18,10 +18,11 @@ module RuboCop 
     | 
|
| 
       18 
18 
     | 
    
         
             
                  #     # ...
         
     | 
| 
       19 
19 
     | 
    
         
             
                  #   end
         
     | 
| 
       20 
20 
     | 
    
         
             
                  #
         
     | 
| 
       21 
     | 
    
         
            -
                  # @see https://github.com/rubocop 
     | 
| 
      
 21 
     | 
    
         
            +
                  # @see https://github.com/rubocop/rubocop-rspec/issues/735
         
     | 
| 
       22 
22 
     | 
    
         
             
                  class DescribedClassModuleWrapping < Base
         
     | 
| 
       23 
23 
     | 
    
         
             
                    MSG = 'Avoid opening modules and defining specs within them.'
         
     | 
| 
       24 
24 
     | 
    
         | 
| 
      
 25 
     | 
    
         
            +
                    # @!method find_rspec_blocks(node)
         
     | 
| 
       25 
26 
     | 
    
         
             
                    def_node_search :find_rspec_blocks, block_pattern('#ExampleGroups.all')
         
     | 
| 
       26 
27 
     | 
    
         | 
| 
       27 
28 
     | 
    
         
             
                    def on_module(node)
         
     | 
| 
         @@ -25,29 +25,43 @@ module RuboCop 
     | 
|
| 
       25 
25 
     | 
    
         
             
                  #     result = service.call
         
     | 
| 
       26 
26 
     | 
    
         
             
                  #     expect(result).to be(true)
         
     | 
| 
       27 
27 
     | 
    
         
             
                  #   end
         
     | 
| 
      
 28 
     | 
    
         
            +
                  #
         
     | 
| 
      
 29 
     | 
    
         
            +
                  # You can set literals you want to fold with `CountAsOne`.
         
     | 
| 
      
 30 
     | 
    
         
            +
                  # Available are: 'array', 'hash', and 'heredoc'. Each literal
         
     | 
| 
      
 31 
     | 
    
         
            +
                  # will be counted as one line regardless of its actual size.
         
     | 
| 
      
 32 
     | 
    
         
            +
                  #
         
     | 
| 
      
 33 
     | 
    
         
            +
                  # @example CountAsOne: ['array', 'heredoc']
         
     | 
| 
      
 34 
     | 
    
         
            +
                  #
         
     | 
| 
      
 35 
     | 
    
         
            +
                  #   it do
         
     | 
| 
      
 36 
     | 
    
         
            +
                  #     array = [         # +1
         
     | 
| 
      
 37 
     | 
    
         
            +
                  #       1,
         
     | 
| 
      
 38 
     | 
    
         
            +
                  #       2
         
     | 
| 
      
 39 
     | 
    
         
            +
                  #     ]
         
     | 
| 
      
 40 
     | 
    
         
            +
                  #
         
     | 
| 
      
 41 
     | 
    
         
            +
                  #     hash = {          # +3
         
     | 
| 
      
 42 
     | 
    
         
            +
                  #       key: 'value'
         
     | 
| 
      
 43 
     | 
    
         
            +
                  #     }
         
     | 
| 
      
 44 
     | 
    
         
            +
                  #
         
     | 
| 
      
 45 
     | 
    
         
            +
                  #     msg = <<~HEREDOC  # +1
         
     | 
| 
      
 46 
     | 
    
         
            +
                  #       Heredoc
         
     | 
| 
      
 47 
     | 
    
         
            +
                  #       content.
         
     | 
| 
      
 48 
     | 
    
         
            +
                  #     HEREDOC
         
     | 
| 
      
 49 
     | 
    
         
            +
                  #   end                 # 5 points
         
     | 
| 
       28 
50 
     | 
    
         
             
                  class ExampleLength < Base
         
     | 
| 
       29 
51 
     | 
    
         
             
                    include CodeLength
         
     | 
| 
       30 
52 
     | 
    
         | 
| 
       31 
     | 
    
         
            -
                     
     | 
| 
      
 53 
     | 
    
         
            +
                    LABEL = 'Example'
         
     | 
| 
       32 
54 
     | 
    
         | 
| 
       33 
55 
     | 
    
         
             
                    def on_block(node)
         
     | 
| 
       34 
56 
     | 
    
         
             
                      return unless example?(node)
         
     | 
| 
       35 
57 
     | 
    
         | 
| 
       36 
     | 
    
         
            -
                       
     | 
| 
       37 
     | 
    
         
            -
             
     | 
| 
       38 
     | 
    
         
            -
                      return unless length > max_length
         
     | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
       40 
     | 
    
         
            -
                      add_offense(node, message: message(length))
         
     | 
| 
      
 58 
     | 
    
         
            +
                      check_code_length(node)
         
     | 
| 
       41 
59 
     | 
    
         
             
                    end
         
     | 
| 
       42 
60 
     | 
    
         | 
| 
       43 
61 
     | 
    
         
             
                    private
         
     | 
| 
       44 
62 
     | 
    
         | 
| 
       45 
     | 
    
         
            -
                    def  
     | 
| 
       46 
     | 
    
         
            -
                       
     | 
| 
       47 
     | 
    
         
            -
                    end
         
     | 
| 
       48 
     | 
    
         
            -
             
     | 
| 
       49 
     | 
    
         
            -
                    def message(length)
         
     | 
| 
       50 
     | 
    
         
            -
                      format(MSG, total: length, max: max_length)
         
     | 
| 
      
 63 
     | 
    
         
            +
                    def cop_label
         
     | 
| 
      
 64 
     | 
    
         
            +
                      LABEL
         
     | 
| 
       51 
65 
     | 
    
         
             
                    end
         
     | 
| 
       52 
66 
     | 
    
         
             
                  end
         
     | 
| 
       53 
67 
     | 
    
         
             
                end
         
     | 
| 
         @@ -45,6 +45,7 @@ module RuboCop 
     | 
|
| 
       45 
45 
     | 
    
         | 
| 
       46 
46 
     | 
    
         
             
                    SUPPORTED_MATCHERS = %i[eq eql equal be].freeze
         
     | 
| 
       47 
47 
     | 
    
         | 
| 
      
 48 
     | 
    
         
            +
                    # @!method expect_literal(node)
         
     | 
| 
       48 
49 
     | 
    
         
             
                    def_node_matcher :expect_literal, <<~PATTERN
         
     | 
| 
       49 
50 
     | 
    
         
             
                      (send
         
     | 
| 
       50 
51 
     | 
    
         
             
                        (send nil? :expect $#literal?)
         
     | 
| 
         @@ -60,6 +61,7 @@ module RuboCop 
     | 
|
| 
       60 
61 
     | 
    
         
             
                      expect_literal(node) do |actual, matcher, expected|
         
     | 
| 
       61 
62 
     | 
    
         
             
                        add_offense(actual.source_range) do |corrector|
         
     | 
| 
       62 
63 
     | 
    
         
             
                          next unless SUPPORTED_MATCHERS.include?(matcher)
         
     | 
| 
      
 64 
     | 
    
         
            +
                          next if literal?(expected)
         
     | 
| 
       63 
65 
     | 
    
         | 
| 
       64 
66 
     | 
    
         
             
                          swap(corrector, actual, expected)
         
     | 
| 
       65 
67 
     | 
    
         
             
                        end
         
     | 
| 
         @@ -35,11 +35,14 @@ module RuboCop 
     | 
|
| 
       35 
35 
     | 
    
         | 
| 
       36 
36 
     | 
    
         
             
                    MSG_BLOCK = 'Prefer `change(%<obj>s, :%<attr>s)`.'
         
     | 
| 
       37 
37 
     | 
    
         
             
                    MSG_CALL = 'Prefer `change { %<obj>s.%<attr>s }`.'
         
     | 
| 
      
 38 
     | 
    
         
            +
                    RESTRICT_ON_SEND = %i[change].freeze
         
     | 
| 
       38 
39 
     | 
    
         | 
| 
      
 40 
     | 
    
         
            +
                    # @!method expect_change_with_arguments(node)
         
     | 
| 
       39 
41 
     | 
    
         
             
                    def_node_matcher :expect_change_with_arguments, <<-PATTERN
         
     | 
| 
       40 
     | 
    
         
            -
                      (send nil? :change  
     | 
| 
      
 42 
     | 
    
         
            +
                      (send nil? :change $_ (sym $_))
         
     | 
| 
       41 
43 
     | 
    
         
             
                    PATTERN
         
     | 
| 
       42 
44 
     | 
    
         | 
| 
      
 45 
     | 
    
         
            +
                    # @!method expect_change_with_block(node)
         
     | 
| 
       43 
46 
     | 
    
         
             
                    def_node_matcher :expect_change_with_block, <<-PATTERN
         
     | 
| 
       44 
47 
     | 
    
         
             
                      (block
         
     | 
| 
       45 
48 
     | 
    
         
             
                        (send nil? :change)
         
     | 
| 
         @@ -52,9 +55,9 @@ module RuboCop 
     | 
|
| 
       52 
55 
     | 
    
         
             
                      return unless style == :block
         
     | 
| 
       53 
56 
     | 
    
         | 
| 
       54 
57 
     | 
    
         
             
                      expect_change_with_arguments(node) do |receiver, message|
         
     | 
| 
       55 
     | 
    
         
            -
                        msg = format(MSG_CALL, obj: receiver, attr: message)
         
     | 
| 
      
 58 
     | 
    
         
            +
                        msg = format(MSG_CALL, obj: receiver.source, attr: message)
         
     | 
| 
       56 
59 
     | 
    
         
             
                        add_offense(node, message: msg) do |corrector|
         
     | 
| 
       57 
     | 
    
         
            -
                          replacement = "change { #{receiver}.#{message} }"
         
     | 
| 
      
 60 
     | 
    
         
            +
                          replacement = "change { #{receiver.source}.#{message} }"
         
     | 
| 
       58 
61 
     | 
    
         
             
                          corrector.replace(node, replacement)
         
     | 
| 
       59 
62 
     | 
    
         
             
                        end
         
     | 
| 
       60 
63 
     | 
    
         
             
                      end
         
     | 
| 
         @@ -15,7 +15,7 @@ module RuboCop 
     | 
|
| 
       15 
15 
     | 
    
         
             
                  #   # good
         
     | 
| 
       16 
16 
     | 
    
         
             
                  #   expect { my_app.print_report }.to output('Hello World').to_stdout
         
     | 
| 
       17 
17 
     | 
    
         
             
                  class ExpectOutput < Base
         
     | 
| 
       18 
     | 
    
         
            -
                    MSG = 'Use `expect { ... }.to output(...).to_%<name>s` '\
         
     | 
| 
      
 18 
     | 
    
         
            +
                    MSG = 'Use `expect { ... }.to output(...).to_%<name>s` ' \
         
     | 
| 
       19 
19 
     | 
    
         
             
                          'instead of mutating $%<name>s.'
         
     | 
| 
       20 
20 
     | 
    
         | 
| 
       21 
21 
     | 
    
         
             
                    def on_gvasgn(node)
         
     |