spec-kemal/README.md

83 lines
1.6 KiB
Markdown
Raw Permalink Normal View History

2016-04-09 14:37:46 +00:00
# spec-kemal
2016-04-09 14:49:51 +00:00
Kemal helpers to Crystal's `spec` for easy testing.
2016-04-09 14:37:46 +00:00
## Installation
2016-04-09 14:49:51 +00:00
Add it to your `shard.yml`.
2016-04-09 14:37:46 +00:00
2016-04-09 14:49:51 +00:00
```yaml
name: your-kemal-app
version: 0.1.0
2016-04-09 14:37:46 +00:00
2016-04-09 14:49:51 +00:00
dependencies:
spec-kemal:
2016-12-10 17:11:12 +00:00
github: kemalcr/spec-kemal
2016-04-09 14:49:51 +00:00
branch: master
kemal:
2016-12-10 17:11:12 +00:00
github: kemalcr/kemal
2016-04-09 14:49:51 +00:00
branch: master
```
2016-04-09 14:37:46 +00:00
## Usage
2016-04-09 14:49:51 +00:00
Just require it before your files in your `spec/spec_helper.cr`
2016-04-09 14:37:46 +00:00
2016-04-09 14:49:51 +00:00
```crystal
require "spec-kemal"
require "../src/your-kemal-app"
```
2016-04-09 14:37:46 +00:00
2016-04-09 14:58:56 +00:00
Your Kemal application
```crystal
# src/your-kemal-app.cr
require "kemal"
get "/" do
"Hello World!"
end
Kemal.run
```
Now you can easily test your `Kemal` application in your `spec`s.
2016-04-09 14:37:46 +00:00
2016-11-04 23:05:09 +00:00
```
KEMAL_ENV=test crystal spec
```
2016-04-09 14:49:51 +00:00
```crystal
# spec/your-kemal-app-spec.cr
2016-04-09 14:37:46 +00:00
2016-04-09 14:49:51 +00:00
describe "Your::Kemal::App" do
2016-04-18 13:51:50 +00:00
2016-04-10 18:03:23 +00:00
# You can use get,post,put,patch,delete to call the corresponding route.
it "renders /" do
2016-04-18 13:51:50 +00:00
get "/"
2016-04-09 14:49:51 +00:00
response.body.should eq "Hello World!"
end
end
```
2016-04-09 14:37:46 +00:00
#### Rescue errors
Errors gets rescued by default which results in the Kemal's exception page is rendered.
This may not always be the desired behaviour, e.g. when a JSON parsing error occurs one might expect `"[]"`
and not Kemal's exception page.
Set `Kemal.config.always_rescue = false` to prevent this behaviour and raise errors instead.
2016-04-09 14:37:46 +00:00
## Contributing
2016-12-10 17:11:12 +00:00
1. Fork it ( https://github.com/kemalcr/spec-kemal/fork )
2016-04-09 14:37:46 +00:00
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
2016-04-09 14:49:51 +00:00
- [sdogruyol](https://github.com/sdogruyol) Sdogruyol - creator, maintainer