As Arkency we’re making our efforts to inculcate Domain Driven Design into Rails community. You should be familiar with Rails Event Store ecosystem. We use it in our customers’ projects with success since quite some time.
One of the cornerstones of the Rails Event Store is keeping it 100% covered with tests. Rails Event Store can become an important part of the application. There’s no other way than keeping it well covered with tests. Mutant is the tool which supports us in achieving that.
One of the missing parts of our ecosystem were RSpec matchers. In each customer’s project, we wrote custom matchers. Some of you who already use Rails Event Store will do the same sooner or later. Based on our experience we decided to provide matchers. They can be used out of the box via rails_event_store-rspec library. I’ll try to describe it better in a separate post.
Developing in RailsEventStore ecosystem
For each of the RailsEventStore parts, we provide
Makefile, for convenience use. After cloning the interesting repository run
make install and you are ready to go. If you want to run tests, just run
make test. To run mutant you do
make mutate. The second one runs tests as an initial phase. Yet, I’ve got tired of constantly switching between my code editor and terminal. Running
make mutate and switching back to code since it takes some time for the Mutant to complete the run.
Looking for an improvement
I used Guard in past to track file changes and run tests but I remember that it was integrating with the code a bit too much. Adding to
.Guardfile to a repository is such integration for me. I don’t want to force people to install stuff which is not necessary for contributing. Anarchy, you know.
I reminded myself that jest is using something under the hood for watching file changes. And there it is, please meet the Watchman - A file watching service. We can read on the project page that Watchman exists to watch files and record when they change. It can also trigger actions (such as rebuilding assets) when matching files change. Sounds good enough. I went through the docs. I’ve figured that there’s dedicated command for running
Makefile tasks. It’s called
How to use it
If you’re a Mac user, simply
brew install watchman. More in the installation section of the docs.
What’s the magic command to use with any part of
watchman-make -p '**/*_spec.rb' '**/*.rb' 'Makefile' -t mutate
-p stands for the patterns to watch, we want to run a test on any spec or lib file. Just figured out that the second pattern includes a first one.
-t is for specifying the build target, in our case, it’s
mutate task from
The tool is powerful. You can specify many targets responding to several patterns. But that’s not our case.
It might be cool to get some notification on success or failure. Current setup is good enough for me and improves my workflow. Yet I don’t want to spend more time on that now.