Sha256: 6c848a47068523cb58cef87b25f344137b9d0f6879b65a09f4e903e463831726

Contents?: true

Size: 1.01 KB

Versions: 24

Compression:

Stored size: 1.01 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module RSpec
      # Check for expectations where `be` is used without argument.
      #
      # The `be` matcher is too generic, as it pass on everything that is not
      # nil or false. If that is the exact intend, use `be_truthy`. In all other
      # cases it's better to specify what exactly is the expected value.
      #
      # @example
      #   # bad
      #   expect(foo).to be
      #
      #   # good
      #   expect(foo).to be_truthy
      #   expect(foo).to be 1.0
      #   expect(foo).to be(true)
      #
      class Be < Base
        MSG = "Don't use `be` without an argument."

        RESTRICT_ON_SEND = Runners.all

        # @!method be_without_args(node)
        def_node_matcher :be_without_args, <<~PATTERN
          (send _ #Runners.all $(send nil? :be))
        PATTERN

        def on_send(node)
          be_without_args(node) do |matcher|
            add_offense(matcher.loc.selector)
          end
        end
      end
    end
  end
end

Version data entries

24 entries across 24 versions & 5 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/be.rb
rubocop-rspec-3.3.0 lib/rubocop/cop/rspec/be.rb
rubocop-rspec-3.2.0 lib/rubocop/cop/rspec/be.rb
rubocop-rspec-3.1.0 lib/rubocop/cop/rspec/be.rb
rubocop-rspec-3.0.5 lib/rubocop/cop/rspec/be.rb
rubocop-rspec-3.0.4 lib/rubocop/cop/rspec/be.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/rubocop-rspec-3.0.1/lib/rubocop/cop/rspec/be.rb
rubocop-rspec-3.0.3 lib/rubocop/cop/rspec/be.rb
rubocop-rspec-3.0.2 lib/rubocop/cop/rspec/be.rb
katalyst-govuk-formbuilder-1.9.2 vendor/bundle/ruby/3.3.0/gems/rubocop-rspec-3.0.1/lib/rubocop/cop/rspec/be.rb
rubocop-rspec-3.0.1 lib/rubocop/cop/rspec/be.rb
rubocop-rspec-3.0.0 lib/rubocop/cop/rspec/be.rb
rubocop-rspec-3.0.0.pre lib/rubocop/cop/rspec/be.rb
rubocop-rspec-2.31.0 lib/rubocop/cop/rspec/be.rb
rubocop-rspec-2.30.0 lib/rubocop/cop/rspec/be.rb
rubocop-rspec-2.29.2 lib/rubocop/cop/rspec/be.rb
rubocop-rspec-2.29.1 lib/rubocop/cop/rspec/be.rb
rubocop-rspec-2.29.0 lib/rubocop/cop/rspec/be.rb
rubocop-rspec-2.28.0 lib/rubocop/cop/rspec/be.rb
rubocop-rspec-2.27.1 lib/rubocop/cop/rspec/be.rb