https://github.com/apiaryio/dredd-hooks-ruby
Ruby Hooks Worker for Dredd API Testing Framework
https://github.com/apiaryio/dredd-hooks-ruby
dredd dredd-hooks ruby sjs-team
Last synced: 10 months ago
JSON representation
Ruby Hooks Worker for Dredd API Testing Framework
- Host: GitHub
- URL: https://github.com/apiaryio/dredd-hooks-ruby
- Owner: apiaryio
- License: mit
- Archived: true
- Created: 2015-06-29T10:33:42.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2021-07-12T13:49:03.000Z (almost 5 years ago)
- Last Synced: 2025-05-30T00:07:20.279Z (11 months ago)
- Topics: dredd, dredd-hooks, ruby, sjs-team
- Language: Ruby
- Homepage: http://dredd.rtfd.org/en/latest/hooks-ruby/
- Size: 111 KB
- Stars: 15
- Watchers: 15
- Forks: 7
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.txt
Awesome Lists containing this project
README
Ruby Hooks Handler for Dredd API Testing Framework
==================================================
[](http://badge.fury.io/rb/dredd_hooks)
[](https://travis-ci.org/apiaryio/dredd-hooks-ruby)
[](https://codeclimate.com/github/apiaryio/dredd-hooks-ruby)
[](http://inch-ci.org/github/apiaryio/dredd-hooks-ruby)
Test your API with the [Dredd HTTP API testing framework](https://github.com/apiaryio/dredd) and write [hooks](http://dredd.readthedocs.org/en/latest/hooks/) in Ruby!
> **DISCLAIMER**: This is an early version of _dred-hooks-ruby_, please be aware that it will not be stable until **v1.0.0**. At any moment, [feedback][issues] is welcome! : )
[issues]: https://github.com/apiaryio/dredd-hooks-ruby/issues
Installation
------------
Add the gem to your `Gemfile`:
```ruby
# Gemfile
gem 'dredd_hooks', '0.1.2' # see semver.org
```
Usage
-----
Create a hook file (the file name is arbitrary):
```ruby
# ./hooks.rb
require 'dredd_hooks/methods'
include DreddHooks::Methods
before "Machines > Machines collection > Get Machines" do |transaction|
transaction['skip'] = "true"
end
```
Run it with Dredd:
```bash
# note that the hooks file was named ./hooks.rb
dredd apiary.apib localhost:3000 --language ruby --hookfiles ./hooks.rb
```
Documentation
-------------
### API
The `DreddHooks::Methods` module provides the following methods to be used with [transaction names][doc-names]:
- `before`
- `after`
- `before_validation`
And these ones to be used without them:
- `before_all`
- `after_all`
- `before_each`
- `after_each`
- `before_each_validation`
See also the official [Hooks documentation][doc-hooks].
[doc-names]: http://dredd.readthedocs.org/en/latest/hooks/#getting-transaction-names
[doc-hooks]: https://dredd.readthedocs.org/en/latest/hooks
Change log
----------
Releases are commented to provide a [brief change log][releases], details can be found in the [`CHANGELOG`][changelog] file.
[releases]: https://github.com/gonzalo-bulnes/dredd-hooks-ruby/releases
[changelog]: ./CHANGELOG.md
Development
-----------
### Testing
```bash
# Run the test suite
rake
```
A set of [RSpec][rspec] specs provide both a granular documentation and a unit test harness. RSpec [tags][tags] are used to categorize the spec examples.
Spec examples that are tagged as `public` describe aspects of the gem public API, and MAY be considered as its documentation.
The `private` or `protected` specs are written for development purpose only. Because they describe internal behaviour which may change at any moment without notice, they are only executed as a secondary task by the [continuous integration service][travis] and SHOULD be ignored.
Run `rake spec:public` to print the gem public documentation.
#### Behavioral Spec
A few [Cucumber][cucumber] features from the [dredd-hooks-template] provide an end-to-end test harness. The test suite is provided as a [Node.js] package and needs to be installed by `npm`:
```
npm install
```
Then the tests can be ran using the `npm test` command, but for the Ruby paths to be correctly set, an environment variable `BUNDLE_GEMFILE` needs to be set to the path to the `Gemfile`. An example how running the end-to-end tests can look like on macOS:
```
BUNDLE_GEMFILE=$(pwd)/Gemfile npm test
```
[cucumber]: https://github.com/cucumber/cucumber-js/
[rspec]: https://www.relishapp.com/rspec
[tags]: https://www.relishapp.com/rspec/rspec-core/v/3-4/docs/command-line/tag-option
[travis]: https://travis-ci.org/gonzalo-bulnes/simple_token_authentication/builds
[dredd-hooks-template]: https://github.com/apiaryio/dredd-hooks-template/
[Node.js]: https://nodejs.org/en/
### Maintenance
Extending the DSL to support new hooks is meant to be easy, see the [maintenance documentation][doc-maintenance] for details. : )
[doc-maintenance]: ./doc/README.md
> Refactored with [love, internet style](https://www.youtube.com/watch?v=Xe1TZaElTAs).
Contributing
------------
1. Fork it
1. Create your feature branch (`git checkout -b my-new-feature`)
1. Commit your changes (`git commit -am 'Add some feature'`)
1. Update the `CHANGELOG`
1. Push to the branch (`git push origin my-new-feature`)
1. Create a new Pull Request
License
-------
See [`LICENSE`][license].
[license]: ./LICENSE.txt