|
1 | | -# Cross-Language Test Suite for Dredd Hooks |
| 1 | +# Cross-Language Test Suite for Dredd Hooks Handlers |
2 | 2 |
|
3 | | -[](https://travis-ci.org/apiaryio/dredd-hooks-template) [](https://greenkeeper.io/) |
| 3 | +[](https://travis-ci.org/apiaryio/dredd-hooks-template) |
4 | 4 |
|
5 | | -Language-agnostic BDD test suite for boilerplating implementation of [Dredd][] [hooks][] handler for a new language. It tests the public interface of the hooks handler and ensures it will work as Dredd expects. It's written in [Gherkin][] and ran by [Aruba][]. |
| 5 | +[Dredd](https://dredd.org) is a tool for testing web APIs. It supports [hooks](http://dredd.org/en/latest/hooks/index.html) written in [many languages](http://dredd.org/en/latest/hooks/index.html#supported-languages). To support a particular language, it needs an adapter, so-called hooks handler. This [BDD](https://en.wikipedia.org/wiki/Behavior-driven_development) test suite ensures that the public interface of each hooks handler works as Dredd expects. The test suite is written in [Gherkin](https://github.com/cucumber/cucumber/wiki/Gherkin) and uses [Cucumber](https://github.com/cucumber/cucumber-js) as a test runner. |
6 | 6 |
|
7 | | - [Aruba]: https://github.com/cucumber/aruba |
8 | | - [Gherkin]: https://github.com/cucumber/cucumber/wiki/Gherkin |
9 | | - [Dredd]: https://github.com/apiaryio/dredd |
10 | | - [hooks]: https://dredd.readthedocs.io/en/latest/hooks/ |
| 7 | +To use the test suite, first read the docs about [how to create a new hooks handler](http://dredd.org/en/latest/hooks/new-language.html) for Dredd. Implement your hooks handler and then continue with the following guide. |
11 | 8 |
|
12 | | -## Usage |
13 | | - |
14 | | -### Install the features dependencies |
| 9 | +## Installation |
15 | 10 |
|
16 | | -```bash |
17 | | -npm install -g dredd |
18 | | -git clone https://github.com/apiaryio/dredd-hooks-template.git |
19 | | -cd dredd-hooks-template |
20 | | -bundle install |
21 | | -``` |
| 11 | +1. Make sure you have [Node.js](https://nodejs.org/) (ideally version 10 or higher) and [npm](https://www.npmjs.com/package/npm) available. |
| 12 | +1. Create a `package.json` file in the root of your project. This is where your JavaScript dependencies are going to be specified: |
22 | 13 |
|
23 | | -### Enable the features for your language |
| 14 | + ```json |
| 15 | + { |
| 16 | + "scripts": { "test": "dredd-hooks-template test" }, |
| 17 | + "private": true |
| 18 | + } |
| 19 | + ``` |
24 | 20 |
|
25 | | -1. Open the feature files in `./features/*.feature` |
26 | | -1. In all of them, replace: |
27 | | - - `{{mylanguage}}` by the hooks handler command for you language |
28 | | - - `{{myextension}}` by the extension for your language |
29 | | -1. Implement the code examples in your language |
30 | | -1. Run the test suite: `bundle exec cucumber` |
| 21 | +1. Run `npm install dredd-hooks-template --save-dev` to install and declare this test suite as your development dependency. |
| 22 | +1. Run `npx dredd-hooks-template init` to get a copy of the test suite in the `./features` directory. |
| 23 | +1. Open the feature files in `./features/*.feature` and in all of them |
31 | 24 |
|
32 | | -### Add the features to your project |
| 25 | + - replace `dredd-hooks-{{mylanguage}}` with a path to your hooks handler executable which you want to get tested (e.g. `./bin/dredd_hooks`) |
| 26 | + - replace `{{myextension}}` by the extension of the hooks handler language (e.g. `.py`), |
| 27 | + - uncomment the code blocks and rewrite them to the hooks handler language. |
33 | 28 |
|
34 | | -If the test suite did run as expected, you can now add the features to your project. |
35 | | -To do so, copy to your project: |
| 29 | +Now you have the test suite ready. |
36 | 30 |
|
37 | | -1. the entire `features/` directory |
38 | | -1. the `Gemfile`, `Gemfile.lock` and `.ruby-version` |
| 31 | +## Usage |
39 | 32 |
|
40 | | -Your should now be able to install the features dependencies and run the test suite in your project. |
| 33 | +Every time you run `npx dredd-hooks-template test` (or `npm test`), you should see the test suite running. The end goal is that all the tests pass: |
41 | 34 |
|
42 | | -Finally, make `bundle exec cucumber` part of your test suite and CI (see `.travis.example.yml` if you are using [Travis CI][travis]). |
| 35 | + |
43 | 36 |
|
44 | | - [travis]: https://travis-ci.org |
| 37 | +You should add the `package.json` file to Git. When starting from scratch, you can run `npm install` to install the JavaScript dependencies. |
45 | 38 |
|
46 | | -## Development |
| 39 | +<a name="upgrading"></a> |
47 | 40 |
|
48 | | -The feature files syntax is validated automatically. To perform the validation locally: |
| 41 | +## Upgrading |
49 | 42 |
|
50 | | -```bash |
51 | | -# Install the dependencies |
52 | | -npm install |
| 43 | +[Watch for newer versions](https://github.com/apiaryio/dredd-hooks-template/releases) of the [dredd-hooks-template package](https://www.npmjs.com/package/dredd-hooks-template) and upgrade regularly to keep up with development of Dredd and the test suite itself. To upgrade, run: |
53 | 44 |
|
54 | | -# Run the linter |
55 | | -npm test |
56 | 45 | ``` |
| 46 | +$ npx dredd-hooks-template upgrade |
| 47 | +``` |
| 48 | +
|
| 49 | +It upgrades the package to the latest version and copies the latest feature files to the project's `./features/` directory. It won't overwrite the existing files as the names of the new files get suffixed with version. Then it's up to you to compare the old and new files, spot changes, and update the project's test suite. |
| 50 | +
|
| 51 | +## Reference Implementations |
| 52 | +
|
| 53 | +The [Python hooks](https://github.com/apiaryio/dredd-hooks-python) and the [Ruby hooks](https://github.com/apiaryio/dredd-hooks-ruby) can be used as examples of how to use this cross-language test suite. |
57 | 54 |
|
58 | | -## Examples |
| 55 | +## Keep Tests Running with CI |
59 | 56 |
|
60 | | -The [Dredd Hooks Ruby gem][ruby] and the [Dredd Hooks Python package][python] can be used as references to use this cross-language test suite. |
| 57 | +To make sure the hooks handler will always work correctly with Dredd and the expectations won't get accidentally broken, put the tests into [Travis CI](https://travis-ci.org), which runs the tests for each change on your repository. See existing configuration files for inspiration: |
61 | 58 |
|
62 | | - [ruby]: https://github.com/apiaryio/dredd-hooks-ruby |
63 | | - [python]: https://github.com/apiaryio/dredd-hooks-python |
| 59 | +- Python: [.travis.yml](https://github.com/apiaryio/dredd-hooks-python/blob/master/.travis.yml) |
| 60 | +- Ruby: [.travis.yml](https://github.com/apiaryio/dredd-hooks-ruby/blob/master/.travis.yml) |
0 commit comments