This message was imported from the Ruby/Rails Modularity Slack server. Find more info in the import thread.
Message originally sent by slack user U712YWCKK8T
When using packs-rails or just packwerk, do you put all tests for all packages under test, or do you have package-specific test directories e.g. packs/foo/test?
We have tests (spec in our case, but it doesn’t really matter) as a subdirectory of packs.
It has historically created some discussion around the two approaches, we so far we’ve always agreed in keeping them there
Do you have any test helpers defined in a package that are used by other packages? For example, we have a Foo::TestHelpers defined in packs/foo, and we want packages that depend on packs/foo to be able to use it in their tests, but I can’t figure out where to put it without violating privacy checks (I don’t want to have it in app/public as I don’t want it loaded in the actual server)
on your first question: the cool thing is that you have options. Moving them into packs gives you more info from packages, moving them out might give you less. We currently have them in packages, but ignore privacy violations in specs, because we wanted to emphasize work on production-code privacy violations first
Your observation that the test helper situation is not currently solved well by packwerk. It would be great to be able to recreate the “separate require for test helpers” pattern that we use for gems.
The best way I know to do it is to create a convention about the location and name of the test helpers in packs and then exclude them from analysis.
We store everything (sample size of two here, packs are still very new to our organization) in packs/:pack/{app,spec} . It works nicely to run the entire suite, or the tests for a single pack. I’m currently struggling with code that should live in a pack’s spec_helper but needed in the app’s spec directory. Right now we shove it all into the main spec_helper which works, but I’m excited to see discussion around this issue.
There’s a solution in the first discussion I linked above based on making spec_helpers a package. It’s a little clunky if you’re using packs-rails because you have to use a sub-directory that Rails won’t load, and it doesn’t let the helpers access private members of the package, but it works.