Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
O

oaken

> 编程语言
Open source

Speed up your test suite and have easy to maintain seeds. Replace slow factories & skip the maintenance burden of fixtures. Fast tests, clear datasets.

435 stars0 likes2 views
WebsiteGitHub

About

Speed up your test suite and have easy to maintain seeds. Replace slow factories & skip the maintenance burden of fixtures. Fast tests, clear datasets.

Oaken

Oaken is fixtures + factories + seeds for your Rails development & test environments.

You may want to head straight to the examples directory.

Benefits

  • In development:

    • Add conventions for db/seeds.rb that feel like Rails.
    • Grouping by scenario: choose how to best group your data.
    • Reveal your Domain Model: describe your object graph sequentially, helping developers see how your app works.
    • Ruby-based recipe-like data scripts: setup accounts first, then attach users, then hang other models off of those.
    • Raise modelling problems early: Oaken can help expose when something feels awkward or off to give you design clues.
  • In tests, reuse development seed data:

    • Tests mirror what developers have already seen in their dev browser.
    • Easier developer onboarding by building a proper mental model faster.
    • Less code that's easier to maintain with more visibility into your object graph.

Benefits over factories

  • Fast tests! Seed shared records once and reuse them across tests, transactions rollback changes.

    • One team saw a 3x speed increase over factories.
    • Another shaved off 5min on their CI time with less than a days work, and they only scratched the surface.
  • Visibility into your system: factories optimize for isolation, which make it easy to get started, but becomes more complex over time.

  • Save 20 lines of setup per test case.

    • Your mileage will vary, but this happened for a team that replaced factories with Oaken.
    • You do DRY up your tests more for non-trivial systems because you write the Oaken seed for common cases once, rather than per-test/file.
  • You can name things: don't lose hours debugging factory-based tests because everything's anonymous, like I have.

  • Less mental load: factories' structure requires you to put things together in your head. How many models and associations does one factory create?

  • DRY setup:

Also worth noting that you

Benefits over fixtures

  • Still fast tests! Oaken inserts data before tests run & wraps tests in transactions, just like fixtures.
  • No more YAML: use Ruby to lay out your object graph sequentially with better organization. You can even sketch it out in a console
  • Break out edge cases or complex scenarios: split data for edge cases or tricky test setups into their own cases, so you don't end up with a 500-line fixture file peppered with warts.
  • Way easier to reason about your object graph: no more chasing 10 files for 10 associations.
  • Less mental load: fixtures' structure requires you to put things together in your head.
  • Way condensed data setup: Oaken can dramatically cut down on some fixture files by letting you use helpers

Oaken is like fixtures, without the nightmare UX

Oaken takes inspiration from Rails' fixtures' approach of storytelling about your app's object graph, but replaces the nightmare YAML-based UX with Ruby-based data scripts. This makes data much easier to reason about & connect the dots.

In Oaken, you start by creating a root-level model, typically an Account, Team, or Organization etc. to group everything on, in a scenario. From your root-level model, you then start building your object graph by mirroring how your app works.

So what comes next in your account flow? Maybe it's creating Users on the account.

You can go further if you need to. Is the Account about selling something, like donuts? Maybe you add a menu and some items.

It'll look like this:

ruby
account = accounts.create :kaspers_donuts, name: "Kasper's Donuts"

kasper   = users.create :kasper,   name: "Kasper",   email_address: "[email protected]",   accounts: [account]
coworker = users.create :coworker, name: "Coworker", email_address: "[email protected]", accounts: [account]

menu = menus.create(account:)
plain_donut     = menu_items.create menu:, name: "Plain",     price_cents: 10_00
sprinkled_donut = menu_items.create menu:, name: "Sprinkled", price_cents: 10_10

[!NOTE] create takes an optional symbol label. This makes the record accessible in tests, e.g. users.create :kasper lets tests do setup { @kasper = users.kasper }.

With fixtures, this would be 4 different files in test/fixtures for accounts, users, menus, and menu_items. It would be ~20 lines of YAML versus ~6 lines of Ruby for this data.

Another issue in fixture files, is that objects from different scenarios are all mixed together making it hard to get a picture of what's going on — even in small apps.

Fixtures also require you to label every record and make them unique throughout your dataset — you have to be careful not to create clashes. This gets difficult to manage quickly and requires diligence on a team that's trying to ship.

However, often the fact that a record is associated onto another is enough. So in Oaken, we let you skip naming every record. Notice how the menus.create & menu_items.create calls don't pass symbol labels. You can still get at them in tests though if you really need to with accounts.kaspers_donuts.menus.first.menu_items.first.

See the fixtures version

yaml
# test/fixtures/accounts.yml
kaspers_donuts:
  name: Kasper's Donuts

# test/fixtures/users.yml
kasper:
  name: "Kasper"
  email_address: "[email protected]"
  accounts: kaspers_donuts

coworker:
  name: "Coworker"
  email_address: "[email protected]"
  accounts: kaspers_donuts

# test/fixtures/menus.yml
basic:
  account: kaspers_donuts

# test/fixtures/menu/items.yml
plain_donut:
  menu: basic
  name: Plain
  price_cents: 10_00

sprinkled_donut:
  menu: basic
  name: Sprinkled
  price_cents: 10_10

Oaken is like fixtures, we seed data before tests run

The reason you go through all the trouble of massaging your fixture files is to have a stable named dataset across test runs that's relatively quick to load — so the database call cost is amortized across tests.

Oaken mirrors this approach giving you stability in your dataset and the relative quickness to insert the data.

For instance, if you have 10 tests that each need the same 2 records, Oaken puts them in the database once before tests run, same as fixtures.

The tradeoff is that if you run just 1 test we'll still seed those 2 same records, but we'll also seed any other record you've added to the shared dataset that might not be needed in those tests.

We rely on Rails' tests being wrapped in transactions so any changes are rolled back after the test case run.

[!NOTE] It can be a good idea to structure your object graph so you won't need database records for your tests — reality can sometimes be far from that ideal state though. Oaken aims to make your present reality easier and something you can improve.

Oaken is unlike factories, focusing on shared datasets

Factories can let you start an app easier. It's just this one factory for now, ok, easy enough.

Over time, however, many teams find their factory based test suite slows to a crawl. Suddenly one factory ends up pulling in the rest of the app.

Factories end up requiring a lot of diligence and passing just the right things in just-so to make managable.

Oaken does away with this. See the sections on the fixtures comparisons above for how.

[!WARNING] Full Disclaimer: while I have worked on systems using factories, I overall don't get it and the fixtures approach makes more sense to me despite the UX issues. I'm trying to support a partial factories approach here in Oaken, see the below section for that, and I'm open to ideas here.

[!TIP] Oaken is compatible with FactoryBot and Fabrication, and they should be able to work together. I consider it a bug if there's compatibility issues, so please open an issue here if you find something.

Oaken is like factories, with dynamic defaults & helper methods

See the sections on defaults & helpers below.

The aim for Oaken is to have most of the feature set of factories for a fraction of the implementation complexity.

Oaken gives db/seeds.rb superpowers

Oaken upgrades seeds in db/seeds.rb, so you can put together scenarios & reuse the development data in tests.

This way, the data you see in your browser, is the same data you work with in tests to make your object graph easier to get — especially for people new to your codebase.

So you get a cohesive & stable dataset with a story like fixtures & their fast loading. But you also get the dynamics of FactoryBot/Fabrication as well without making tons of one-off records to handle each case.

The end result is you end up writing less data back & forth to the database because you aren’t cobbling stuff together.

Praise from users

But seriously; Oaken is one of the single greatest tools I've added to my belt in the past year

It's made cross-environment shared data, data prepping for demos, edge-case tests, and overall development much more reliable & shareable across a team

@tcannonfodder

Thanks for this wonderful project! My head doesn't grok factories and I just want vanilla Rails testing with something better than fixtures, and this is so much better.

The default YAML fixtures is somehow both too simple and too convoluted. It's hard to reference complex associations with it, and the fact that the data gets spread across many files makes it hard to read and harder to grasp.

Oaken, on the other hand, is closer to using the console, which we already know, only in a repeatable and tidier way. The testing data/seeds setup process just feels more intentional this way.

@evenreven

Design goals

Consistent data & constrained Ruby

We're using accounts.create and such instead of Account.create! to help enforce consistency & constrain your Ruby usage. This also allows for extra features like defaults and helpers that take way less to implement.

Pick up in 1 hour or less

We don't want to be a costly DSL that takes ages to learn and relearn when you come back to it.

We're aiming for a time-to-understand of less than an hour. Same goes for the internals, if you dive in, it should ideally take less than 1 hour to comprehend most of it.

Similar ideas to Pkl

We share similar sentiments to the Pkl configuration language. You may find the ideas helpful before using Oaken.

Oddly enough Oaken came out before Pkl, I just read the ideas here and went "yes, exactly!"

Setup

Loading directories/files

By default, Oaken.loader returns an Oaken::Loader instance to handle loading seed files.

You can load a seed directory via Oaken.loader.seed. You can also load a file, it'll technically just be a match that happens to only hit one file.

So if you call Oaken.loader.seed :accounts, we'll look within db/seeds/ and db/seeds/#{Rails.env}/ and match accounts{,**/*}.rb. So these files would be found:

  • accounts.rb
  • accounts/kaspers_donuts.rb
  • accounts/kaspers_donuts/deeply/nested/path.rb
  • accounts/demo.rb
  • and so on.

[!TIP] You can call Oaken.loader.glob with a single identifier to see what files we'll match. > Some samples: Oaken.loader.glob :accounts, Oaken.loader.glob "cases/pagination".

[!TIP] Putting a file in the top-level db/seeds versus db/seeds/development or db/seeds/test means it's shared in both environments. See below for more tips.

Any directories and/or single-file matches are loaded in the order they're specified. So loader.seed :data, :accounts would first load data and then accounts.

[!IMPORTANT] Understanding and making effective use of Oaken's directory loading will pay dividends for your usage. You generally want to have 1 top-level directive seed call to dictate how seeding happens in e.g. db/seeds.rb and then let individual seed files load in no specified order within that.

Using the setup phase

When you call Oaken.seed/Oaken.loader.seed we'll also call seed :setup fo

Issues· 7 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Ruby

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言