Writing Faster Tests by Bypassing Rails

Get an overview of the groups of the tests we've written so far.

We'll cover the following

Bypassing Rails for faster tests

Another way to run tests without loading the entire Rails framework is to write tests that don’t require the entire Rails framework. That sounds crazy, and we know since we’re writing a Rails application. Let’s see what we mean.

The tests we’ve written so far mostly fall into five groups:

  • End-to-end tests. These tests require the entire Rails stack since we’re testing the entire stack.

  • Tests that use only ActiveRecord and need the database. Right now, this group includes tests for ActiveRecord finder methods and our action object tests that save to the database.

  • Request tests that require ActionPack may or may not require ActiveRecord and may or may not touch the database, depending on how they’re stubbed.

  • Tests that use ActiveRecord objects but don’t touch the database.

  • Tests that use no Rails-specific classes at all.

The first category will be, broadly speaking, be the slowest, and each step down should be a faster set of tests. Right now, we don’t have many tests in the last category. We think the only ones there are the AvatarAdapter tests we wrote to interact with Twitter. How do we move tests to the lower and faster categories in this list? And why is removing Rails helpful?

Note: Rails is not the application. It is a framework using which we build our application, unless we work at Basecamp and actually develop Rails.

Get hands-on with 1200+ tech skills courses.