Sha256: a9e52a33f57499ae5acaa25fa7ae8f7b2536f6aa95b2fb02c1612e39c72aaa6c

Contents?: true

Size: 1002 Bytes

Versions: 16

Compression:

Stored size: 1002 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 < Base
        MSG = "Don't use `be` without an argument."

        # @!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

16 entries across 14 versions & 2 rubygems

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