Sha256: fd6435be09f820223f4be1ae49b4b44500acf67b9b2e8089fa48d4d32c07f0c1

Contents?: true

Size: 991 Bytes

Versions: 12

Compression:

Stored size: 991 Bytes

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 < Cop
        MSG = 'Don\'t use `be` without an argument.'

        def_node_matcher :be_without_args, <<-PATTERN
          (send _ #{Runners::ALL.node_pattern_union} $(send nil? :be))
        PATTERN

        def on_send(node)
          be_without_args(node) do |matcher|
            add_offense(matcher, location: :selector)
          end
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
rubocop-rspec-1.41.0 lib/rubocop/cop/rspec/be.rb
rubocop-rspec-1.40.0 lib/rubocop/cop/rspec/be.rb
rubocop-rspec-1.39.0 lib/rubocop/cop/rspec/be.rb
rubocop-rspec-1.38.1 lib/rubocop/cop/rspec/be.rb
rubocop-rspec-1.38.0 lib/rubocop/cop/rspec/be.rb
rubocop-rspec-1.37.1 lib/rubocop/cop/rspec/be.rb
rubocop-rspec-1.37.0 lib/rubocop/cop/rspec/be.rb
rubocop-rspec-1.36.0 lib/rubocop/cop/rspec/be.rb
rubocop-rspec-1.35.0 lib/rubocop/cop/rspec/be.rb
rubocop-rspec-1.34.1 lib/rubocop/cop/rspec/be.rb
rubocop-rspec-1.34.0 lib/rubocop/cop/rspec/be.rb
rubocop-rspec-1.33.0 lib/rubocop/cop/rspec/be.rb