For years I've followed the rails convention of putting spec files in a spec folder and entirely separate from the code they describe:
- app
- controllers
- application_controller.rb
- models
- user.rb
- spec
- controllers
- application_controller_spec.rb
- models
- user_spec.rb
However there's a lot of unnecessary dislocation and confusion that can come with that approach and I really like Angular's approach of keeping components, their specs and code side by side. Having worked on large rails projects, the dislocation between spec and code can become incredibly confusing and disorientating.
What changes would be needed to make this happen?
I'd like to experiment doing the same thing in rails and moving the specs to sit next to the files they describe so that the directory structure is more similar to this:
- app
- controllers
- application_controller.rb
- application_controller_spec.rb
- models
- user.rb
- user_spec.rb
What things will I need to change to make this work?
A couple of things that spring to mind are:
- making sure Zeitwerk doesn't load spec files into memory on app load
- adjusting guard so that it watches the correct directories
What other things would I need though and is there anything in particular I should watch out for?