dredd_hooks 0.0.1 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +38 -0
- data/LICENSE.txt +3 -3
- data/README.md +100 -26
- data/Rakefile +31 -0
- data/bin/dredd-hooks-ruby +3 -13
- data/doc/README.md +26 -0
- data/features/execution_order.feature +9 -8
- data/features/failing_transaction.feature +1 -0
- data/features/hook_handlers.feature +1 -0
- data/features/multiple_hookfiles.feature +4 -1
- data/features/support/env.rb +2 -5
- data/lib/dredd_hooks.rb +4 -5
- data/lib/dredd_hooks/cli.rb +18 -0
- data/lib/dredd_hooks/definitions.rb +30 -0
- data/lib/dredd_hooks/errors.rb +15 -0
- data/lib/dredd_hooks/file_loader.rb +12 -10
- data/lib/dredd_hooks/methods.rb +43 -37
- data/lib/dredd_hooks/runner.rb +113 -56
- data/lib/dredd_hooks/server.rb +53 -63
- data/lib/dredd_hooks/server/buffer.rb +49 -0
- data/lib/dredd_hooks/server/events_handler.rb +33 -0
- data/lib/dredd_hooks/version.rb +1 -1
- data/spec/integration/definitions_consistency_spec.rb +38 -0
- data/spec/lib/dredd_hooks/methods_spec.rb +62 -0
- data/spec/lib/dredd_hooks/runner_spec.rb +41 -0
- data/spec/lib/dredd_hooks/server/buffer_spec.rb +58 -0
- data/spec/lib/dredd_hooks/server/events_handler_spec.rb +50 -0
- data/spec/spec_helper.rb +35 -0
- metadata +41 -25
- data/.gitignore +0 -15
- data/.travis.yml +0 -9
- data/dredd_hooks.gemspec +0 -25
- data/features/tcp_server.feature +0 -66
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0a973e6c81a178f196919b8b84438a95ba0b7b2d
|
4
|
+
data.tar.gz: 448ecde2a65cedf46e9ae08a6233080be172a9b2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2c655cdc6b3b4c974ec79588ce426f5f8e13c65371668712d3516aa3ff6d4730d368cd3465defd56740230ba1fbd0b3519922f3562a264b7a7f7a48f003d4546
|
7
|
+
data.tar.gz: c2bd886fad87c7c805687890ee301349a23de809a869f081a17d2dce6fada88efb0076597a933360bef39ca010fa118dfc1af036c73c4a8a2efbeed42e49e2f3
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# Change Log
|
2
|
+
|
3
|
+
All notable changes to this project will be documented in this file.
|
4
|
+
This project adheres to [Semantic Versioning](http://semver.org/).
|
5
|
+
|
6
|
+
## [0.1.0] - 2016-08-06
|
7
|
+
|
8
|
+
### Added
|
9
|
+
|
10
|
+
- This change log : )
|
11
|
+
- Possibility to use DreddHooks::Server as a library (see DreddHooks::CLI for an example)
|
12
|
+
|
13
|
+
### Changed
|
14
|
+
|
15
|
+
- Started using the Semantic Versioning convention
|
16
|
+
|
17
|
+
### Fixed
|
18
|
+
|
19
|
+
- The test suite can be used locally (it is a workaround only)
|
20
|
+
|
21
|
+
## 0.0.1 - 2015-07-07
|
22
|
+
|
23
|
+
### Added
|
24
|
+
|
25
|
+
- Ability to write Dredd hooks in Ruby
|
26
|
+
|
27
|
+
## Previously
|
28
|
+
|
29
|
+
The original [proof of concept][poc] was written by @netmilk.
|
30
|
+
|
31
|
+
|
32
|
+
[0.1.0]: https://github.com/apiaryio/dredd-hooks-ruby/compare/v0.0.1...v0.1.0
|
33
|
+
[poc]: https://github.com/gonzalo-bulnes/dredd-rack/issues/7#issue-70936733
|
34
|
+
|
35
|
+
## Inspiration
|
36
|
+
|
37
|
+
See http://keepachangelog.com and take part of the discussion!
|
38
|
+
|
data/LICENSE.txt
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
The MIT License
|
2
|
+
Copyright (c) 2015, 2016 Adam Kliment
|
3
|
+
Copyright (c) 2016 Gonzalo Bulnes Guilpain
|
4
4
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining
|
6
6
|
a copy of this software and associated documentation files (the
|
data/README.md
CHANGED
@@ -1,31 +1,38 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
Ruby Hooks Handler for Dredd API Testing Framework
|
2
|
+
==================================================
|
3
3
|
|
4
4
|
[](https://travis-ci.org/apiaryio/dredd-hooks-ruby)
|
5
|
+
[](https://gemnasium.com/github.com/apiaryio/dredd-hooks-ruby)
|
6
|
+
[](https://codeclimate.com/github/apiaryio/dredd-hooks-ruby)
|
7
|
+
[](http://inch-ci.org/github/apiaryio/dredd-hooks-ruby)
|
5
8
|
|
6
|
-
Test your
|
7
|
-
|
8
|
-
## Installation
|
9
|
+
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!
|
9
10
|
|
10
|
-
|
11
|
+
> **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! : )
|
11
12
|
|
12
|
-
|
13
|
-
gem 'dredd_worker'
|
14
|
-
```
|
13
|
+
[issues]: https://github.com/apiaryio/dredd-hooks-ruby/issues
|
15
14
|
|
16
|
-
|
15
|
+
Installation
|
16
|
+
------------
|
17
17
|
|
18
|
-
|
18
|
+
Add the gem to your `Gemfile`:
|
19
19
|
|
20
|
-
|
20
|
+
```ruby
|
21
|
+
# Gemfile
|
21
22
|
|
22
|
-
|
23
|
+
gem 'dredd_hooks', '0.1.0' # see semver.org
|
24
|
+
```
|
23
25
|
|
24
|
-
|
26
|
+
Usage
|
27
|
+
-----
|
25
28
|
|
26
|
-
|
29
|
+
Create a hook file (the file name is arbitrary):
|
27
30
|
|
28
31
|
```ruby
|
32
|
+
# ./hooks.rb
|
33
|
+
|
34
|
+
require 'dredd_hooks/methods'
|
35
|
+
|
29
36
|
include DreddHooks::Methods
|
30
37
|
|
31
38
|
before "Machines > Machines collection > Get Machines" do |transaction|
|
@@ -33,24 +40,91 @@ before "Machines > Machines collection > Get Machines" do |transaction|
|
|
33
40
|
end
|
34
41
|
```
|
35
42
|
|
36
|
-
|
43
|
+
Run it with Dredd:
|
37
44
|
|
45
|
+
```bash
|
46
|
+
# note that the hooks file was named ./hooks.rb
|
47
|
+
dredd apiary.apib localhost:3000 --language ruby --hookfiles ./hooks.rb
|
38
48
|
```
|
39
|
-
|
49
|
+
|
50
|
+
Documentation
|
51
|
+
-------------
|
52
|
+
|
53
|
+
### API
|
54
|
+
|
55
|
+
The `DreddHooks::Methods` module provides the following methods to be used with [transaction names][doc-names]:
|
56
|
+
|
57
|
+
- `before`
|
58
|
+
- `after`
|
59
|
+
- `before_validation`
|
60
|
+
|
61
|
+
And these ones to be used without them:
|
62
|
+
|
63
|
+
- `before_all`
|
64
|
+
- `after_all`
|
65
|
+
- `before_each`
|
66
|
+
- `after_each`
|
67
|
+
- `before_each_validation`
|
68
|
+
|
69
|
+
See also the official [Hooks documentation][doc-hooks].
|
70
|
+
|
71
|
+
[doc-names]: http://dredd.readthedocs.org/en/latest/hooks/#getting-transaction-names
|
72
|
+
[doc-hooks]: https://dredd.readthedocs.org/en/latest/hooks
|
73
|
+
|
74
|
+
Change log
|
75
|
+
----------
|
76
|
+
|
77
|
+
Releases are commented to provide a [brief change log][releases], details can be found in the [`CHANGELOG`][changelog] file.
|
78
|
+
|
79
|
+
[releases]: https://github.com/gonzalo-bulnes/dredd-hooks-ruby/releases
|
80
|
+
[changelog]: ./CHANGELOG.md
|
81
|
+
|
82
|
+
Development
|
83
|
+
-----------
|
84
|
+
|
85
|
+
### Testing
|
86
|
+
|
87
|
+
```bash
|
88
|
+
# Run the test suite
|
89
|
+
rake
|
40
90
|
```
|
41
91
|
|
42
|
-
|
92
|
+
A few [Cucumber][cucumber] features provide an end-to-end test harness, and a set of [RSpec][rspec] specs provide both a more granular documentation and a unit test harness.
|
93
|
+
|
94
|
+
RSpec [tags][tags] are used to categorize the spec examples.
|
95
|
+
|
96
|
+
Spec examples that are tagged as `public` describe aspects of the gem public API, and MAY be considered as its documentation.
|
43
97
|
|
44
|
-
|
98
|
+
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.
|
45
99
|
|
46
|
-
|
100
|
+
Run `rake spec:public` to print the gem public documentation.
|
47
101
|
|
48
|
-
|
102
|
+
[cucumber]: https://github.com/cucumber/cucumber-rails
|
103
|
+
[rspec]: https://www.relishapp.com/rspec
|
104
|
+
[tags]: https://www.relishapp.com/rspec/rspec-core/v/3-4/docs/command-line/tag-option
|
105
|
+
[travis]: https://travis-ci.org/gonzalo-bulnes/simple_token_authentication/builds
|
49
106
|
|
50
|
-
|
107
|
+
### Maintenance
|
108
|
+
|
109
|
+
Extending the DSL to support new hooks is meant to be easy, see the [maintenance documentation][doc-maintenance] for details. : )
|
110
|
+
|
111
|
+
[doc-maintenance]: ./doc/README.md
|
112
|
+
|
113
|
+
> Refactored with [love, internet style](https://www.youtube.com/watch?v=Xe1TZaElTAs).
|
114
|
+
|
115
|
+
Contributing
|
116
|
+
------------
|
51
117
|
|
52
118
|
1. Fork it
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
119
|
+
1. Create your feature branch (`git checkout -b my-new-feature`)
|
120
|
+
1. Commit your changes (`git commit -am 'Add some feature'`)
|
121
|
+
1. Push to the branch (`git push origin my-new-feature`)
|
122
|
+
1. Create a new Pull Request
|
123
|
+
|
124
|
+
License
|
125
|
+
-------
|
126
|
+
|
127
|
+
See [`LICENSE`][license].
|
128
|
+
|
129
|
+
[license]: ./LICENSE.txt
|
130
|
+
|
data/Rakefile
CHANGED
@@ -1,2 +1,33 @@
|
|
1
1
|
require "bundler/gem_tasks"
|
2
|
+
require "cucumber/rake/task"
|
3
|
+
|
4
|
+
Cucumber::Rake::Task.new
|
5
|
+
|
6
|
+
begin
|
7
|
+
require 'rspec/core/rake_task'
|
8
|
+
|
9
|
+
desc 'Provide private interfaces documentation'
|
10
|
+
RSpec::Core::RakeTask.new(:spec)
|
11
|
+
|
12
|
+
namespace :spec do
|
13
|
+
desc 'Provide public interfaces documentation'
|
14
|
+
RSpec::Core::RakeTask.new(:public) do |t|
|
15
|
+
t.rspec_opts = "--tag public"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
namespace :spec do
|
20
|
+
desc 'Provide private interfaces documentation for development purpose'
|
21
|
+
RSpec::Core::RakeTask.new(:development) do |t|
|
22
|
+
t.rspec_opts = "--tag protected --tag private"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
rescue LoadError
|
26
|
+
desc 'RSpec rake task not available'
|
27
|
+
task :spec do
|
28
|
+
abort 'RSpec rake task is not available. Be sure to install rspec-core as a gem or plugin'
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
task default: ['spec:public', 'spec:development', :cucumber]
|
2
33
|
|
data/bin/dredd-hooks-ruby
CHANGED
@@ -1,16 +1,6 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
$LOAD_PATH.push File.join(File.dirname(__FILE__), "/../lib" )
|
2
3
|
|
3
|
-
require 'dredd_hooks'
|
4
|
+
require 'dredd_hooks/cli'
|
4
5
|
|
5
|
-
|
6
|
-
# http://stackoverflow.com/questions/23001033/how-to-live-stream-output-from-ruby-script-using-child-process-spawn
|
7
|
-
$stdout.sync = true
|
8
|
-
|
9
|
-
# Load all files given on the command-line
|
10
|
-
DreddHooks::FileLoader.load ARGV
|
11
|
-
|
12
|
-
# Run the server
|
13
|
-
|
14
|
-
puts 'Starting Ruby Dredd Hooks Worker'
|
15
|
-
server = DreddHooks::Server.new
|
16
|
-
server.run
|
6
|
+
DreddHooks::CLI.start(ARGV)
|
data/doc/README.md
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
How to Add New Hooks
|
2
|
+
====================
|
3
|
+
|
4
|
+
Dredd does support new hooks? It's time to extend the Ruby DSL!
|
5
|
+
|
6
|
+
In order to enable your new hook:
|
7
|
+
|
8
|
+
1. Determine if the hook is specific to a transaction or applies to all of them
|
9
|
+
1. Add the _registration_ and _run_ method to the [runner spec][runner-spec]
|
10
|
+
1. Add the DSL method to the [DSL spec][methods-spec]
|
11
|
+
1. Add the usage example to the [**Execution order** feature][feature]
|
12
|
+
1. Run the entire test suite and watch the tests fail (start worrying if they don't!)
|
13
|
+
1. Add the hook name to the corresponding list in the [definitions file][def]
|
14
|
+
1. Add the corresponding Dredd **event** to the [events definition][def] (be careful, the hooks order does matter!)
|
15
|
+
1. Run the test suite and watch it pass : )
|
16
|
+
|
17
|
+
Finally, bump the [_minor_][semver] version number, update the `README`, the `CHANGELOG` and do anything you need to do in order to release!
|
18
|
+
|
19
|
+
[def]: ../lib/dredd_hooks/definitions.rb
|
20
|
+
[events-handler]: ../lib/dredd_hooks/server/events_handler.rb
|
21
|
+
|
22
|
+
[runner-spec]: ../spec/lib/dredd_hooks/runner_spec.rb
|
23
|
+
[methods-spec]: ../spec/lib/dredd_hooks/methods_spec.rb
|
24
|
+
[feature]: ../features/execution_order.feature
|
25
|
+
[semver]: http://semver.org
|
26
|
+
|
@@ -23,47 +23,48 @@ Feature: Execution order
|
|
23
23
|
Scenario:
|
24
24
|
Given a file named "hookfile.rb" with:
|
25
25
|
"""
|
26
|
+
require 'dredd_hooks/methods'
|
26
27
|
include DreddHooks::Methods
|
27
28
|
|
28
29
|
key = 'hooks_modifications'
|
29
30
|
|
30
31
|
before("/message > GET") do |transaction|
|
31
|
-
transaction[key]
|
32
|
+
transaction[key] ||= []
|
32
33
|
transaction[key].push "before modification"
|
33
34
|
end
|
34
35
|
|
35
36
|
after("/message > GET") do |transaction|
|
36
|
-
transaction[key]
|
37
|
+
transaction[key] ||= []
|
37
38
|
transaction[key].push "after modification"
|
38
39
|
end
|
39
40
|
|
40
41
|
before_validation("/message > GET") do |transaction|
|
41
|
-
transaction[key]
|
42
|
+
transaction[key] ||= []
|
42
43
|
transaction[key].push "before validation modification"
|
43
44
|
end
|
44
45
|
|
45
46
|
before_all do |transaction|
|
46
|
-
transaction[0][key]
|
47
|
+
transaction[0][key] ||= []
|
47
48
|
transaction[0][key].push "before all modification"
|
48
49
|
end
|
49
50
|
|
50
51
|
after_all do |transaction|
|
51
|
-
transaction[0][key]
|
52
|
+
transaction[0][key] ||= []
|
52
53
|
transaction[0][key].push "after all modification"
|
53
54
|
end
|
54
55
|
|
55
56
|
before_each do |transaction|
|
56
|
-
transaction[key]
|
57
|
+
transaction[key] ||= []
|
57
58
|
transaction[key].push "before each modification"
|
58
59
|
end
|
59
60
|
|
60
61
|
before_each_validation do |transaction|
|
61
|
-
transaction[key]
|
62
|
+
transaction[key] ||= []
|
62
63
|
transaction[key].push "before each validation modification"
|
63
64
|
end
|
64
65
|
|
65
66
|
after_each do |transaction|
|
66
|
-
transaction[key]
|
67
|
+
transaction[key] ||= []
|
67
68
|
transaction[key].push "after each modification"
|
68
69
|
end
|
69
70
|
|
@@ -23,6 +23,7 @@ Feature: Multiple hookfiles with a glob
|
|
23
23
|
Scenario:
|
24
24
|
Given a file named "hookfile1.rb" with:
|
25
25
|
"""
|
26
|
+
require 'dredd_hooks/methods'
|
26
27
|
include DreddHooks::Methods
|
27
28
|
before("/message > GET") do |transaction|
|
28
29
|
puts "It's me, File1"
|
@@ -30,6 +31,7 @@ Feature: Multiple hookfiles with a glob
|
|
30
31
|
"""
|
31
32
|
And a file named "hookfile2.rb" with:
|
32
33
|
"""
|
34
|
+
require 'dredd_hooks/methods'
|
33
35
|
include DreddHooks::Methods
|
34
36
|
before("/message > GET") do |transaction|
|
35
37
|
puts "It's me, File2"
|
@@ -37,6 +39,7 @@ Feature: Multiple hookfiles with a glob
|
|
37
39
|
"""
|
38
40
|
And a file named "hookfile_to_be_globed.rb" with:
|
39
41
|
"""
|
42
|
+
require 'dredd_hooks/methods'
|
40
43
|
include DreddHooks::Methods
|
41
44
|
before("/message > GET") do |transaction|
|
42
45
|
puts "It's me, File3"
|
@@ -55,4 +58,4 @@ Feature: Multiple hookfiles with a glob
|
|
55
58
|
And the output should contain:
|
56
59
|
"""
|
57
60
|
It's me, File3
|
58
|
-
"""
|
61
|
+
"""
|
data/features/support/env.rb
CHANGED
@@ -4,9 +4,6 @@ require "sinatra/base"
|
|
4
4
|
Before do
|
5
5
|
puts "Killing server..."
|
6
6
|
system "for i in `ps axu | grep 'server.rb' | grep ruby | awk '{print $2}'`; do kill -9 $i; done > /dev/null 2>&1"
|
7
|
-
puts "Killing handler..."
|
8
|
-
system "for i in `ps axu | grep 'dredd-hooks' | grep ruby | awk '{print $2}'`; do kill -9 $i; done > /dev/null 2>&1"
|
9
|
-
sleep 3
|
10
7
|
|
11
|
-
@aruba_timeout_seconds =
|
12
|
-
end
|
8
|
+
@aruba_timeout_seconds = 20
|
9
|
+
end
|
data/lib/dredd_hooks.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
|
-
require
|
1
|
+
require 'dredd_hooks/file_loader'
|
2
|
+
require 'dredd_hooks/server'
|
3
|
+
|
4
|
+
module DreddHooks; end
|
2
5
|
|
3
|
-
require File.join(File.dirname(__FILE__), './dredd_hooks/methods.rb')
|
4
|
-
require File.join(File.dirname(__FILE__), './dredd_hooks/runner.rb')
|
5
|
-
require File.join(File.dirname(__FILE__), './dredd_hooks/file_loader.rb')
|
6
|
-
require File.join(File.dirname(__FILE__), './dredd_hooks/server.rb')
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'dredd_hooks'
|
2
|
+
|
3
|
+
module DreddHooks
|
4
|
+
class CLI
|
5
|
+
|
6
|
+
def self.start(error=STDERR, out=STDOUT, files)
|
7
|
+
|
8
|
+
# Load all files given on the command-line
|
9
|
+
DreddHooks::FileLoader.load(files)
|
10
|
+
|
11
|
+
# Run the server
|
12
|
+
out.puts 'Starting Ruby Dredd Hooks Worker...'
|
13
|
+
server = DreddHooks::Server.new(error, out)
|
14
|
+
server.run
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|