class RuboCop::Cop::RSpec::NoExpectationExample

Checks if an example contains any expectation.

All RSpec’s example and expectation methods are covered by default. If you are using your own custom methods, add the following configuration:

RSpec:
  Language:
    Examples:
      Regular:
        - custom_it
    Expectations:
      - custom_expect

@example

# bad
it do
  a?
end

# good
it do
  expect(a?).to be(true)
end

This cop can be customized with an allowed expectation methods pattern with an ‘AllowedPatterns` option. ^expect_ and ^assert_ are allowed by default.

@example ‘AllowedPatterns` configuration

# .rubocop.yml
# RSpec/NoExpectationExample:
#   AllowedPatterns:
#     - ^expect_
#     - ^assert_

@example

# bad
it do
  not_expect_something
end

# good
it do
  expect_something
end

it do
  assert_something
end

Constants

MSG

Public Instance Methods

on_block(node) click to toggle source

@param [RuboCop::AST::BlockNode] node

# File lib/rubocop/cop/rspec/no_expectation_example.rb, line 89
def on_block(node)
  return unless regular_or_focused_example?(node)
  return if includes_expectation?(node)
  return if includes_skip_example?(node)
  return if skipped_in_metadata?(node.send_node)

  add_offense(node)
end
Also aliased as: on_numblock
on_numblock(node)
Alias for: on_block