How to Make RubyMine Autodetect Subfolders as Spec Files

This message was imported from the Ruby/Rails Modularity Slack server. Find more info in the import thread.

Message originally sent by slack user U717FXJ8HWK

Has anyone been able to figure out how to make RubyMine autodetect packs/foo/spec subfolders as containing specs? I know it’s possible to mark those as “Test Sources Root”, but it’s tedious if you have lots of packs.

Well this is funny, I have no idea if there’s a magic way to do it, but I wrote a Ruby script just yesterday to automatically mark all packs/*/spec as test roots in RubyMine :smile: Happy to share if you’re interested

Message originally sent by slack user U717FXJ8HWK

Would love to see your approach. I assume it edits .idea/*.iml files, right?

correct

I’ve exported my script into a gist: https://gist.github.com/iMacTia/adcf8d38b82a1cafacdb9dede10d96ab

Careful because there are a few things you need to change in there:
• the path to the project root (depending on where you put this script)
• the project name (ours is syft2backend)
• the root of your packs (in our project, we changed that to components)

Message originally sent by slack user U717FXJ8HWK

Do you know how RubyMine reacts if the .iml file is edited while it’s running? I don’t think it would reload the project :thinking_face:

Message originally sent by slack user U717FXJ8HWK

Just ran the script, and RubyMine did reload the project! I think I’ll adopt this in our project as well :smile: Thank you!

yes the same happened to me, it just realised on its own and reloaded :open_mouth: !

Message originally sent by slack user U717FXJ8HWK

Some thoughts:
• I think it would make sense to convert this script into a Rake task that would inspect Stimpack’s configuration to discover packages’ paths, so that there’s no possibility of paths being out of sync
• Rake task could be shipped as a gem (or as a part of some exising gem, TBD)
• Adding old backup cleanup would be nice
• It needs to become more generic (i.e. autodiscover .idea/*.iml instead of having it hardcoded)

I wholeheartedly agree with all of the above!
I hadn’t thought about sharing it with the world while writing it (I was busy fighting with Nokogiri just to make it work :joy: ), but I’d love to see this turned into something reusable in a plug-and-play way :raised_hands: