r/ruby • • 19d 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

22 Upvotes

2 comments sorted by

2

u/Salzig 18d ago

0

u/127001-sweet-127001 6d ago

Good question! We've since released ArchUnitRuby 1.0.0 and compared it with ArchSpec 1.1.0:

Coverage + workflow: rules run in RSpec/Minitest. Expanded mode checks imports and constant references; my fixtures caught import-only violations and import cycles the tested ArchSpec configuration didn’t flag.

Runtime: on my synthetic 5,000-file workload, median runtime was 6.83s versus 17.40s for ArchSpec - not a universal speed ranking.

Different strengths: ArchSpec also offers method/convention checks and ready-made architecture templates, which are useful beyond dependency testing.

I wrote up the full comparison, configurations, and limitations here: https://medium.com/@krusetristan1/ruby-architecture-testing-compared-why-id-choose-archunitruby-433a5db5810f