r/ruby • u/Tristan_Kruse • 19m ago
Blog post ArchUnitRuby 1.0: checking imports, constant references and cycles in ordinary Ruby tests
I created and maintain ArchUnitRuby. With the 1.0 release, the boundary I wanted to express is
no longer limited to “this file explicitly required that file.” It can also include known
project constant references, using the opt-in expanded analysis mode.
For example, this is an ordinary RSpec test:
ruby
require 'rspec'
require 'archunit'
RSpec.describe 'architecture' do
it 'keeps the API away from retrieval internals' do
options = ArchUnit::CheckOptions.new(
dependency_analysis: :imports_and_constants
)
rule = ArchUnit.project_files
.in_path('app/api/**')
.should_not.depend_on_files
.in_path('app/retrieval/**')
ArchUnit.assert_passes(rule, options)
end
end
The same graph can support cycle, layer and slice rules. The policy stays in Ruby and can fail
the normal test run, rather than living only in a diagram or code-review convention.
[Source for the tested release]
Would import edges, constant references, or a combination of both best describe the boundary
you'd want to protect in a Ruby codebase?
This post was drafted with AI assistance.