Running Tests Automatically with Guard

Another way to get test feedback quickly is to allow the tests to run automatically when your code changes. In Ruby, the Guard gem allows you to trigger arbitrary events when files change.[81] It’s a powerful system, and running tests is only a fraction of what it can do. You’re just going to manage basic setup here; full documentation is available online. Mac users should check out the Mac-specific wiki page to make sure Guard receives file events correctly.[82]

Guard is a generic system for triggering events, and it has separate libraries that make it easy to trigger specific kinds of events, such as starting a test.

To set up Guard, add the Guard gem and any of the dependent libraries to the Gemfile. ...

Get Rails 5 Test Prescriptions now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.