Brutal 💎🔨

RuboCop Status Build Status Gem Version Inline docs Documentation

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

Intro

I Hate Tests

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

Overview

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.

Warning

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.

Installation

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.

Usage

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}"

contexts:
  string:
    - Alice
    - Bob

actuals:
  - "%{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"
end

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

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

actual = begin
  "Hello " + "Bob"
end

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

More examples

https://github.com/fixrb/brutal/raw/main/examples/

Rake integration example

A generated test.rb file could be matched as follows:

Rake::TestTask.new do |t|
  t.pattern = "test.rb"
end

Contact

Versioning

Brutal follows Semantic Versioning 2.0.

License

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


This project is sponsored by:
Sashite