Sha256: 94e5a4a9a5c5386d160a02ee6bc4053da6fc58d011906c10e4c9ee5666ba80a6

Contents?: true

Size: 1.14 KB

Versions: 21

Compression:

Stored size: 1.14 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module RSpec
      # Check for `specify` with `is_expected` and one-liner expectations.
      #
      # @example
      #   # bad
      #   specify { is_expected.to be_truthy }
      #
      #   # good
      #   it { is_expected.to be_truthy }
      #
      #   # good
      #   specify do
      #     # ...
      #   end
      #   specify { expect(sqrt(4)).to eq(2) }
      #
      class IsExpectedSpecify < Base
        extend AutoCorrector

        RESTRICT_ON_SEND = %i[specify].freeze
        IS_EXPECTED_METHODS = ::Set[:is_expected, :are_expected].freeze
        MSG = 'Use `it` instead of `specify`.'

        # @!method offense?(node)
        def_node_matcher :offense?, <<~PATTERN
          (block (send _ :specify) _ (send (send _ IS_EXPECTED_METHODS) ...))
        PATTERN

        def on_send(node)
          block_node = node.parent
          return unless block_node&.single_line? && offense?(block_node)

          selector = node.loc.selector
          add_offense(selector) do |corrector|
            corrector.replace(selector, 'it')
          end
        end
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 4 rubygems

Version Path
minato_ruby_api_client-0.2.2 vendor/bundle/ruby/3.2.0/gems/rubocop-rspec-3.0.3/lib/rubocop/cop/rspec/is_expected_specify.rb
rubocop-rspec-3.3.0 lib/rubocop/cop/rspec/is_expected_specify.rb
rubocop-rspec-3.2.0 lib/rubocop/cop/rspec/is_expected_specify.rb
rubocop-rspec-3.1.0 lib/rubocop/cop/rspec/is_expected_specify.rb
rubocop-rspec-3.0.5 lib/rubocop/cop/rspec/is_expected_specify.rb
rubocop-rspec-3.0.4 lib/rubocop/cop/rspec/is_expected_specify.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/rubocop-rspec-3.0.1/lib/rubocop/cop/rspec/is_expected_specify.rb
rubocop-rspec-3.0.3 lib/rubocop/cop/rspec/is_expected_specify.rb
rubocop-rspec-3.0.2 lib/rubocop/cop/rspec/is_expected_specify.rb
katalyst-govuk-formbuilder-1.9.2 vendor/bundle/ruby/3.3.0/gems/rubocop-rspec-3.0.1/lib/rubocop/cop/rspec/is_expected_specify.rb
rubocop-rspec-3.0.1 lib/rubocop/cop/rspec/is_expected_specify.rb
rubocop-rspec-3.0.0 lib/rubocop/cop/rspec/is_expected_specify.rb
rubocop-rspec-3.0.0.pre lib/rubocop/cop/rspec/is_expected_specify.rb
rubocop-rspec-2.31.0 lib/rubocop/cop/rspec/is_expected_specify.rb
rubocop-rspec-2.30.0 lib/rubocop/cop/rspec/is_expected_specify.rb
rubocop-rspec-2.29.2 lib/rubocop/cop/rspec/is_expected_specify.rb
rubocop-rspec-2.29.1 lib/rubocop/cop/rspec/is_expected_specify.rb
rubocop-rspec-2.29.0 lib/rubocop/cop/rspec/is_expected_specify.rb
rubocop-rspec-2.28.0 lib/rubocop/cop/rspec/is_expected_specify.rb
rubocop-rspec-2.27.1 lib/rubocop/cop/rspec/is_expected_specify.rb