Mid-level Track Roadmap

Testing: in-memory database

This course asks whether a Rails test suite should run against an in-memory SQLite database, and answers by measuring. It profiles a 1,206-example RSpec suite and compares database round trips with boot time and slow sandbox examples. It explains how SQLite's :memory: mode and shared cache work. It then weighs PostgreSQL features such as jsonb, pg_trgm and ILIKE against the risk of silent divergence. It also covers transactional tests, other ways to speed up the suite, and the projects where an in-memory database fits.

What you'll learn

  • ✓Profiling an RSpec suite with --profile before optimizing
  • ✓How SQLite :memory: databases, shared cache URIs and connection pools interact
  • ✓Why jsonb, pg_trgm, ILIKE and window functions make SQLite tests diverge from production
  • ✓How transactional fixtures and savepoints isolate each example
  • ✓Practical speedups: one file per run, --only-failures, random order, build over create, parallel_tests
  • ✓When an in-memory database or in-memory test double is the right choice
Free preview · Lesson 1 4 min read

Where the time actually goes

This course is about a well-known trick: run the test suite against an in-memory SQLite database instead of a real one, and watch it get faster. The trick is real. Whether it helps you is a question with a measurable answer, and measuring first is the entire discipline.

Read the full lesson free →

Curriculum

7 lessons
Type to start searching...