Why does Rails CLI not come with --watch option?

Hi all, this is my first post in this forum - nice to be here.

I wanted to ask something that seems like a jarring miss in the Rails CLI - why is it so hard to setup rails test to watch for file changes?

For example, for those familiar with Jest, their CLI provides this out of the box:

$ jest --watchAll

And what it does is to watch files and upon saving those files, if there are changes, re-run a subset or all of the tests.

It’s certainly a complex problem to figure out which specific tests to re-run based on affected code paths, but I’m not even talking about that level of cleverness. To start off, I’m just looking for something simple that re-runs all test cases in a specific test file when that test file has had newly saved modifications - that’d bring 50% of the usefulness to automating test runs in my opinion.

Has this been discussed before? If not, does anyone have context into why this isn’t a thing?

Sincerely, Nick

Welcome! This is a good suggestion, and it’s one that has already spawned some well-proven solutions. There are several gems that leverage Rails’ own file reloading to run affected tests automagically. Have a look here for some options: Category: Continuous Testing - The Ruby Toolbox

Walter

Thanks @walterdavis! Aside from the list of gems, you helped me learn about ruby-toolbox.com - I’m bookmarking it.

I have indeed heard of gems like guard and have also used it in a practice app. The setup is a bit fiddly and guard seems to run the System tests that are automatically generated by Rails, which in some cases is not ideal (whereas rails test skips system tests by default). This is the experience when running guard init minitest with guard + guard-minitest plugin. There’s probably a way to configure it to skip system tests though, which I’ll look into.

I wonder if I’m the only person who feels like it should come out of the box with the CLI. :thinking:

Coming to this thread late.

Yes - this would be very nice to have OOB. Guard-minitest barely works with Rails 7 and requires more work than seems reasonable to get it up