Brutal 💎🔨
A code-first approach to automate the writing of unit tests.
Intro
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.
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"
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
Brutal needs a configuration file to know how to write your tests.
Currently, only the YAML format is supported.
This file is by default named .brutal.yml
and is 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:
brutal .brutal.yml
or:
brutal .
or even:
brutal
This would create a test.rb
file containing the test suite.
Configuration files can also be named differently:
brutal path/to/test_hello_world.yml
This would create a path/to/test_hello_world.rb
file containing the test suite.
To avoid accidentally overwriting a file, the --no-force
option can be used:
brutal path/to/test_hello_world.yml --no-force
A path/to/test_hello_world.rb file already exists!
Getting started
- Create a
.brutal.yml
file in your application's root directory. For example: https://github.com/fixrb/brutal/blob/v1.4.0/examples/hello_world_v1/.brutal.yml - Run the
brutal
command from the same directory. - Read the generated
test.rb
file in the same directory: https://github.com/fixrb/brutal/blob/v1.4.0/examples/hello_world_v1/test.rb
More examples
https://github.com/fixrb/brutal/blob/v1.4.0/examples/
Rake integration example
A generated test.rb
file could be matched as follows:
Rake::TestTask.new do |t|
t.pattern = "test.rb"
end
Test suite
Brutal's test set is brutally self-generated here: ./test.rb
Contact
- Source code: https://github.com/fixrb/brutal
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é: