Excluding Spec Directories from Packwerk Checking: How to Handle Private Models in System Tests?

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

Do you omit your spec directories from packwerk checking?
For example, I have an “application” pack, leveraging business logic from multiple domains to deliver value to the user.
In a system spec (capybara), I have an assertion about the database being affected a certain way… after all, this is a system test.
But packwerk complains that I’m using a private model in my test logic (wherein I fetch the last ActiveRecord record of that type, and ensure that what I think ought to have been persisted, was persisted).

Message originally sent by slack user U715TW4PT5O

I definitely wouldn’t globally omit them, but in this case it sounds like a well reasoned scenario you could add to a package_todo.yml file?https://github.com/Shopify/packwerk/blob/main/RESOLVING_VIOLATIONS.md

@gpassero At Gusto, we included them for a long time. The rationale was that we believe we should only test public API, not private API.

We ended up turning this off with the hope to turn it on in the future, because with so few public APIs yet, this was hard to institute in practice. Furthermore, it let us focus on violations within the production code which is arguably more valuable to focus on.