Sha256: b6868c92f86c5c001a08085b18f44e4133e39b7e4aaa0535b874cae5c8ca7d31

Contents?: true

Size: 940 Bytes

Versions: 2

Compression:

Stored size: 940 Bytes

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module RSpec
      # Do not use `expect` in let.
      #
      # @example
      #   # bad
      #   let(:foo) do
      #     expect(something).to eq 'foo'
      #   end
      #
      #   # good
      #   it do
      #     expect(something).to eq 'foo'
      #   end
      #
      class ExpectInLet < Base
        MSG = 'Do not use `%<expect>s` in let'

        # @!method expectation(node)
        def_node_search :expectation, '(send nil? #Expectations.all ...)'

        def on_block(node)
          return unless let?(node)
          return if node.body.nil?

          expectation(node.body) do |expect|
            add_offense(expect.loc.selector, message: message(expect))
          end
        end

        alias on_numblock on_block

        private

        def message(expect)
          format(MSG, expect: expect.method_name)
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rubocop-rspec-2.31.0 lib/rubocop/cop/rspec/expect_in_let.rb
rubocop-rspec-2.30.0 lib/rubocop/cop/rspec/expect_in_let.rb