A tiny and simple test framework for Crystal with common assertions and no pollution into Object class.
require"crotest"
describe "DSL"do
it "defines small test cases"do
assert trueend
describe "nested describes for a better readability"do
it "has only a few assertions"do
var =false
reject var
assert_equal false, var
assert_raise ExceptiondoraiseException.new("Boom!")
endendend
pending "tests are defined without a block"
pending "tests can also be defined with a block, which will not be executed"dofail"This won't be executed :)"endendAdd this to your application's shard.yml:
dependencies:
crotest:
github: emancu/crotestrequire"crotest"Run your tests with crystal spec.
assertrejectassert_equalassert_raise
Extend the assertions used by Crotest is really easy.
You need to open the module Crotest::Assertions and add your assertions like the example below:
require"crotest"moduleCrotest::Assertionsmacroassert_greater_than_4(value, file=__FILE__, line=__LINE__)
assert {{value}} >4, "#{{{value}}} <= 4", {{file}}, {{line}}
endend
it "supports my custom assertion"do
assert_greater_than_4 5endIf you need to run code before or after each test, declare each block like in the example below.
Remember to define before/after blocks before the corresponding it blocks.
Given this is not dynamically evaluated, we must define at the beginning of the file or describe block.
before do# First block to be executedend
after do# Fifth and last block to be executedend
describe "a nested context"do
before do# Second block to be executedend
after do# Fourth block to be executedend
it "executes the before blocks and"do# Third block to be executedendend- Fork it ( https://github.com/emancu/crotest/fork )
- Create your feature branch (git checkout -b my-new-feature)
- Commit your changes (git commit -am 'Add some feature')
- Push to the branch (git push origin my-new-feature)
- Create a new Pull Request
- emancu Emiliano Mancuso - creator, maintainer