Sha256: 6a0ffd5facfb755d138e06bc624ebfbc1c1dffe742267deb2f5224f214b18f25

Contents?: true

Size: 975 Bytes

Versions: 8

Compression:

Stored size: 975 Bytes

Contents

module RuboCop
  module Cop
    module RSpec
      # Checks for consistent method usage for negating expectations.
      #
      # @example
      #   # bad
      #   it '...' do
      #     expect(false).to_not be_true
      #   end
      #
      #   # good
      #   it '...' do
      #     expect(false).not_to be_true
      #   end
      class NotToNot < Cop
        include ConfigurableEnforcedStyle

        MSG = 'Prefer `%<replacement>s` over `%<original>s`.'.freeze

        def_node_matcher :not_to_not_offense, '(send _ % ...)'

        def on_send(node)
          not_to_not_offense(node, alternative_style) do
            add_offense(node, location: :selector)
          end
        end

        def autocorrect(node)
          ->(corrector) { corrector.replace(node.loc.selector, style.to_s) }
        end

        private

        def message(_node)
          format(MSG, replacement: style, original: alternative_style)
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
rubocop-rspec-1.32.0 lib/rubocop/cop/rspec/not_to_not.rb
rubocop-rspec-1.31.0 lib/rubocop/cop/rspec/not_to_not.rb
rubocop-rspec-1.30.1 lib/rubocop/cop/rspec/not_to_not.rb
rubocop-rspec-1.30.0 lib/rubocop/cop/rspec/not_to_not.rb
rubocop-rspec-1.29.1 lib/rubocop/cop/rspec/not_to_not.rb
rubocop-rspec-1.29.0 lib/rubocop/cop/rspec/not_to_not.rb
rubocop-rspec-1.28.0 lib/rubocop/cop/rspec/not_to_not.rb
rubocop-rspec-1.27.0 lib/rubocop/cop/rspec/not_to_not.rb