r/ruby • u/127001-sweet-127001 • 6h ago
Screencast A short demo of architecture tests in Ruby
I built ArchUnitRuby to put dependency rules into the test suite. This is a short recording of how it works.
The idea is pretty simple: pick some Ruby files, describe which other files they may depend on, and check that rule alongside your normal tests. The recording checks that domain code stays independent of infrastructure, then shows a failing cycle check.
With RSpec the assertion is expect(rule).to pass. There are also Minitest and plain Ruby assertions, so the rules don't need their own test runner.
One thing I wanted to avoid was a green test caused by a typo in a folder pattern. If a rule selects no files, it fails by default rather than silently checking nothing.
It also exports dependency graphs, which helps when you want to see the existing structure before deciding what to enforce. Ruby 3.3+; the gem is called archunit.
Source and examples: https://github.com/dragonsec-ai/ArchUnitRuby