A Ruby test framework for people who don't have time for slow tests
A Ruby test framework for people who don't have time for slow tests
TLDR is a suspiciously-delightful testing framework for Ruby.
As a test library, TLDR is largely API-compatible with Minitest. As a test runner, TLDR boasts a few features RSpec's CLI still doesn't have.
The library, command line interface, and every decision in-between was prioritized to maximize productivity to promote fast feedback loops. Some highlights:
foo_test.rb), line number (foo_test.rb:13), name (--name test_foo), or regex pattern (-n /_foo/)--watch--timeout--fail-fast flag that aborts the run as soon as a failure is encountered--prepend)We hope you'll give it a try!
You can either read the rest of this README and learn about TLDR passively, or you can just clone this TLDR demo repo and work through its README as you play with its tests and run them with various options.
JUST IN CASE YOU'RE ALREADY SKIMMING THIS, I said stop reading and clone this interactive repo if you're a hands-on learner.
You know the drill. gem install tldr or add it to your Gemfile:
gem "tldr"By default, TLDR expects your tests to be in test/ with filenames that match test_*.rb or *_test.rb and will require a test/helper.rb if you define one.
…The tldr CLI will look for a .tldr.yml file in the root of your project that can set all the same options supported by the CLI. You can specify a custom YAML location with --config some/path.yml if you want it to live someplace else.
Any options found in the dotfile will override TLDR's defaults, but can still be overridden by the tldr CLI or a TLDR::Config object when running tests programmatically.
Here's an example project that specifies a .tldr.yml file as well as some internal tests demonstrating its behavior.
If you've ever seen a Minitest test, then you already know how to write TLDR tests. Rather than document how to write tests, this section just highlights the ways TLDR tests differ from Minitest tests.
First, instead of inheriting from Minitest::Test, TLDR test classes should descend from (wait for it) the TLDR base class:
class MyTest < TLDR
def test_looks_familiar
assert true
end
endSecond, if your tests depend on a test helper, it will be automatically loaded by TLDR if you name it test/helper.rb. That means you don't need to add require "helper" to the top of every test. If you want to name the helper something else, you can do so with the --helper option:
tldr --helper test/test_helper.rbThird, TLDR offers fewer features:
And that's it! You officially know how to write TLDR tests.
Because TLDR ships with a CLI, it offers a veritable plethora of ways to run your tests.
Once installed, running all your tests is just five keystrokes away:
tldrThis assumes your tests are stored in test/. It will also add lib/ to Ruby's load paths and require test/helper.rb before your tests, if it exists.
TLDR ships with a minimal rake task that simply shells out to the tldr CLI by default. If you want to run TLDR with Rake, you can configure the task by setting flags on an env var named TLDR_OPTS or in a .tldr.yml file.
All your Rakefile needs is require "tldr/rake" and you can run the task individually like this:
$ rake tldr
# Or, with options in TLDR_OPTS
$ TLDR_OPTS="--no-parallel" rake tldrHere's an example Rakefile that runs both TLDR and Standard Ruby as the default task:
require "standard/rake"
require "tldr/rake"
task default: ["tldr", "standard:fix"]One situation where you'd want to invoke TLDR with Rake is when you have multiple test suites that you want to be able to easily run separately (this talk discussed a few reasons why this can be useful).
To create a custom TLDR Rake task, you can instantiate TLDR::Task like this, which allows you to define its TLDR::Config configuration in code:
require "tldr/rake"
TLDR::Task.new(name: :safe_tests, config: TLDR::Config.new(
paths: FileList["safe/**/*_test.rb"],
helper_paths: ["safe/helper.rb"],
load_paths: ["lib", "safe"]
))The above will create a second Rake task named safe_tests running a different set of tests than the default tldr task. Here's an example from TLDR's test suite.
The tldr CLI includes a --watch option that will watch for changes in any of the configured load paths (["test", "lib"] by default) and then execute your tests each time a file is changed. To keep the output up-to-date and easy
to scan, it will also clear your console before each run.
Note that this feature requires you have fswatch installed and on your PATH
Here's what that might look like with the --emoji flag enabled:
If you'd rather use TLDR by running Ruby files instead of the tldr CLI, you can simply require "tldr/autorun" (just like require "minitest/autorun").
Given a file test/some_test.rb:
require "tldr/autorun"
class SomeTest < TLDR
def test_truth
assert true
end
endYou can then run the test by passing ruby the file:
$ ruby test/some_test.rbAny CLI options you add will still be parsed, as well (e.g. ruby my_test.rb --emoji will work).
If you want to be explicit about setting the Kernel.at_exit hook, or if you want to configure TLDR with code, you can invoke TLDR.at_exit! directly:
require "tldr"
TLDR::Run.at_exit! TLDR::Config.new(emoji: true)If we just want to know if the build passes, we want to know as fast as possible. Ever see a test fail and then sit around waiting for the whole suite to finish running anyway? Why wait? Turn on --fail-fast and abort the test run the instant a failure is encountered:
tldr --fail-fastAdditionally, you might notice the top of each run will show you a command you can use to execute the same run, like this:
Command: bundle exec tldr --fail-fast --prepend "test/calculator_test.rb"That's because TLDR will look at the file system and move your most-recently-edited test file to the front of the queue with --prepend. When used in conjunction with --fail-fast, you'll fail extra fast, because the most likely test to fail is the one you're actively working on.
We initially developed TLDR because we wanted a test runner that supported suite-wide time limits as a first-class feature. When test suites become slow, people run them (much) less often. And once a developer gets in the habit of only running tests occasionally, it's not long before they only run them before push, and then only the ones they're immediately working on, and then they just wait for CI to run them in a pull request. And if you don't run all your tests very often, you don't feel any pain when you make your tests (or the code its testing) slower.
Each time you write code and don't run your tests, you're making an assumption that whatever code you just wrote works flawlessly. If that assumption is correct, you saved however much time it takes to run your tests. But every time that assumption is incorrect, you've just extended the amount of time before discovering that you broke something. If that's a few minutes later, that might only cost a few minutes of rework. If you only run tests once or twice a day, you might have to undo hours of work to fix it.
We originally came up with the idea of TLDR on a livestream, joking that only an unconfigurable 1.8 second time limit would prevent test suites from ballooning in duration over time. As of 1.0, we've made the timeout configurable, but we still think it's a good idea to enable it with the --timeout option:
tldr --timeoutNot only does a timeout keep us running the whole suite frequently (it'll never take more than 1.8 seconds, after all), but even if the suite begins to exceed our self-imposed timeout, TLDR's random test order and parallel execution means that—so long as you keep running that partial suite frequently—you'll still be running ALL your tests many more times than if they waited until some arbitrary checkpoint to run them.
When enabled, --timeout will set the timer to 1.8 seconds. But you can set whatever time limit you like. The right value is depends on your individual capacity for paying attention. Basically, "however long you're willing to wait without caving and running your tests less often."
Examples:
# A badass 200ms timeout
tldr --timeout 0.2
# A miserable-sounding 20 second timeout
tldr --timeout 20If we've won you over towards this way of working, we suggest creating a .tldr.yml file in the root of your project and specifying your desired timeout.
For TLDR Classic™ and a 1.8s timeout:
# .tldr.yml
timeout: trueOr any number of seconds you like:
# .tldr.yml
timeout: 0.01And if you're running with the timeout enabled this way, you can still disable it for any given test run by adding the --no-timeout flag.
By default, when TLDR times out it exits with status code 3 to indicate the test suite was aborted. However, if you know that your full test suite is slower than whatever duration you consider to be "fast enough for fast feedback", you can use the --exit-0-on-timeout flag and simply use the timeout to enforce whatever feedback loop budget you set with --timeout.
For example:
# Get feedback within 400ms but don't consider a timeout a failure
tldr --timeout 0.4 --exit-0-on-timeoutThis is particularly useful for:
In AI agent-based coding workflows, it's common to configure hooks that will block the agent from proceeding whenever tests or linters fail. With Claude Code specifically, a hook will only block if i