Running Tests Automatically with Guard
Explore how to set up and use the Guard gem to automatically run tests when files change in your Ruby on Rails application. Understand integration with RSpec and Minitest, watch commands, and customization to speed up your test-driven development workflow.
Running tests automatically with Guard
Another way to get test feedback quickly is to allow the tests to run automatically when our code changes. In Ruby, the Guard gem allows us to trigger arbitrary events when files change. It’s a powerful system, and running tests is only a fraction of what it can do. We’re just going to manage the basic setup here; the full documentation is available online. Mac users should check out the Mac-specific wiki page to ensure Guard receives file events correctly.
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.
Setting up Guard
To set up Guard, we’ll add the Guard gem and any of the dependent libraries to the Gemfile. Note that these all go in the development group, not the test ...