Brutal 💎🔨

RuboCop Status Build Status Gem Version Inline docs Documentation

A code-first approach to automate the writing of unit tests.


I Hate Tests

I don't like tests. It's not DRY.
-- Matz


Let Brutal shape for you in no time the actual behavior of your code through as many combinations of contexts as needed.

By delegating to Brutal the repetitive (and redundant) task of writing tests, you'll be able to focus on your core business: the code itself.


Brutal development process does not prevent from bugs.

As a picture of the behavior of the code, a generated test suite is wrong as long as the code is wrong, regardless of whether all true expectations.

However, this document becomes relevant when it shows that the code behaves as it is supposed to. It is therefore important to read it well. This is the price for Brutal-Driven Development.


Add this line to your application's Gemfile:

gem "brutal"

And then execute:

$ bundle install

Or install it yourself as:

$ gem install brutal

Quick Start

Just type brutal in a Ruby project's folder and watch the magic happen.


The brutal.yml file is a manifest you can use to define your Brutal meta-spec. It has 4 top-level sections:

  • header - Specifies the code to execute before generating the test suite.
  • subject - Specifies the template of the code to be declined across contexts.
  • contexts - Specifies a list of variables to populate the subject's template.
  • actuals - Specifies templates to challenge evaluated subjects & get results.

Getting started

  1. Create a brutal.yml file in your application's root directory. The following example brutal.yml defines the shape of a Hello test suite:
subject: |
  "Hello " + "%{string}"

    - Alice
    - Bob

  - "%{subject}.to_s"
  - "%{subject}.length"
  1. Run the brutal command from the same directory.

  2. Read the generated test.rb file in the same directory:

# Brutal test suite

# ------------------------------------------------------------------------------

actual = begin
  "Hello " + "Alice"

raise if actual.to_s != "Hello Alice"
raise if actual.length != 11

# ------------------------------------------------------------------------------

actual = begin
  "Hello " + "Bob"

raise if actual.to_s != "Hello Bob"
raise if actual.length != 9

More examples

Rake integration example

A generated test.rb file could be matched as follows: do |t|
  t.pattern = "test.rb"



Brutal follows Semantic Versioning 2.0.


The gem is available as open source under the terms of the MIT License.

This project is sponsored by: