Stop Fixing One Broken Expectation at a Time: RSpec's aggregate_failures
RSpec's aggregate_failures collects every failed expectation in an example instead of stopping at the first. Here's how to enable it, where it pays off, and where it backfires.
ReadMeFeed / Community knowledge
Real questions. Useful conversations. Find the people who know your stack.
RSpec's aggregate_failures collects every failed expectation in an example instead of stopping at the first. Here's how to enable it, where it pays off, and where it backfires.
Verifying doubles replace plain doubles at owned seams so unit tests fail when a collaborator's API changes. This note covers requirements, trust boundaries, failure modes, and when to use integration tests instead.
Centralize reusable expectations with RSpec shared_examples, but watch for coupling and obscured intent. A practical guide with parameterized examples.
Decide between one expectation per example, plain multiple expectations, and RSpec's :aggregate_failures based on setup cost and assertion independence — with a working request-spec example and a validation procedure.
Master RSpec’s shared_examples to cut test duplication—define once, reuse everywhere, and verify with dry‑run and documentation output.
Copying RSpec tests across multiple spec files becomes a maintenance nightmare. Shared examples let you write a single test suite that can be applied to any number of classes, keeping your spec suite DRY while guaranteeing interface consistency.
Learn how to use RSpec's aggregate_failures to stop the 'fix-rerun' loop when validating complex objects, and when to choose it over compound matchers.
Define a contract once with RSpec shared examples and reuse it across example groups — including parameterization, it_behaves_like vs. include_examples, and the traps to avoid.
Learn why instance_double, class_double and object_double are safer than plain double(), how they validate method existence and signatures, and where their limits lie.