| name | rspec-conventions |
| description | Rootstrap RSpec conventions. Use when writing, reviewing, or editing RSpec test files (spec/**/*_spec.rb, spec/rails_helper.rb, spec/spec_helper.rb, spec/support/**/*.rb) or factories. Covers describe/context structure, let/subject, matchers, factories, mocking/stubbing, shared examples, and spec types (model, request, feature, controller). |
| paths | spec/**/*_spec.rb,spec/rails_helper.rb,spec/spec_helper.rb,spec/support/**/*.rb,spec/factories/**/*.rb |
RSpec Conventions (Rootstrap)
Apply these whenever producing or modifying RSpec test code. Full guide: https://github.com/rootstrap/tech-guides/blob/master/ruby/rspec/style_guide.md
Complements ruby-conventions — language-level Ruby style still applies.
Structure & Formatting
- No blank line directly after
describe/context/feature opening.
- Leave one blank line after
let/subject groups and after before/after blocks.
- Group
let and subject together; separate them from before/after with a blank line.
- One blank line around each
it block.
- Use
before (not before(:each)); before(:all) should be rare and explicit.
describe & context
it / Examples
let & subject
Matchers
Factories & Fixtures
- Use FactoryBot (
create(:article)); never Rails fixtures.
- Avoid
ModelName.create in integration specs — reach for the factory.
- Use Faker for fake data; Database Cleaner keeps state isolated.
Mocking / Stubbing / Doubles
Shared Examples
- Extract shared examples when duplication is real and clarifies intent — don't DRY prematurely.
- Duplication inside specs is acceptable, even preferred, if it aids readability.
Spec Types (quick guidance)
- Model/service/job/mailer specs — unit tests of public methods and callbacks; don't test private methods.
- Feature specs — full UI flow via Capybara; only enable JS driver when required.
- Controller specs — for non-API controllers and edge cases faster than feature specs.
- Request specs (
type: :request) — preferred over controller specs for APIs; exercises routes and real responses.
- Prefer
describe ... do style over Capybara's feature/scenario DSL for consistency.