An open API service indexing awesome lists of open source software.

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

Awesome Lists containing this project

README

          

Ruby Hooks Handler for Dredd API Testing Framework
==================================================

[![Gem Version](https://badge.fury.io/rb/dredd_hooks.svg)](http://badge.fury.io/rb/dredd_hooks)
[![Build Status](https://travis-ci.org/apiaryio/dredd-hooks-ruby.svg?branch=master)](https://travis-ci.org/apiaryio/dredd-hooks-ruby)
[![Code Climate](https://codeclimate.com/github/apiaryio/dredd-hooks-ruby/badges/gpa.svg)](https://codeclimate.com/github/apiaryio/dredd-hooks-ruby)
[![Inline Docs](http://inch-ci.org/github/apiaryio/dredd-hooks-ruby.svg?branch=master)](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