AI writes your code. AI writes your tests. But who tests the tests?
Copilot, Claude, and ChatGPT generate code faster than humans can review it. They'll even write tests that pass. But passing tests aren't the same as meaningful tests.
Mutant is mutation testing for Ruby. It systematically modifies your code and verifies your tests actually catch each change.
The more code AI writes for you, the more you need verification you can trust.
Each surviving (alive) mutation is a call to action with exactly one of two options:
- Keep the mutated code - your tests already specify the correct semantics, and the original code is redundant. Accept the mutation as a simplification.
- Add the missing test - the original code is correct, but the tests don't verify the behavior the mutation removed.
Mutant was created and is developed by Markus Schirp. It is the subject of IEEE-published research and is included in the Trail of Bits Ruby Security Field Guide.
# lib/person.rb
class Person
def initialize(age:)
@age = age
end
def adult?
@age >= 18
end
end# spec/person_spec.rb
RSpec.describe Person do
describe '#adult?' do
it 'returns true for age 19' do
expect(Person.new(age: 19).adult?).to be(true)
end
it 'returns false for age 17' do
expect(Person.new(age: 17).adult?).to be(false)
end
end
endTests pass. But run mutant:
gem install mutant-rspec
mutant run --use rspec --usage opensource --require ./lib/person 'Person#adult?'Mutant finds a surviving mutation indicating a shallow test:
def adult?
- @age >= 18
+ @age > 18
endYour tests don't cover age == 18. The mutation from >= to > doesn't break them.
This is just one of many mutation operators. Mutant also mutates arithmetic, logical, bitwise operators, removes statements, modifies return values, and more.
A full working example is available in the quick_start directory.
- Learn the nomenclature (subjects, mutations, operators)
- Set up your integration: RSpec or Minitest
- Run mutant on CI in incremental mode
Mutant is supported on Linux and macOS.
| Version | Runtime | Syntax | Mutations |
|---|---|---|---|
| 3.2 | ✔️ | ✔️ | ✔️ |
| 3.3 | ✔️ | ✔️ | ✔️ |
| 3.4 | ✔️ | ✔️ | ✔️ |
| 4.0 | ✔️ | ✔️ | ✔️ |
Free for open source. Use --usage opensource for public repositories.
Commercial use requires a subscription ($30/month or $250/year per developer). Enterprise — reach out directly. See commercial licensing for pricing and details.
- Configuration
- RSpec Integration
- Minitest Integration
- Incremental Mode
- Reading Reports
- Concurrency
- AST Pattern Matching
- Hooks
- Sorbet
- Nomenclature
- Limitations
- Mutant in the Wild
See CONTRIBUTING.md for development setup and guidelines.
- Contributors
- The
mutant-minitestintegration was sponsored by Arkency