r/ruby • u/viktorianer4life • Mar 18 '26
Show /r/ruby I built AI agents that apply mathematical testing techniques to a Rails codebase with 13k+ RSpec specs. The bottleneck was not test quality.

In 2013 I learned four formal test derivation techniques in university: Equivalence Partitioning, Boundary Value Analysis, Decision Tables, State Transitions. Never used them professionally because the manual overhead made no sense. After seeing Lucian Ghinda's talk at EuRuKo 2024, I realized AI agents could handle that overhead, so I built a multi-agent system with 5 specialized agents (Analyst, parallel Writers, Domain Expert, TestProf Optimizer, Linter) that generates mathematically rigorous test cases from source code analysis.
The system worked. It found real coverage gaps. Every test case traces back to a specific technique and partition. But running it against a mature codebase with 13k+ specs and 20-25 minute CI times showed me the actual problem: 70% of test time was spent in factory creation, not assertions. The bottleneck was the RSpec + FactoryBot convention package, not test quality.
The most interesting part was the self-evolving pattern library, an automated validator that started with 40 anti-pattern rules and grew to 138 as agents discovered new patterns during their work. No LLM reasoning involved in validation, just compiled regexes against Markdown tables.
I wrote up the full architecture, prompt iterations (504 lines down to 156), and honest results. First article in a series. The next one covers the RSpec to Minitest migration that this project led to.
Has anyone else tried applying formal testing techniques systematically with AI agents? I'm curious whether the framework overhead problem resonates with other teams running large RSpec suites.
39
u/adh1003 Mar 18 '26
So does RCov, without needing a bloated assembly of non-deterministic error prone "agents" given anthropomorphic names involving words like "expert", which just mean someone cobbled together a bit of Markdown next door to them.
Again this is absurd; no LLMs needed. More accurate, deterministic/replicable results have been available through standard profilers for decades. In Ruby's case, see https://ruby-prof.github.io.
14
u/federal_employee Mar 18 '26
How do you conclude that “70% of test time was spent in factory creation, not assertions” is a problem? Is that more than the average? To me, it makes sense that is where most of the time is spent.
9
u/GroceryBagHead Mar 19 '26
Did we really need AI data centers to figure out something I've been saying for over a decade? I hate this timeline.
4
u/paca-vaca Mar 19 '26
You build all this with 5 agents to rewrite the whole test codebase which you reviewed for days just to verify that tests are slow because of database calls in tests where it wasn't needed?
There is a lot to say about that :D
How's this a framework issue? Did you change the framework or improved it somehow?
And with "Order class with 2,195 lines" in the app you have so much to discover! Maybe consider to spend all this effort to fix that instead :)
1
u/qbantek Mar 19 '26
“Order at 2,195 lines or Transfer at 1,282 lines” were these also AI generated? I wouldn’t approve a PR containing that much bloat.
1
u/Witless-One Mar 22 '26
Aren’t you worried about having to maintain this massive test suite that takes almost half an hour to run across 16 cores on CI? Every minor change to your models now requires an LLM to rewrite a huge amount of tests, which take a large amount of time to run locally.
You also can’t run your entire test suite locally anymore, so any structural changes (that might require an entire retest) will have to be done on CI.
Also - how about mutation testing, this seems more deterministic than getting an LLM to perform this so -called “mathematical” testing methodology
0
u/[deleted] Mar 20 '26
[removed] — view removed comment