shard-spectator/README.md

146 lines
4.6 KiB
Markdown
Raw Normal View History

2018-08-18 21:33:20 +00:00
Spectator
=========
Fully-featured spec-based test framework for Crystal.
Provides more functionality from [RSpec](http://rspec.info/)
than the built-in Crystal [Spec](https://crystal-lang.org/api/latest/Spec.html) utility.
Spectator also provides additional features to make testing easier and more fluent.
2018-08-18 21:33:20 +00:00
Installation
------------
Add this to your application's `shard.yml`:
```yaml
dependencies:
spectator:
gitlab: arctic-fox/spectator
```
Usage
-----
If it doesn't exist already, create a `spec/spec_helper.cr` file.
In it, place the following:
2018-08-18 21:33:20 +00:00
```crystal
require "spectator"
require "../src/*"
```
This will include Spectator and the source code for your shard.
Now you can start writing your specs.
The syntax is the same as what you would expect from modern RSpec.
The "expect" syntax is recommended and the default, however the "should" syntax is also available.
Your specs must be wrapped in a `Spectator.describe` block.
All other blocks inside the top-level block may use `describe` and `context`.
Here's a minimal spec to demonstrate:
```crystal
require "./spec_helper"
Spectator.describe String do
subject { "foo" }
describe "#==" do
context "with the same value" do
let(value) { subject.dup }
it "is true" do
is_expected.to eq(value)
end
end
context "with a different value" do
let(value) { "bar" }
it "is false" do
is_expected.to_not eq(value)
end
end
end
end
2018-08-18 21:33:20 +00:00
```
If you find yourself trying to shoehorn in functionality
or unsure how to write a test, please create an issue for it.
We want to make it as easy as possible to write specs and keep it elegant.
We may come up with a better solution or even introduce a feature to support your needs.
NOTE: Due to the way this shard uses macros,
you may find that some code you would expect to work creates syntax errors.
If you run into this, please create an issue so that we may help you find a solution.
Features
--------
TODO: Document the features and give brief usage examples.
2018-08-18 21:33:20 +00:00
Development
-----------
This shard is under heavy development and is not ready to be used for production.
### Feature Progress
2018-08-30 21:15:01 +00:00
In no particular order, features that have been implemented and are planned:
- [ ] DSL
- [X] `describe` and `context` blocks
2018-09-04 22:59:59 +00:00
- [X] Contextual values with `let`, `let!`, `subject`, `described_class`
2018-09-07 04:12:58 +00:00
- [X] Test multiple and generated values - `given`
2018-09-15 15:59:55 +00:00
- [X] Before and after hooks - `before_each`, `before_all`, `after_each`, `after_all`, `around_each`
2018-09-22 18:35:44 +00:00
- [ ] Other hooks - `on_success`, `on_failure`, `on_error`
2018-08-30 21:15:01 +00:00
- [ ] One-liner syntax
- [ ] Should syntax
- [X] Helper methods and modules
2018-09-13 01:11:36 +00:00
- [ ] Aliasing - custom example group types with preset attributes
- [X] Pending tests - `pending`
2018-09-13 01:11:36 +00:00
- [ ] Shared examples - `behaves_like`, `include_examples`
2018-08-30 21:15:01 +00:00
- [ ] Matchers
- [ ] Equality matchers - `eq`, `be`, `be_a`, `match`
- [ ] Truthy matchers - `be_true`, `be_false`, `be_truthy`, `be_falsey`
- [ ] Comparison matchers - `<`, `<=`, `>`, `>=`, `be_within`
- [ ] Question matchers - `be_nil`, `be_xxx`
- [ ] Exception matchers - `raise_error`
- [ ] Collection matchers - `start_with`, `end_with`, `contain`, `contain_exactly`
- [ ] Change matchers - `change`, `from`, `to`, `by`, `by_at_least`, `by_at_most`
- [ ] Satisfy matcher - `satisfy`
- [ ] Yield matchers - `yield_control`, `times`, `yield_values`
2018-09-13 01:11:36 +00:00
- [ ] Expectation combining with `&` and `|`
2018-08-30 21:15:01 +00:00
- [ ] Runner
- [ ] Fail fast
2018-09-13 01:11:36 +00:00
- [ ] Test filtering - by name, context, and tags
2018-08-30 21:15:01 +00:00
- [ ] Fail on no tests
- [ ] Randomize test order
2018-09-13 01:11:36 +00:00
- [ ] Dry run - for validation and checking formatted output
- [ ] Config block in `spec_helper.cr`
- [ ] Config file - `.rspec`
- [ ] Reporter and formatting
- [ ] RSpec/Crystal Spec default
- [ ] JSON
- [ ] JUnit
### How it Works
This shard makes extensive use of the Crystal macro system to build classes and modules.
Each `describe` and `context` block creates a new module nested in its parent.
The `it` block creates a class derived from an `Example` class.
An instance of the example class is created to run the test.
Each example class includes a context module, which contains all test values and hooks.
2018-08-18 21:33:20 +00:00
Contributing
------------
1. Fork it (<https://gitlab.com/arctic-fox/spectator/fork/new>)
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 Merge Request
Contributors
------------
- [arctic-fox](https://gitlab.com/arctic-fox) Michael Miller - creator, maintainer