Skip to content

Files

Latest commit

 

History

History
59 lines (45 loc) · 1.24 KB

RSpec-MultipleExpectations.md

File metadata and controls

59 lines (45 loc) · 1.24 KB

Pattern: Too many expect calls in example

Issue: -

Description

Checks if examples contain too many expect calls.

This rule is configurable using the Max option.

Examples

# bad
describe UserCreator do
  it 'builds a user' do
    expect(user.name).to eq("John")
    expect(user.age).to eq(22)
  end
end

# good
describe UserCreator do
  it 'sets the users name' do
    expect(user.name).to eq("John")
  end

  it 'sets the users age' do
    expect(user.age).to eq(22)
  end
end

configuration

# .rubocop.yml
# RSpec/MultipleExpectations:
#   Max: 2

# not flagged by rubocop
describe UserCreator do
  it 'builds a user' do
    expect(user.name).to eq("John")
    expect(user.age).to eq(22)
  end
end

Configurable attributes

Name Default value Configurable values
Max 1 Integer
AggregateFailuresByDefault false Boolean

Further Reading