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


Keywords
ruby, scaffold, shape, test
License
MIT
Install
gem install brutal -v 1.6.0.beta4

Documentation

Brutal 💎🔨

Version Yard documentation Ruby RuboCop License

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 craft for you in no time a (potentially huge) framework-less vanilla Ruby file describing the actual behavior of your code across as many context combinations as necessary.

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

Brutal-Driven Development

Warning

The Brutal-Driven Development process does not prevent bugs from appearing in the code.

A generated test suite acts as a picture of the code's behavior. Therefore, if the code is wrong, the picture of the code's behavior will also be wrong.

The mere fact that all expectations are true does not mean that the code behaves as it should.

It is therefore the responsibility of the developer to analyze the generated behavioral pictures to ensure that the code reacts as it is supposed to according to the contexts in which it is evaluated.

Installation

Add this line to your application's Gemfile:

gem "brutal", ">= 1.6.0.beta1", require: false

And then execute:

bundle install

Or install it yourself as:

gem install brutal --pre

Command line

The brutal command comes with several options you can use to customize Brutal's behavior.

For a full list of options, run the brutal command with the --help flag:

brutal --help
Usage: #{$PROGRAM_NAME} [options] [files or directories]

    --format=FORMAT Choose "ruby" (default).
    --help          Display this help.
    --version       Display the version.

Usage

Brutal needs configuration files in YAML format to know how to write tests. Configuration file names are suffixed by _brutal.yaml and composed of 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.

When the configuration file is present, the generation of a test suite can be done with the command:

Assuming that in the workspace there is a configuration file named user_brutal.yaml, the test suite can be generated via one of these commands:

brutal user_brutal.yaml

or:

brutal .

or even:

brutal

This would create a user_brutal.rb file containing the test suite.

Assuming now that in the workspace there are a large number of configuration files named in the spec/ folder, the complete test suite could be generated recursively via this command:

brutal spec/ # => generate tests from each configuration file matching ./spec/**/*_brutal.yaml in to ./spec/**/*_brutal.rb

Some examples

https://github.com/fixrb/brutal/blob/v1.6.0.beta1/examples/

Rake integration example

Generated test suite files could be matched as follows:

Rake::TestTask.new do |t|
  t.pattern = "**/*_brutal.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 Sashité:

Sashité logo Sashité logo