Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/emancu/crotest
A tiny and simple test framework for crystal
https://github.com/emancu/crotest
assertions crystal crystal-lang test-driven-development testing testing-framework
Last synced: 6 days ago
JSON representation
A tiny and simple test framework for crystal
- Host: GitHub
- URL: https://github.com/emancu/crotest
- Owner: emancu
- License: mit
- Created: 2016-03-17T06:34:59.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2022-01-10T17:40:47.000Z (almost 3 years ago)
- Last Synced: 2024-10-25T01:24:52.322Z (15 days ago)
- Topics: assertions, crystal, crystal-lang, test-driven-development, testing, testing-framework
- Language: Crystal
- Homepage:
- Size: 35.2 KB
- Stars: 28
- Watchers: 5
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-crystal - crotest - A tiny and simple test framework (Testing)
- awesome-crystal - crotest - A tiny and simple test framework (Testing)
- awesome-crystal - crotest - A tiny and simple test framework (Testing)
README
# crotest
[![Build](https://github.com/emancu/crotest/actions/workflows/crystal.yml/badge.svg)](https://github.com/emancu/crotest/actions/workflows/crystal.yml)A tiny and simple test framework for Crystal with common assertions and no pollution into `Object` class.
## Example
```crystal
require "crotest"describe "DSL" do
it "defines small test cases" do
assert true
enddescribe "nested describes for a better readability" do
it "has only a few assertions" do
var = falsereject var
assert_equal false, var
assert_raise Exception do
raise Exception.new("Boom!")
end
end
endpending "tests are defined without a block"
pending "tests can also be defined with a block, which will not be executed" do
fail "This won't be executed :)"
end
end
```## Installation
Add this to your application's `shard.yml`:
```yaml
dependencies:
crotest:
github: emancu/crotest
```## Usage
```crystal
require "crotest"
```Run your tests with `crystal spec`.
### Assertions
- `assert`
- `reject`
- `assert_equal`
- `assert_raise`### Custom assertions
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:```crystal
require "crotest"module Crotest::Assertions
macro assert_greater_than_4(value, file = __FILE__, line = __LINE__)
assert {{value}} > 4, "#{{{value}}} <= 4", {{file}}, {{line}}
end
endit "supports my custom assertion" do
assert_greater_than_4 5
end
```### Before/After blocks
If 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.```crystal
before do
# First block to be executed
endafter do
# Fifth and last block to be executed
enddescribe "a nested context" do
before do
# Second block to be executed
endafter do
# Fourth block to be executed
endit "executes the before blocks and" do
# Third block to be executed
end
end
```## Contributing
1. Fork it ( https://github.com/emancu/crotest/fork )
2. Create your feature branch (git checkout -b my-new-feature)
3. Commit your changes (git commit -am 'Add some feature')
4. Push to the branch (git push origin my-new-feature)
5. Create a new Pull Request## Contributors
- [emancu](https://github.com/emancu) Emiliano Mancuso - creator, maintainer