DEV Community

Discussion on: Fixing Random, Intermittent, and Flaky RSpec Test Failures

phallstrom profile image
Philip Hallstrom

One thing I've found that can help with this is to have some basic tests for the model/factory at the top of the file. Something like this:

  let(:subject) { build(:widget) }

  it "is valid from the factory" do
    expect(subject).to be_valid

The above as well as some additional ones like "ensure username is unique" will ensure that any changes to your factory will be tested right up front where it's clear what's going wrong vs what appears to be a totally unrelated spec.