lib/rubocop/cop/rspec/empty_example_cops.rb
# Checks if an example does not include any expectations.
#
# @example usage
#
#   # bad
#   describe Bacon do
#     let(:bacon)      { Bacon.new(chunkiness) }
#     let(:chunkiness) { true }
#
#     it 'is chunky' do
#       bacon.chunky?
#     end
#   end
#
#   # good
#   describe Bacon do
#     let(:bacon)      { Bacon.new(chunkiness) }
#     let(:chunkiness) { true }
#
#     it 'is chunky' do
#       expect(bacon.chunky?).to be_truthy
#     end
#   end
Checks if an example does not include any expectations.
Checks if an example does not include any expectations .
def example_present?(node)
          if expect?(node) || should?(node) || assert?(node)
            true
          elsif node.nil?
            false
          elsif RuboCop::AST::Node === node && node.children.size > 0
            node.children.any? { |child| example_present?(child) }
          else 
            false
          end
        end
def example_present? ( node ) if expect? ( node ) || should? ( node ) || assert? ( node ) true elsif node . nil? false elsif RuboCop :: AST :: Node === node && node . children . size > 0 node . children . any? { | child | example_present? ( child ) } else false end end
Checks if an example does not include any expectations.
Checks if an example does not include any expectations .
# something not expectation
node
<not_specific>
example
usage # bad describe Bacon do let(:bacon) { Bacon.new(chunkiness) } let(:chunkiness) { true } it 'is chunky' do bacon.chunky. end end # good describe Bacon do let(:bacon) { Bacon.new(chunkiness) } let(:chunkiness) { true } it 'is chunky' do expect(bacon.chunky?).to be_truthy end end
usage # bad describe Bacon do let ( : bacon ) { Bacon . new ( chunkiness ) } let ( : chunkiness ) { true } it ' is chunky ' do bacon . chunky . end end # good describe Bacon do let ( : bacon ) { Bacon . new ( chunkiness ) } let ( : chunkiness ) { true } it ' is chunky ' do expect ( bacon . chunky? ) . to be_truthy end end