Sha256: 91865502d951defae9ac4cf041dccbfb8fa44530b49889778b84921e5608a2f9

Contents?: true

Size: 984 Bytes

Versions: 6

Compression:

Stored size: 984 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.'

        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.loc.selector)
          end
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
rubocop-rspec-2.0.0.pre lib/rubocop/cop/rspec/be.rb
rubocop-rspec-1.44.1 lib/rubocop/cop/rspec/be.rb
rubocop-rspec-1.44.0 lib/rubocop/cop/rspec/be.rb
rubocop-rspec-1.43.2 lib/rubocop/cop/rspec/be.rb
rubocop-rspec-1.43.1 lib/rubocop/cop/rspec/be.rb
rubocop-rspec-1.43.0 lib/rubocop/cop/rspec/be.rb