Sha256: 6809d1e3495cd82d0d2032991362c2a41dc2e5ff43afdeab9c30cf63bd789d4f

Contents?: true

Size: 1.01 KB

Versions: 20

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

20 entries across 20 versions & 4 rubygems

Version Path
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rubocop-rspec-2.22.0/lib/rubocop/cop/rspec/be.rb
rubocop-rspec-2.25.0 lib/rubocop/cop/rspec/be.rb
rubocop-rspec-2.24.1 lib/rubocop/cop/rspec/be.rb
rubocop-rspec-2.24.0 lib/rubocop/cop/rspec/be.rb
rubocop-rspec-2.23.2 lib/rubocop/cop/rspec/be.rb
rubocop-rspec-2.23.1 lib/rubocop/cop/rspec/be.rb
rubocop-rspec-2.23.0 lib/rubocop/cop/rspec/be.rb
mlh-rubocop-config-1.0.2 vendor/bundle/ruby/3.2.0/gems/rubocop-rspec-2.22.0/lib/rubocop/cop/rspec/be.rb
fablicop-1.10.3 vendor/bundle/ruby/3.2.0/gems/rubocop-rspec-2.22.0/lib/rubocop/cop/rspec/be.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rubocop-rspec-2.22.0/lib/rubocop/cop/rspec/be.rb
fablicop-1.10.2 vendor/bundle/ruby/3.2.0/gems/rubocop-rspec-2.22.0/lib/rubocop/cop/rspec/be.rb
rubocop-rspec-2.22.0 lib/rubocop/cop/rspec/be.rb
rubocop-rspec-2.21.0 lib/rubocop/cop/rspec/be.rb
rubocop-rspec-2.20.0 lib/rubocop/cop/rspec/be.rb
rubocop-rspec-2.19.0 lib/rubocop/cop/rspec/be.rb
rubocop-rspec-2.18.1 lib/rubocop/cop/rspec/be.rb
rubocop-rspec-2.18.0 lib/rubocop/cop/rspec/be.rb
rubocop-rspec-2.17.1 lib/rubocop/cop/rspec/be.rb
rubocop-rspec-2.17.0 lib/rubocop/cop/rspec/be.rb
rubocop-rspec-2.16.0 lib/rubocop/cop/rspec/be.rb