dredd-rack 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +75 -24
- data/doc/rake_task.md +119 -0
- data/doc/runner.md +95 -0
- data/lib/dredd/rack/rake_task.rb +33 -17
- data/lib/dredd/rack/runner.rb +19 -4
- data/lib/dredd/rack/version.rb +1 -1
- data/spec/lib/dredd/rack/runner_spec.rb +50 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: df87b935a638c2038e83e801e28641077a711fbe
|
4
|
+
data.tar.gz: 642d5c8ddc31c41e3770b8523b54c35b0ba800ba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 558870fb92e474692d10b01955ec8ff012ad5b461b9ed3605a24d9c0edb154ea9ece9e2c5a165bad76269e81277797fafe6033c7635472f1690d8a37bf65c5f0
|
7
|
+
data.tar.gz: c591fcba3305d303b20fe08052727ad998400ea09795fa4d6fea2d98814b5fbc9e0a9acfb66d360d575c40e3235435bb73b6189f40d6124fd3820bebe1cfb381
|
data/README.md
CHANGED
@@ -1,12 +1,15 @@
|
|
1
1
|
Dredd::Rack
|
2
2
|
===========
|
3
3
|
|
4
|
+
[![Gem Version](https://badge.fury.io/rb/dredd-rack.svg)](http://badge.fury.io/rb/dredd-rack)
|
4
5
|
[![Build Status](https://travis-ci.org/gonzalo-bulnes/dredd-rack.svg?branch=master)](https://travis-ci.org/gonzalo-bulnes/dredd-rack)
|
5
6
|
[![Code Climate](https://codeclimate.com/github/gonzalo-bulnes/dredd-rack.svg)](https://codeclimate.com/github/gonzalo-bulnes/dredd-rack)
|
6
|
-
[![Dredd Reference Version](https://img.shields.io/badge/dredd_reference_version-0.4.
|
7
|
+
[![Dredd Reference Version](https://img.shields.io/badge/dredd_reference_version-0.4.8-brightgreen.svg)](https://github.com/apiaryio/dredd)
|
7
8
|
[![Inline docs](http://inch-ci.org/github/gonzalo-bulnes/dredd-rack.svg?branch=master)](http://inch-ci.org/github/gonzalo-bulnes/dredd-rack)
|
8
9
|
|
9
|
-
|
10
|
+
> **DISCLAIMER**: This is an early version of Dredd::Rack, please be aware that it will not be stable until `v1.0.0`. At any moment, [feedback][issues] is more than welcome! : ) -- [GB][gonzalo-bulnes]
|
11
|
+
|
12
|
+
This gem provides a [Dredd][dredd] runner and a `dredd` rake task to make [API blueprint][blueprint] testing convenient for Rack applications. When verifying blueprints locally, an application server is automatically set up, without need of any manual intervention.
|
10
13
|
|
11
14
|
Besides being convenient, that allows to use the API blueprints as acceptance test suites to practice [BDD][rspec-book] with Dredd and RSpec, for example, while clients developers use [Apiary][apiary] as a mock server.
|
12
15
|
|
@@ -14,6 +17,8 @@ Besides being convenient, that allows to use the API blueprints as acceptance te
|
|
14
17
|
[blueprint]: https://apiblueprint.org/
|
15
18
|
[rspec-book]: https://pragprog.com/book/achbd/the-rspec-book
|
16
19
|
[apiary]: http://apiary.io
|
20
|
+
[issues]: https://github.com/gonzalo-bulnes/dredd-rack/issues
|
21
|
+
[gonzalo-bulnes]: https://github.com/gonzalo-bulnes
|
17
22
|
|
18
23
|
Installation
|
19
24
|
------------
|
@@ -23,71 +28,117 @@ Add the gem to your `Gemfile`:
|
|
23
28
|
```ruby
|
24
29
|
# Gemfile
|
25
30
|
|
26
|
-
gem 'dredd-rack', '~>
|
31
|
+
gem 'dredd-rack', '~> 0.4.0' # see semver.org
|
27
32
|
```
|
28
33
|
|
29
|
-
|
30
|
-
|
34
|
+
Define which application Dredd::Rack must serve automatically:
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
# config/initializers/dredd-rack.rb or app.rb or Rakefile
|
31
38
|
|
32
|
-
|
39
|
+
require 'dredd/rack'
|
33
40
|
|
34
|
-
|
41
|
+
# Allow the automatic setup of a local application server when necessary
|
42
|
+
#
|
43
|
+
# Find the name of your application in its `config.ru` file.
|
44
|
+
Dredd::Rack.app = Example::Application # or Rails.application, Sinatra::Application...
|
45
|
+
```
|
35
46
|
|
47
|
+
Usage
|
48
|
+
-----
|
36
49
|
|
37
|
-
###
|
50
|
+
### Getting started
|
38
51
|
|
39
|
-
|
52
|
+
Define the `dredd` rake task in your `Rakefile`:
|
40
53
|
|
41
54
|
```ruby
|
42
55
|
# Rakefile
|
43
56
|
|
44
57
|
require 'dredd/rack'
|
45
58
|
|
46
|
-
#
|
47
|
-
Dredd::Rack.app Sinatra::Application # or the name of your modular-style app, or Rails app
|
59
|
+
# ...
|
48
60
|
|
49
|
-
#
|
61
|
+
# Define the :dredd task
|
62
|
+
Dredd::Rack::RakeTask.new # run: `dredd doc/*.apib doc/*.apib.md <local or remote URL>`
|
50
63
|
|
51
64
|
# Optionally add the API blueprint verification to the default test suite
|
52
65
|
# task :default => [:spec, :dredd]
|
53
66
|
```
|
54
67
|
|
55
|
-
Run the API blueprint verification
|
68
|
+
Run the API blueprint verification:
|
56
69
|
|
57
70
|
```bash
|
71
|
+
# locally
|
58
72
|
rake dredd
|
59
73
|
|
60
74
|
# or specify a remote server:
|
61
|
-
#API_HOST=http://api.example.com rake
|
75
|
+
#API_HOST=http://api.example.com rake dredd
|
62
76
|
```
|
63
77
|
|
64
|
-
|
65
|
-
-----
|
78
|
+
The `:dredd` rake task requires no further configuration. However, it relies on the following convention: API blueprints must be stored in the `doc` directory with either the `.apib` or the `.apib.md` extension.
|
66
79
|
|
67
|
-
###
|
80
|
+
### Further usage
|
68
81
|
|
69
|
-
|
82
|
+
Of course you can define your own rake tasks with custom runners!
|
83
|
+
|
84
|
+
Each Dredd::Rack runner stores a specific Dredd configuration. In order to manage different runners, you can define multiple rake tasks with custom names or descriptions:
|
70
85
|
|
71
86
|
```ruby
|
72
87
|
# Rakefile
|
73
88
|
|
74
|
-
|
75
|
-
|
76
|
-
# Configure Dredd::Rack to automatically set a server up for your application
|
77
|
-
Dredd::Rack.app Sinatra::Application # or the name of your modular-style app, or Rails app
|
89
|
+
# ...
|
78
90
|
|
79
91
|
namespace :blueprint do
|
80
|
-
|
81
|
-
|
92
|
+
namespace :verify do
|
93
|
+
|
94
|
+
desc 'Verify the whole API compliance with its blueprint'
|
95
|
+
Dredd::Rack::RakeTask.new(:all)
|
96
|
+
|
97
|
+
desc 'Verify the Machines API compliance with its blueprint'
|
98
|
+
Dredd::Rack::RakeTask.new(:machines) do |task|
|
99
|
+
task.runner.configure do |dredd|
|
100
|
+
dredd.only 'Machines > Machines Collection > List all Machines',
|
101
|
+
'Machines > Machine > Retrieve a Machine' # etc.
|
102
|
+
dredd.sorted!.details!
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
# ...
|
107
|
+
end
|
82
108
|
end
|
109
|
+
|
110
|
+
# run with `rake blueprint:verify:all` and `rake blueprint:verify:machines`
|
83
111
|
```
|
84
112
|
|
113
|
+
Both the [rake task documentation][rake-task-doc] and the [runner documentation][runner-doc] contain more examples, and the runner documentation does also contain a comprehensive list of the [configuration methods][conf] that can be used to customize runners. Take a look at them!
|
114
|
+
|
115
|
+
[rake-task-doc]: doc/rake_task.md
|
116
|
+
[runner-doc]: doc/runner.md
|
117
|
+
[conf]: doc/runner.md#configuration-methods-reference
|
118
|
+
|
119
|
+
|
120
|
+
#### Remote API testing
|
121
|
+
|
122
|
+
Configuring a runner for remote API blueprint compliance testing is as easy as setting its **api_endpoint** option (see the [runner documentation][conf]). Please remember that you must ensure that the API is being served at the specified URI when performing remote API blueprint validation.
|
123
|
+
|
124
|
+
Credits
|
125
|
+
-------
|
126
|
+
|
127
|
+
The `Dredd::Rack::RakeTask` is heavily inspired in the [`RSpec::Core::RakeTask`][rspec-core-raketask]. Let the corresponding credits go to the RSpec team.
|
128
|
+
|
129
|
+
[rspec-core-raketask]: https://github.com/rspec/rspec-core/blob/v3.2.1/lib/rspec/core/rake_task.rb
|
130
|
+
|
85
131
|
License
|
86
132
|
-------
|
87
133
|
|
88
134
|
Dredd::Rack provides convenient API blueprint testing to Rack applications.
|
89
135
|
Copyright (C) 2015 Gonzalo Bulnes Guilpain
|
90
136
|
|
137
|
+
Copyright (C) 2012 Chad Humphries, David Chelimsky, Myron Marston
|
138
|
+
Copyright (C) 2009 Chad Humphries, David Chelimsky
|
139
|
+
Copyright (C) 2006 David Chelimsky, The RSpec Development Team
|
140
|
+
Copyright (C) 2005 Steven Baker
|
141
|
+
|
91
142
|
This program is free software: you can redistribute it and/or modify
|
92
143
|
it under the terms of the GNU General Public License as published by
|
93
144
|
the Free Software Foundation, either version 3 of the License, or
|
data/doc/rake_task.md
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
See also: [Dredd::Rack::Runner](runner.md)
|
2
|
+
|
3
|
+
Dredd::Rack::RakeTask
|
4
|
+
=====================
|
5
|
+
|
6
|
+
**Table of Contents**
|
7
|
+
|
8
|
+
1. [Example](#example)
|
9
|
+
1. [Custom name, description](#custom-rake-task-name-description)
|
10
|
+
1. [Custom runner](#custom-rake-task-runner)
|
11
|
+
1. [Fully custom rake tasks](#fully-custom-rake-tasks)
|
12
|
+
|
13
|
+
----
|
14
|
+
|
15
|
+
Example
|
16
|
+
-------
|
17
|
+
|
18
|
+
Use the `dredd` rake task from your `Rakefile`:
|
19
|
+
|
20
|
+
```ruby
|
21
|
+
# Rakefile
|
22
|
+
|
23
|
+
require 'dredd/rack'
|
24
|
+
Dredd::Rack.app = Example::Application
|
25
|
+
|
26
|
+
Dredd::Rack::RakeTask.new
|
27
|
+
# That's all! Dredd::Rack will serve the app automatically,
|
28
|
+
# and the :dredd task is defined.
|
29
|
+
|
30
|
+
# Optionally add the API blueprint verification to the default test suite
|
31
|
+
# task :default => [:spec, :dredd]
|
32
|
+
```
|
33
|
+
|
34
|
+
Run the API blueprint verification:
|
35
|
+
|
36
|
+
```bash
|
37
|
+
# locally
|
38
|
+
rake dredd
|
39
|
+
|
40
|
+
# or specify a remote server:
|
41
|
+
#API_HOST=http://api.example.com rake dredd
|
42
|
+
```
|
43
|
+
|
44
|
+
Custom rake task name, description
|
45
|
+
----------------------------------
|
46
|
+
|
47
|
+
You can define a custom task name or description:
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
# Rakefile
|
51
|
+
|
52
|
+
# ...
|
53
|
+
|
54
|
+
require 'dredd/rack'
|
55
|
+
Dredd::Rack.app = Example::Application
|
56
|
+
|
57
|
+
namespace :blueprint do
|
58
|
+
desc 'Verify the API blueprint accuracy'
|
59
|
+
Dredd::Rack::RakeTask.new(:verify)
|
60
|
+
end
|
61
|
+
|
62
|
+
# run with: `rake blueprint:verify`
|
63
|
+
```
|
64
|
+
|
65
|
+
Custom rake task runner
|
66
|
+
-----------------------
|
67
|
+
|
68
|
+
You can also configure the Dredd::Rack runner:
|
69
|
+
|
70
|
+
```ruby
|
71
|
+
# Rakefile
|
72
|
+
|
73
|
+
# ...
|
74
|
+
|
75
|
+
require 'dredd/rack'
|
76
|
+
Dredd::Rack.app Example::Application
|
77
|
+
|
78
|
+
Dredd::Rack::RakeTask.new(:dredd) do |task|
|
79
|
+
task.runner.configure do |dredd|
|
80
|
+
dredd.paths_to_blueprints 'blueprints/*.md', 'blueprints/*.apib'
|
81
|
+
dredd.level(:silly).no_color!
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
# run with: `rake dredd`
|
86
|
+
```
|
87
|
+
|
88
|
+
Fully custom rake tasks
|
89
|
+
-----------------------
|
90
|
+
|
91
|
+
In fact, you can define as many tasks as you need, with custom names, descriptions or runners:
|
92
|
+
|
93
|
+
```ruby
|
94
|
+
# Rakefile
|
95
|
+
|
96
|
+
require 'dredd/rack'
|
97
|
+
Dredd::Rack.app RobotsFactory::API
|
98
|
+
|
99
|
+
namespace :blueprint do
|
100
|
+
namespace :verify do
|
101
|
+
|
102
|
+
desc 'Verify the whole API compliance with its blueprint'
|
103
|
+
Dredd::Rack::RakeTask.new(:all)
|
104
|
+
|
105
|
+
desc 'Verify the Machines API compliance with its blueprint'
|
106
|
+
Dredd::Rack::RakeTask.new(:machines) do |task|
|
107
|
+
task.runner.configure do |dredd|
|
108
|
+
dredd.only 'Machines > Machines Collection > List all Machines',
|
109
|
+
'Machines > Machine > Retrieve a Machine' # etc.
|
110
|
+
dredd.sorted!.details!
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
# ...
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
# run with `rake blueprint:verify:all` and `rake blueprint:verify:machines`
|
119
|
+
```
|
data/doc/runner.md
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
See also: [Dredd::Rack::RakeTask](rake_task.md)
|
2
|
+
|
3
|
+
Dredd::Rack::Runner
|
4
|
+
===================
|
5
|
+
|
6
|
+
**Table of Contents**
|
7
|
+
|
8
|
+
1. [Example](#example)
|
9
|
+
1. [Runner configuration](#runner-configuration)
|
10
|
+
1. [Configuration methods reference](#configuration-methods-reference)
|
11
|
+
|
12
|
+
----
|
13
|
+
|
14
|
+
Example
|
15
|
+
-------
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
|
19
|
+
# Dredd command to run:
|
20
|
+
# `dredd *.apib *.md <local API endpoint> --level "warning" --no-color`
|
21
|
+
|
22
|
+
dredd = Dredd::Rack::Runner.new do |options|
|
23
|
+
options.paths_to_blueprints '*.apib', '*.md'
|
24
|
+
options.level(:warning).no_color!
|
25
|
+
end
|
26
|
+
|
27
|
+
# run Dredd (a server will be started and stopped automatically)
|
28
|
+
dredd.run
|
29
|
+
```
|
30
|
+
|
31
|
+
Runner configuration
|
32
|
+
--------------------
|
33
|
+
|
34
|
+
Runners can be configured immediately after being created (see example above), or at any moment using the `configure` method:
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
dredd = Dredd::Rack::Runner.new
|
38
|
+
|
39
|
+
dredd.configure do |options|
|
40
|
+
options.api_endpoint 'https://api.example.com'
|
41
|
+
options.details!
|
42
|
+
end
|
43
|
+
```
|
44
|
+
|
45
|
+
Please note that configuration methods can be chained for convenience:
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
dredd.configure { |options| options.level(:info).sorted!.no_color! }
|
49
|
+
```
|
50
|
+
|
51
|
+
Configuration methods reference
|
52
|
+
-------------------------------
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
# See https://github.com/apiaryio/dredd#command-line-options for Dredd commands usage
|
56
|
+
|
57
|
+
dredd = Dredd::Rack::Runner.new do |options|
|
58
|
+
|
59
|
+
options.api_endpoint 'https://api.example.com' # allows to validate remote API
|
60
|
+
|
61
|
+
options.hookfiles 'doc/hooks/*_hooks.coffee'
|
62
|
+
|
63
|
+
options.only 'Machines > Machines Collection > List all Machines',
|
64
|
+
'Machines > Machine > Retrieve a Machine'
|
65
|
+
|
66
|
+
options.reporter(:markdown)
|
67
|
+
options.reporter(:html).output('doc/report.html')
|
68
|
+
|
69
|
+
options.header 'X-User-Email: alice@example.com'
|
70
|
+
options.header 'X-User-Token: 1G8_s7P-V-4MGojaKD7a'
|
71
|
+
|
72
|
+
options.user 'username:password'
|
73
|
+
|
74
|
+
options.level(:info)
|
75
|
+
|
76
|
+
options.path('doc/*.md').path('doc/*.apib.md')
|
77
|
+
|
78
|
+
options.method('POST').method('PUT')
|
79
|
+
|
80
|
+
options.dry_run! # no_dry_run!
|
81
|
+
options.names! # no_names!
|
82
|
+
options.sorted! # no_sorted!
|
83
|
+
options.inline_errors! # no_inline_errors!
|
84
|
+
options.details! # no_details!
|
85
|
+
options.color! # no_color!
|
86
|
+
options.timestamp! # no_timestamp!
|
87
|
+
options.silent! # no_silent!
|
88
|
+
|
89
|
+
options.help
|
90
|
+
options.version
|
91
|
+
end
|
92
|
+
|
93
|
+
# run Dredd (you don't have to worry about the server unless the API is remote)
|
94
|
+
dredd.run
|
95
|
+
```
|
data/lib/dredd/rack/rake_task.rb
CHANGED
@@ -3,6 +3,21 @@ require 'rainbow'
|
|
3
3
|
require 'rake'
|
4
4
|
require 'rake/tasklib'
|
5
5
|
|
6
|
+
# This class is heavily inspired in the RSpec::Core::RakeTask, which
|
7
|
+
# was published under the MIT license by:
|
8
|
+
#
|
9
|
+
# Copyright (C) 2009 Chad Humphries, David Chelimsky
|
10
|
+
# Copyright (C) 2006 David Chelimsky, The RSpec Development Team
|
11
|
+
# Copyright (C) 2005 Steven Baker
|
12
|
+
#
|
13
|
+
# See https://github.com/rspec/rspec-core/blob/v3.2.2/lib/rspec/core/rake_task.rb
|
14
|
+
#
|
15
|
+
# Modifications are part of Dredd::Rack, published under the GNU GPLv3 ot later by:
|
16
|
+
#
|
17
|
+
# Copyright (C) 2015 Gonzalo Bulnes Guilpain
|
18
|
+
#
|
19
|
+
# See https://github.com/gonzalo-bulnes/dredd-rack/blob/v0.3.0/lib/dredd/rack/rake_task.rb
|
20
|
+
|
6
21
|
module Dredd
|
7
22
|
module Rack
|
8
23
|
|
@@ -32,32 +47,18 @@ module Dredd
|
|
32
47
|
attr_reader :runner
|
33
48
|
|
34
49
|
# Define a task with a custom name, arguments and description
|
35
|
-
def initialize(*args)
|
50
|
+
def initialize(*args, &task_block)
|
36
51
|
@name = args.shift || :dredd
|
37
52
|
@description = 'Run Dredd::Rack API blueprint verification'
|
38
53
|
@runner = Dredd::Rack::Runner.new(ENV['API_HOST'])
|
39
54
|
|
40
55
|
desc description unless ::Rake.application.last_comment
|
41
|
-
task name, args do
|
56
|
+
task name, *args do |task_args|
|
57
|
+
task_block.call(*[self, task_args].slice(0, task_block.arity)) if task_block
|
42
58
|
run_task(runner)
|
43
59
|
end
|
44
60
|
end
|
45
61
|
|
46
|
-
def run_task(runner)
|
47
|
-
abort dredd_not_available_message unless dredd_available?
|
48
|
-
|
49
|
-
puts starting_message
|
50
|
-
|
51
|
-
puts command_message(runner)
|
52
|
-
|
53
|
-
success = runner.run
|
54
|
-
exit_status = $?.exitstatus
|
55
|
-
|
56
|
-
puts connection_error_message(runner) unless success if dredd_connection_error?(exit_status)
|
57
|
-
|
58
|
-
abort unless exit_status == 0
|
59
|
-
end
|
60
|
-
|
61
62
|
private
|
62
63
|
|
63
64
|
def dredd_available?
|
@@ -100,6 +101,21 @@ module Dredd
|
|
100
101
|
eos
|
101
102
|
end
|
102
103
|
|
104
|
+
def run_task(runner)
|
105
|
+
abort dredd_not_available_message unless dredd_available?
|
106
|
+
|
107
|
+
puts starting_message
|
108
|
+
|
109
|
+
puts command_message(runner)
|
110
|
+
|
111
|
+
success = runner.run
|
112
|
+
exit_status = $?.exitstatus
|
113
|
+
|
114
|
+
puts connection_error_message(runner) unless success if dredd_connection_error?(exit_status)
|
115
|
+
|
116
|
+
abort unless exit_status == 0
|
117
|
+
end
|
118
|
+
|
103
119
|
def starting_message
|
104
120
|
<<-eos.gsub /^( |\t)+/, ""
|
105
121
|
|
data/lib/dredd/rack/runner.rb
CHANGED
@@ -38,9 +38,6 @@ module Dredd
|
|
38
38
|
# Store the Dredd command line options
|
39
39
|
attr_accessor :command_parts
|
40
40
|
|
41
|
-
# Return the API endpoint
|
42
|
-
attr_reader :api_endpoint
|
43
|
-
|
44
41
|
# Initialize a runner instance
|
45
42
|
#
|
46
43
|
# The API endpoint can be local or remote.
|
@@ -56,18 +53,36 @@ module Dredd
|
|
56
53
|
yield self if block_given?
|
57
54
|
end
|
58
55
|
|
56
|
+
# Set or return the runner API endpoint
|
57
|
+
#
|
58
|
+
# Use with no arguments to read the runner API endpoint,
|
59
|
+
# provide an API endpoint to set it.
|
60
|
+
#
|
61
|
+
# api_endpoint - String URL of the API endpoint to validate
|
62
|
+
#
|
63
|
+
# Returns the String URL of the runner API endpoint.
|
64
|
+
def api_endpoint(api_endpoint=nil)
|
65
|
+
@api_endpoint = api_endpoint unless api_endpoint.nil?
|
66
|
+
@api_endpoint
|
67
|
+
end
|
68
|
+
|
59
69
|
# Return the Dredd command line
|
60
70
|
def command
|
61
71
|
([@dredd_command, @paths_to_blueprints, @api_endpoint] + @command_parts).join(' ')
|
62
72
|
end
|
63
73
|
|
74
|
+
# Configure the runner instance
|
75
|
+
def configure
|
76
|
+
yield self if block_given?
|
77
|
+
end
|
78
|
+
|
64
79
|
# Define custom paths to blueprints
|
65
80
|
#
|
66
81
|
# paths_to_blueprints - as many Strings as paths where blueprints are located
|
67
82
|
#
|
68
83
|
# Returns self.
|
69
84
|
def paths_to_blueprints(*paths_to_blueprints)
|
70
|
-
raise ArgumentError, 'invalid path to blueprints' if paths_to_blueprints == ['']
|
85
|
+
raise ArgumentError, 'invalid path to blueprints' if paths_to_blueprints == [''] || paths_to_blueprints.empty?
|
71
86
|
|
72
87
|
@paths_to_blueprints = paths_to_blueprints.join(' ')
|
73
88
|
self
|
data/lib/dredd/rack/version.rb
CHANGED
@@ -18,6 +18,10 @@ describe Dredd::Rack::Runner do
|
|
18
18
|
expect(subject).to respond_to :command_parts=
|
19
19
|
end
|
20
20
|
|
21
|
+
it 'responds to :configure', public: true do
|
22
|
+
expect(subject).to respond_to :configure
|
23
|
+
end
|
24
|
+
|
21
25
|
it 'respond_to :paths_to_blueprints', public: true do
|
22
26
|
expect(subject).to respond_to :paths_to_blueprints
|
23
27
|
end
|
@@ -48,6 +52,26 @@ describe Dredd::Rack::Runner do
|
|
48
52
|
end
|
49
53
|
end
|
50
54
|
|
55
|
+
describe '#api_endpoint', public: true do
|
56
|
+
|
57
|
+
let(:subject) { Dredd::Rack::Runner.new('https://example.com') }
|
58
|
+
|
59
|
+
it 'returns the runner api_endpoint' do
|
60
|
+
expect(subject.api_endpoint).to eq 'https://example.com'
|
61
|
+
end
|
62
|
+
|
63
|
+
context 'when given an argument' do
|
64
|
+
|
65
|
+
it 'returns the runner api_endpoint' do
|
66
|
+
expect(subject.api_endpoint('https://another.example.com')).to eq 'https://another.example.com'
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'sets the runner api_endpoint' do
|
70
|
+
expect(subject.api_endpoint('https://another.example.com')).to eq 'https://another.example.com'
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
51
75
|
describe '#command_valid?', private: true do
|
52
76
|
|
53
77
|
context 'when the generated command has less than two arguments' do
|
@@ -59,6 +83,24 @@ describe Dredd::Rack::Runner do
|
|
59
83
|
end
|
60
84
|
end
|
61
85
|
|
86
|
+
describe '#configure', public: true do
|
87
|
+
|
88
|
+
context 'when the generated command has less than two arguments' do
|
89
|
+
|
90
|
+
it 'executes a configration block in the context of the runner' do
|
91
|
+
allow(subject).to receive_message_chain(:command, :has_at_least_two_arguments?).and_return(false)
|
92
|
+
|
93
|
+
expect(subject).to receive_message_chain(:dry_run!, :color!)
|
94
|
+
expect(subject).to receive(:level).with(:warning)
|
95
|
+
|
96
|
+
subject.configure do |s|
|
97
|
+
s.dry_run!.color!
|
98
|
+
s.level(:warning)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
62
104
|
describe '#initialize', public: true do
|
63
105
|
|
64
106
|
context 'with an API endpoint as argument' do
|
@@ -96,6 +138,7 @@ describe Dredd::Rack::Runner do
|
|
96
138
|
expect(subject.paths_to_blueprints('some/path/*.apib')).to eq subject
|
97
139
|
end
|
98
140
|
|
141
|
+
|
99
142
|
context 'with one or more paths to blueprints as arguments' do
|
100
143
|
|
101
144
|
it 'defines custom paths to blueprints' do
|
@@ -104,6 +147,13 @@ describe Dredd::Rack::Runner do
|
|
104
147
|
end
|
105
148
|
end
|
106
149
|
|
150
|
+
context 'with no arguments' do
|
151
|
+
|
152
|
+
it 'raises ArgumentError' do
|
153
|
+
expect{ subject.paths_to_blueprints() }.to raise_error ArgumentError, 'invalid path to blueprints'
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
107
157
|
context 'with a blank path as argument', public: true do
|
108
158
|
|
109
159
|
it 'raises ArgumentError' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dredd-rack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gonzalo Bulnes Guilpain
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: capybara
|
@@ -91,6 +91,8 @@ files:
|
|
91
91
|
- LICENSE
|
92
92
|
- README.md
|
93
93
|
- Rakefile
|
94
|
+
- doc/rake_task.md
|
95
|
+
- doc/runner.md
|
94
96
|
- lib/dredd/rack.rb
|
95
97
|
- lib/dredd/rack/configuration.rb
|
96
98
|
- lib/dredd/rack/rake_task.rb
|