Sha256: 539dc01aeb97633c71b5e9bf0f85393fa0e9399d9989ed7bdbddf1e034fb9f78

Contents?: true

Size: 988 Bytes

Versions: 15

Compression:

Stored size: 988 Bytes

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module RSpec
      module Rails
        # Checks that tests use RSpec `before` hook over Rails `setup` method.
        #
        # @example
        #
        #   # bad
        #   setup do
        #     allow(foo).to receive(:bar)
        #   end
        #
        #   # good
        #   before do
        #     allow(foo).to receive(:bar)
        #   end
        #
        class AvoidSetupHook < Base
          extend AutoCorrector

          MSG = 'Use `before` instead of `setup`.'

          # @!method setup_call(node)
          def_node_matcher :setup_call, <<-PATTERN
            (block
              $(send nil? :setup)
              (args) _)
          PATTERN

          def on_block(node)
            setup_call(node) do |setup|
              add_offense(node) do |corrector|
                corrector.replace setup, 'before'
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

15 entries across 13 versions & 2 rubygems

Version Path
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rubocop-rspec-2.12.1/lib/rubocop/cop/rspec/rails/avoid_setup_hook.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rubocop-rspec-2.9.0/lib/rubocop/cop/rspec/rails/avoid_setup_hook.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rubocop-rspec-2.12.1/lib/rubocop/cop/rspec/rails/avoid_setup_hook.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rubocop-rspec-2.9.0/lib/rubocop/cop/rspec/rails/avoid_setup_hook.rb
rubocop-rspec-2.12.1 lib/rubocop/cop/rspec/rails/avoid_setup_hook.rb
rubocop-rspec-2.12.0 lib/rubocop/cop/rspec/rails/avoid_setup_hook.rb
rubocop-rspec-2.11.1 lib/rubocop/cop/rspec/rails/avoid_setup_hook.rb
rubocop-rspec-2.11.0 lib/rubocop/cop/rspec/rails/avoid_setup_hook.rb
rubocop-rspec-2.10.0 lib/rubocop/cop/rspec/rails/avoid_setup_hook.rb
rubocop-rspec-2.9.0 lib/rubocop/cop/rspec/rails/avoid_setup_hook.rb
rubocop-rspec-2.8.0 lib/rubocop/cop/rspec/rails/avoid_setup_hook.rb
rubocop-rspec-2.7.0 lib/rubocop/cop/rspec/rails/avoid_setup_hook.rb
rubocop-rspec-2.6.0 lib/rubocop/cop/rspec/rails/avoid_setup_hook.rb
rubocop-rspec-2.5.0 lib/rubocop/cop/rspec/rails/avoid_setup_hook.rb
rubocop-rspec-2.4.0 lib/rubocop/cop/rspec/rails/avoid_setup_hook.rb