<commit_before># microtest [![Build Status](https://travis-ci.org/Ragmaanir/microtest.svg?branch=master)](https://travis-ci.org/Ragmaanir/microtest)[![Dependency Status](https://shards.rocks/badge/github/ragmaanir/microtest/status.svg)](https://shards.rocks/github/ragmaanir/microtest)

### Version 1.0.0

A very tiny testing framework inspired by minitest/minitest.cr.

## Features

- This framework is opinionated
- It uses power asserts by default. There are no `assert_equals`, `assert_xyz`, just power asserts (except for `assert_raises`)
- It uses the spec syntax for test case structure (`describe`, `test`, `before`, `after`). Reasons: No test-case name-clashes when using describe. Not forgetting to call super in setup/teardown methods.
- No nesting of describe blocks. IMO nesting of those blocks is an anti-pattern.
- No let-definitions. Only before / after hooks. Use local variables mostly.
- Tests have to be started explicitly by `Microtest.run!`, no at-exit hook.

## Installation


Add this to your application's `shard.yml`:

```yaml
dependencies:
  microtest:
    github: ragmaanir/microtest
```


## Usage


```crystal
describe MyLib::WaterPump do
  test "that it pumps water" do
    p = MyLib::WaterPump.new("main")
    p.enable
    p.start

    assert(p.pumps_water?)
  end

  test "that it pumps with a certain speed" do
    p = MyLib::WaterPump.new("main", speed: 100)
    p.enable
    p.start

    assert(p.pump_speed > 50)
  end

  test "this one is pending since it got no body"

  test "only run this focused test", :focus do
  end

  test! "and this one too since it is focused also" do
  end
end

```

## Power Assert Output

```crystal
describe AssertionFailure do
  test "assertion failure" do
    a = 5
    b = "aaaaaa"
    assert "a" * a == b
  end
end

```

Generates:

![Assertion Failure](assets/assertion_failure.png?raw=true)

### Microtest Test Output (default reporter)
![Default](assets/spec.png?raw=true)

## Reporters

```crystal
describe First do
  test "success" do
  end

  test "skip this"
end

describe Second do
  def raise_an_error
    raise "Oh, this is wrong"
  end

  test "first failure" do
    a = 5
    b = 7
    assert a == b * 2
  end

  test "error" do
    raise_an_error
  end
end

```

### Progress Reporter
![Progress Reporter](assets/progress_reporter.png?raw=true)

### Description Reporter
![Description Reporter](assets/description_reporter.png?raw=true)

### When focus active

```crystal
describe Focus do
  test "not focuesd" do
  end

  test! "focused" do
  end

  test "focused too", :focus do
  end
end

```

![Focus](assets/focus.png?raw=true)

## Development

I am using guardian to run the tests on each change. Also the guardian task uses the computer voice to report build/test failure/success. 
Run `build.cr` to run tests and generate `README.md` from `README.md.template` and generate the images of the test outputs (using an alpine docker image).
<commit_msg>Fix typo<commit_after># microtest [![Build Status](https://travis-ci.org/Ragmaanir/microtest.svg?branch=master)](https://travis-ci.org/Ragmaanir/microtest)[![Dependency Status](https://shards.rocks/badge/github/ragmaanir/microtest/status.svg)](https://shards.rocks/github/ragmaanir/microtest)

### Version 1.0.0

A very tiny testing framework inspired by minitest/minitest.cr.

## Features

- This framework is opinionated
- It uses power asserts by default. There are no `assert_equals`, `assert_xyz`, just power asserts (except for `assert_raises`)
- It uses the spec syntax for test case structure (`describe`, `test`, `before`, `after`). Reasons: No test-case name-clashes when using describe. Not forgetting to call super in setup/teardown methods.
- No nesting of describe blocks. IMO nesting of those blocks is an anti-pattern.
- No let-definitions. Only before / after hooks. Use local variables mostly.
- Tests have to be started explicitly by `Microtest.run!`, no at-exit hook.

## Installation


Add this to your application's `shard.yml`:

```yaml
dependencies:
  microtest:
    github: ragmaanir/microtest
```


## Usage


```crystal
describe MyLib::WaterPump do
  test "that it pumps water" do
    p = MyLib::WaterPump.new("main")
    p.enable
    p.start

    assert(p.pumps_water?)
  end

  test "that it pumps with a certain speed" do
    p = MyLib::WaterPump.new("main", speed: 100)
    p.enable
    p.start

    assert(p.pump_speed > 50)
  end

  test "this one is pending since it got no body"

  test "only run this focused test", :focus do
  end

  test! "and this one too since it is focused also" do
  end
end

```

## Power Assert Output

```crystal
describe AssertionFailure do
  test "assertion failure" do
    a = 5
    b = "aaaaaa"
    assert "a" * a == b
  end
end

```

Generates:

![Assertion Failure](assets/assertion_failure.png?raw=true)

### Microtest Test Output (default reporter)
![Default](assets/spec.png?raw=true)

## Reporters

```crystal
describe First do
  test "success" do
  end

  test "skip this"
end

describe Second do
  def raise_an_error
    raise "Oh, this is wrong"
  end

  test "first failure" do
    a = 5
    b = 7
    assert a == b * 2
  end

  test "error" do
    raise_an_error
  end
end

```

### Progress Reporter
![Progress Reporter](assets/progress_reporter.png?raw=true)

### Description Reporter
![Description Reporter](assets/description_reporter.png?raw=true)

### When focus active

```crystal
describe Focus do
  test "not focused" do
  end

  test! "focused" do
  end

  test "focused too", :focus do
  end
end

```

![Focus](assets/focus.png?raw=true)

## Development

I am using guardian to run the tests on each change. Also the guardian task uses the computer voice to report build/test failure/success. 
Run `build.cr` to run tests and generate `README.md` from `README.md.template` and generate the images of the test outputs (using an alpine docker image).

{'fraction_non_alphanumeric': 0.11056302092192549, 'fraction_numerical': 0.004082326926348018, 'mean_word_length': 3.772727272727273, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2385180', 'n_tokens_mistral': 2014, 'n_tokens_neox': 1860, 'n_words': 661}