---
title: "Spec-tacular: ways to think about writing expressive RSpec"
description: "Structuring RSpec like a scientific experiment, with shared setup as control variables, `subject` as the dependent variable and `let` inside contexts as the independent variable, makes specs read as documentation of a class's interface."
url: "https://swe.quest/articles/spec-tacular-ways-to-think-about-writing-expressive-rspec-678c66c3f853b737"
canonical: "https://engineering.freeagent.com/2026/07/07/spec-tacular-ways-to-think-about-writing-expressive-rspec/"
source: "FreeAgent Engineering"
published: "2026-07-07"
difficulty: "medium"
kind: "Opinion"
reading_minutes: 6
tags: ["testing","ruby"]
---

# Spec-tacular: ways to think about writing expressive RSpec

A post on [FreeAgent Engineering](https://swe.quest/sources/freeagent.md), published 2026-07-07, 6 min read, Opinion. Original: [https://engineering.freeagent.com/2026/07/07/spec-tacular-ways-to-think-about-writing-expressive-rspec/](https://engineering.freeagent.com/2026/07/07/spec-tacular-ways-to-think-about-writing-expressive-rspec/)

## Summary

Structuring RSpec like a scientific experiment, with shared setup as control variables, \`subject\` as the dependent variable and \`let\` inside contexts as the independent variable, makes specs read as documentation of a class's interface. Implicit descriptions via \`subject\` and \`is\_expected\` work well for plain Ruby objects. View and controller specs usually benefit from hand-written descriptions that state behaviour, for example "includes the delete button" instead of a CSS selector. For controllers, a named \`subject(:response)\` returning \`@response\` combined with compound matchers lets several expectations share a single request. Nesting deeper than two contexts adds complexity, and Minitest's plain-Ruby four-phase style is a fair alternative, but RSpec's expressiveness is worth it if you treat tests as documentation.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Testing](https://swe.quest/tags/testing.md) (Engineering practices)
- [Ruby](https://swe.quest/tags/ruby.md) (Languages)

## Prerequisites

- RSpec basics
- Ruby on Rails controllers and views ([easy posts on Ruby](https://swe.quest/tags/ruby.md?difficulty=easy))

## Keywords

RSpec, Ruby on Rails, Minitest, betterspecs.org

## Related posts

- [What if writing tests was a joyful experience?](https://swe.quest/articles/what-if-writing-tests-was-a-joyful-experience-24be6abe32cc317e.md): Jane Street Tech Blog · 2023-01-09 · Medium · 11 min read · Testing, Functional programming, Developer productivity
  Expect tests (snapshot tests) let you write a blank \`\[%expect\]\` block under code that prints output; the test runner fills in the actual output as a diff you can accept in your editor, making test-writing feel like a REPL session.
- [Focus On Behavior, Not State, for a More Maintainable Codebase](https://swe.quest/articles/focus-on-behavior-not-state-for-a-more-maintainable-codebase-d186fd1356391a16.md): Shopify Engineering · 2022-09-01 · Medium · 9 min read · Refactoring & migrations, Ruby, E-commerce, System design
  When adding pre-orders and try-before-you-buy to Shopify's Purchase Options APIs, code that equated "has a selling plan" with "is a subscription" forced repeated refactors.
- [Reliving Your Happiest HTTP Interactions with Ruby’s VCR Gem](https://swe.quest/articles/reliving-your-happiest-http-interactions-with-ruby-s-vcr-gem-875b5fd62be42b02.md): Shopify Engineering · 2023-01-05 · Medium · 8 min read · Ruby, Testing
  VCR records live HTTP interactions into YAML "cassettes" and replays them in Ruby tests, giving accurate fixtures for complex, slow, or poorly understood APIs where hand-built Webmock stubs drift from real behavior.
- [Enhancing the Mock Server: A User Interface Approach](https://swe.quest/articles/enhancing-the-mock-server-a-user-interface-approach-ff47adf3053feadf.md): Zalando Engineering · 2024-04-24 · Medium · 7 min read · Frontend, React, Testing, Developer productivity
  Zalando's team built a UI on top of mirage.js so product managers and designers can switch which mocked response each API endpoint returns on a staging build, without code changes or redeploys.
- [Recycle your tests: many shades of green](https://swe.quest/articles/recycle-your-tests-many-shades-of-green-4564b5fe718b0f4b.md): trivago tech · 2026-11-12 · Medium · 6 min read · Testing, Observability, Web performance, CI/CD
  trivago reuses a small subset of its existing Selenium/Cucumber end-to-end scenarios (via its internal framework trupi) for three extra jobs by adding Gherkin tags rather than new test code.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
