rspec-apib 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.codeclimate.yml +14 -0
- data/.dockerignore +6 -0
- data/.envrc +5 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.rubocop.yml +8 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +4 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Dockerfile +30 -0
- data/Gemfile +4 -0
- data/Guardfile +70 -0
- data/LICENSE.txt +21 -0
- data/README.md +61 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/docker-compose.yml +13 -0
- data/lib/rspec/apib/configuration.rb +32 -0
- data/lib/rspec/apib/recorder.rb +147 -0
- data/lib/rspec/apib/version.rb +5 -0
- data/lib/rspec/apib/writer.rb +82 -0
- data/lib/rspec/apib.rb +51 -0
- data/rspec-apib.gemspec +28 -0
- metadata +167 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3b881ddc9569c27542ca7c4d29c691c9b37d5e85
|
4
|
+
data.tar.gz: 7c51e086a7f24f4cfdb5fbce93d020fedbf54b9e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 06eb471cfa55de3668c81033c899838d0b9810bf39084cecebe79befdf3005d944fe22c47981dc6e214f30576ae5ea25dbee7c3636fca92d2cfe08bb5466a4c7
|
7
|
+
data.tar.gz: 4ee28410a78066c8397dd347823df202c729ce96e39f9a93a79857322632f387fe2a78f10d25a6601849cc18e8efb9de529c9767cc208a9e3b3fbadb171c5bbb
|
data/.codeclimate.yml
ADDED
data/.dockerignore
ADDED
data/.envrc
ADDED
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rspec-apib
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.2
|
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Dockerfile
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
FROM ruby:2.2
|
2
|
+
|
3
|
+
# Install dependencies
|
4
|
+
RUN apt-get update -qq && \
|
5
|
+
apt-get install -y -qq \
|
6
|
+
libpq-dev
|
7
|
+
|
8
|
+
# Create app directory
|
9
|
+
ENV APP_HOME /usr/src/app
|
10
|
+
RUN mkdir $APP_HOME
|
11
|
+
WORKDIR $APP_HOME
|
12
|
+
|
13
|
+
# Copy working directory
|
14
|
+
ADD . $APP_HOME
|
15
|
+
|
16
|
+
# Set Bundler cache directory outside of app scope
|
17
|
+
ENV BUNDLE_GEMFILE=$APP_HOME/Gemfile \
|
18
|
+
BUNDLE_JOBS=2 \
|
19
|
+
BUNDLE_PATH=/bundle
|
20
|
+
|
21
|
+
# Install gems
|
22
|
+
RUN bundle install
|
23
|
+
|
24
|
+
# Add bin/ folder to PATH
|
25
|
+
ENV PATH $APP_HOME/bin:$PATH
|
26
|
+
|
27
|
+
# Create tmp directory
|
28
|
+
RUN mkdir $APP_HOME/tmp && \
|
29
|
+
mkdir $APP_HOME/tmp/pids \
|
30
|
+
mkdir $APP_HOME/log
|
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
## Uncomment and set this to only include directories you want to watch
|
5
|
+
# directories %w(app lib config test spec features) \
|
6
|
+
# .select{|d| Dir.exists?(d) ? d : UI.warning("Directory #{d} does not exist")}
|
7
|
+
|
8
|
+
## Note: if you are using the `directories` clause above and you are not
|
9
|
+
## watching the project directory ('.'), then you will want to move
|
10
|
+
## the Guardfile to a watched dir and symlink it back, e.g.
|
11
|
+
#
|
12
|
+
# $ mkdir config
|
13
|
+
# $ mv Guardfile config/
|
14
|
+
# $ ln -s config/Guardfile .
|
15
|
+
#
|
16
|
+
# and, you'll have to watch "config/Guardfile" instead of "Guardfile"
|
17
|
+
|
18
|
+
# Note: The cmd option is now required due to the increasing number of ways
|
19
|
+
# rspec may be run, below are examples of the most common uses.
|
20
|
+
# * bundler: 'bundle exec rspec'
|
21
|
+
# * bundler binstubs: 'bin/rspec'
|
22
|
+
# * spring: 'bin/rspec' (This will use spring if running and you have
|
23
|
+
# installed the spring binstubs per the docs)
|
24
|
+
# * zeus: 'zeus rspec' (requires the server to be started separately)
|
25
|
+
# * 'just' rspec: 'rspec'
|
26
|
+
|
27
|
+
guard :rspec, cmd: "rspec" do
|
28
|
+
require "guard/rspec/dsl"
|
29
|
+
dsl = Guard::RSpec::Dsl.new(self)
|
30
|
+
|
31
|
+
# Feel free to open issues for suggestions and improvements
|
32
|
+
|
33
|
+
# RSpec files
|
34
|
+
rspec = dsl.rspec
|
35
|
+
watch(rspec.spec_helper) { rspec.spec_dir }
|
36
|
+
watch(rspec.spec_support) { rspec.spec_dir }
|
37
|
+
watch(rspec.spec_files)
|
38
|
+
|
39
|
+
# Ruby files
|
40
|
+
ruby = dsl.ruby
|
41
|
+
dsl.watch_spec_files_for(ruby.lib_files)
|
42
|
+
|
43
|
+
# Rails files
|
44
|
+
rails = dsl.rails(view_extensions: %w(erb haml slim))
|
45
|
+
dsl.watch_spec_files_for(rails.app_files)
|
46
|
+
dsl.watch_spec_files_for(rails.views)
|
47
|
+
|
48
|
+
watch(rails.controllers) do |m|
|
49
|
+
[
|
50
|
+
rspec.spec.("routing/#{m[1]}_routing"),
|
51
|
+
rspec.spec.("controllers/#{m[1]}_controller"),
|
52
|
+
rspec.spec.("acceptance/#{m[1]}")
|
53
|
+
]
|
54
|
+
end
|
55
|
+
|
56
|
+
# Rails config changes
|
57
|
+
watch(rails.spec_helper) { rspec.spec_dir }
|
58
|
+
watch(rails.routes) { "#{rspec.spec_dir}/routing" }
|
59
|
+
watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }
|
60
|
+
|
61
|
+
# Capybara features specs
|
62
|
+
watch(rails.view_dirs) { |m| rspec.spec.("features/#{m[1]}") }
|
63
|
+
watch(rails.layouts) { |m| rspec.spec.("features/#{m[1]}") }
|
64
|
+
|
65
|
+
# Turnip features and steps
|
66
|
+
watch(%r{^spec/acceptance/(.+)\.feature$})
|
67
|
+
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
|
68
|
+
Dir[File.join("**/#{m[1]}.feature")][0] || "spec/acceptance"
|
69
|
+
end
|
70
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Paul Spieker
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
# Rspec::Apib
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/rspec/apib`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'rspec-apib'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install rspec-apib
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
# rails_helper.rb
|
27
|
+
# ...
|
28
|
+
require 'rspec/apib'
|
29
|
+
|
30
|
+
# Configuration
|
31
|
+
RSpec::Apib.configure do |config|
|
32
|
+
# Define pre documentation files
|
33
|
+
config.pre_docs = Dir[Rails.root.join('docs/pre_*.md')]
|
34
|
+
|
35
|
+
# Define post documentation files
|
36
|
+
config.post_docs = Dir[Rails.root.join('docs/post_*.md')]
|
37
|
+
|
38
|
+
# Define output file
|
39
|
+
config.dest_file = Rails.root.join('apiary.apib')
|
40
|
+
|
41
|
+
# Example types to record
|
42
|
+
config.record_types = [:request]
|
43
|
+
end
|
44
|
+
# ...
|
45
|
+
RSpec::Apib.start
|
46
|
+
```
|
47
|
+
|
48
|
+
## Development
|
49
|
+
|
50
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
51
|
+
|
52
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
53
|
+
|
54
|
+
## Contributing
|
55
|
+
|
56
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/rspec-apib. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
57
|
+
|
58
|
+
|
59
|
+
## License
|
60
|
+
|
61
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "rspec/apib"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/docker-compose.yml
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
module RSpec
|
2
|
+
module Apib
|
3
|
+
class Configuration < Struct.new(
|
4
|
+
:dest_file, :pre_docs, :post_docs, :request_header_blacklist,
|
5
|
+
:request_param_blacklist, :record_types
|
6
|
+
)
|
7
|
+
def initialize
|
8
|
+
self.pre_docs = []
|
9
|
+
self.post_docs = []
|
10
|
+
self.request_header_blacklist = %w(host accept cookie)
|
11
|
+
self.request_param_blacklist = %i(controller action)
|
12
|
+
self.record_types = %i(request)
|
13
|
+
end
|
14
|
+
|
15
|
+
def dest_file
|
16
|
+
super || File.join(Rails.root.to_s, 'apiary.apib')
|
17
|
+
end
|
18
|
+
|
19
|
+
def pre_docs=(value)
|
20
|
+
super([value].flatten)
|
21
|
+
end
|
22
|
+
|
23
|
+
def post_docs=(value)
|
24
|
+
super([value].flatten)
|
25
|
+
end
|
26
|
+
|
27
|
+
def record_types=(value)
|
28
|
+
super([value].flatten)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,147 @@
|
|
1
|
+
module RSpec
|
2
|
+
module Apib
|
3
|
+
class Recorder
|
4
|
+
attr_reader :example, :request, :response, :routes, :apib
|
5
|
+
|
6
|
+
def initialize(example, request, response, routes, apib)
|
7
|
+
@example = example
|
8
|
+
@request = request
|
9
|
+
@response = response
|
10
|
+
@routes = routes
|
11
|
+
@apib = apib
|
12
|
+
end
|
13
|
+
|
14
|
+
def run
|
15
|
+
return unless request
|
16
|
+
return unless response
|
17
|
+
|
18
|
+
document_request
|
19
|
+
document_response
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
# Request headers contained in the blacklist will not be included in the
|
25
|
+
# API documentation
|
26
|
+
def request_header_blacklist
|
27
|
+
RSpec::Apib.config.request_header_blacklist
|
28
|
+
end
|
29
|
+
|
30
|
+
def request_param_blacklist
|
31
|
+
RSpec::Apib.config.request_param_blacklist
|
32
|
+
end
|
33
|
+
|
34
|
+
# The routing object for the rails route of the request
|
35
|
+
def route
|
36
|
+
@route ||= begin
|
37
|
+
route = routes.router.send(:find_routes, request).first
|
38
|
+
route = route.third if route.present?
|
39
|
+
route
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# The top level example group the example is contained in
|
44
|
+
def example_group
|
45
|
+
@example_group ||= begin
|
46
|
+
example_group = example.metadata[:example_group]
|
47
|
+
while example_group[:parent_example_group]
|
48
|
+
example_group = example_group[:parent_example_group]
|
49
|
+
end
|
50
|
+
example_group
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def path
|
55
|
+
@path ||= begin
|
56
|
+
parts = route.parts
|
57
|
+
tmp = {}
|
58
|
+
parts.each do |part|
|
59
|
+
if route.optional_parts.include?(part)
|
60
|
+
tmp[part] = "(:#{part}:)"
|
61
|
+
else
|
62
|
+
tmp[part] = ":#{part}:"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
result = route.format(tmp).gsub(/:(.*?):/, '{\\1}')
|
66
|
+
result = result.gsub('.(', '(.')
|
67
|
+
result = result.gsub('/(', '(/')
|
68
|
+
result
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def group
|
73
|
+
@group ||= begin
|
74
|
+
apib[resource_name] ||= {}
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def resource_type
|
79
|
+
@resource_type ||= begin
|
80
|
+
route.required_parts.include?(:id) ? 'resource' : 'collection'
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def resource_name
|
85
|
+
@resource_name ||= example_group[:description].to_s.singularize
|
86
|
+
end
|
87
|
+
|
88
|
+
def action
|
89
|
+
@action ||= begin
|
90
|
+
name = "#{request.method} #{path}"
|
91
|
+
group[name] ||= {
|
92
|
+
request: { _status: 600 },
|
93
|
+
response: []
|
94
|
+
}
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def document_request
|
99
|
+
document_request_params
|
100
|
+
return if response.status >= action[:request][:_status]
|
101
|
+
action[:request][:_status] = response.status
|
102
|
+
action[:request][:path] = request.path
|
103
|
+
action[:request][:body] = request.body.read
|
104
|
+
document_request_header
|
105
|
+
end
|
106
|
+
|
107
|
+
def document_request_header
|
108
|
+
action[:request][:headers] = {}
|
109
|
+
request.headers.each do |k, v|
|
110
|
+
next unless k.starts_with?('HTTP_')
|
111
|
+
header = k.gsub('HTTP_', '').downcase
|
112
|
+
next if request_header_blacklist.include? header
|
113
|
+
action[:request][:headers][header] = v
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def document_request_params
|
118
|
+
return if (200..299).exclude?(response.status)
|
119
|
+
params = request.params.symbolize_keys
|
120
|
+
request_param_blacklist.each { |param| params.except!(param) }
|
121
|
+
action[:request][:params] ||= {}
|
122
|
+
params.each do |name, value|
|
123
|
+
action[:request][:params][name] ||= {
|
124
|
+
value: value,
|
125
|
+
path: route.parts.include?(name),
|
126
|
+
required: route.required_parts.include?(name)
|
127
|
+
}
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
def document_response
|
132
|
+
data = {}
|
133
|
+
return if response_exists?
|
134
|
+
data[:description] = example.description
|
135
|
+
data[:status] = response.status
|
136
|
+
data[:content_type] = response.content_type.to_s
|
137
|
+
data[:body] = response.body
|
138
|
+
data[:headers] = response.headers
|
139
|
+
action[:response] << data
|
140
|
+
end
|
141
|
+
|
142
|
+
def response_exists?
|
143
|
+
action[:response].any? { |r| r[:status] == response.status }
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
module RSpec
|
2
|
+
module Apib
|
3
|
+
class Writer
|
4
|
+
def initialize(doc)
|
5
|
+
@apib = doc
|
6
|
+
end
|
7
|
+
|
8
|
+
def write
|
9
|
+
data = []
|
10
|
+
data << pre_docs
|
11
|
+
data << build
|
12
|
+
data << post_docs
|
13
|
+
write_to_file data.join("\n\n")
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def write_to_file(data)
|
19
|
+
File.open(RSpec::Apib.config.dest_file, 'w') do |file|
|
20
|
+
file.write(data)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def pre_docs
|
25
|
+
RSpec::Apib.config.pre_docs.map { |f| File.read(f) }.join("\n\n")
|
26
|
+
end
|
27
|
+
|
28
|
+
def post_docs
|
29
|
+
RSpec::Apib.config.post_docs.map { |f| File.read(f) }.join("\n\n")
|
30
|
+
end
|
31
|
+
|
32
|
+
def build
|
33
|
+
apib = ""
|
34
|
+
|
35
|
+
@apib.each do |group_name, group|
|
36
|
+
apib += "# Group #{group_name}\n\n"
|
37
|
+
group.each do |action, data|
|
38
|
+
apib += "## #{action}\n\n"
|
39
|
+
|
40
|
+
if data[:request][:params].length > 0
|
41
|
+
apib += "+ Parameters\n\n"
|
42
|
+
data[:request][:params].each do |name, param|
|
43
|
+
required = param[:required] ? 'required' : 'optional'
|
44
|
+
value = param[:value]
|
45
|
+
apib += " + #{name} (#{required}, string, `#{value}`) ...\n"
|
46
|
+
end
|
47
|
+
apib += "\n"
|
48
|
+
end
|
49
|
+
|
50
|
+
apib += "+ Request\n\n"
|
51
|
+
apib += " + Headers\n\n"
|
52
|
+
data[:request][:headers].each do |header, value|
|
53
|
+
apib += " #{header}: #{value}\n"
|
54
|
+
end
|
55
|
+
apib += "\n"
|
56
|
+
unless data[:request][:body].blank?
|
57
|
+
apib += " + Body\n\n"
|
58
|
+
apib += data[:request][:body].to_s.indent(12)
|
59
|
+
apib += "\n\n"
|
60
|
+
end
|
61
|
+
data[:response].sort { |a, b| a[:status] - b[:status] }.each do |response|
|
62
|
+
apib += "+ Response #{response[:status]}\n\n"
|
63
|
+
apib += " #{response[:description]}\n\n"
|
64
|
+
apib += " + Headers\n\n"
|
65
|
+
response[:headers].each do |header, value|
|
66
|
+
apib += " #{header}: #{value}\n"
|
67
|
+
end
|
68
|
+
apib += "\n"
|
69
|
+
unless response[:body].blank?
|
70
|
+
apib += " + Body\n\n"
|
71
|
+
apib += response[:body].to_s.indent(12)
|
72
|
+
apib += "\n\n"
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
apib
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
data/lib/rspec/apib.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'rails'
|
2
|
+
require 'rspec/apib/version'
|
3
|
+
require 'rspec/apib/configuration'
|
4
|
+
require 'rspec/apib/recorder'
|
5
|
+
require 'rspec/apib/writer'
|
6
|
+
|
7
|
+
module RSpec
|
8
|
+
module Apib
|
9
|
+
class <<self
|
10
|
+
def configure
|
11
|
+
@config = Configuration.new
|
12
|
+
yield(@config) if block_given?
|
13
|
+
@config
|
14
|
+
end
|
15
|
+
|
16
|
+
def config
|
17
|
+
@config || configure
|
18
|
+
end
|
19
|
+
|
20
|
+
def connection
|
21
|
+
Connection.instance
|
22
|
+
end
|
23
|
+
|
24
|
+
def start
|
25
|
+
types = config.record_types
|
26
|
+
RSpec.configure do |config|
|
27
|
+
config.after :each do |example|
|
28
|
+
if types.include?(example.metadata[:type])
|
29
|
+
RSpec::Apib.record(example, request, response, @routes)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
config.after :all do |example|
|
34
|
+
RSpec::Apib.write
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def record(example, request, response, routes)
|
40
|
+
@_doc ||= {}
|
41
|
+
recorder = Recorder.new(example, request, response, routes, @_doc)
|
42
|
+
recorder.run
|
43
|
+
end
|
44
|
+
|
45
|
+
def write
|
46
|
+
writer = Writer.new(@_doc || {})
|
47
|
+
writer.write
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/rspec-apib.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rspec/apib/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rspec-apib"
|
8
|
+
spec.version = RSpec::Apib::VERSION
|
9
|
+
spec.authors = ["Paul Spieker"]
|
10
|
+
spec.email = ["p.spieker@duenos.de"]
|
11
|
+
|
12
|
+
spec.summary = %q{Generates API Blueprint from request specs}
|
13
|
+
spec.homepage = "https://github.com/spieker/rspec-apib"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = "exe"
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.10'
|
22
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
23
|
+
spec.add_development_dependency 'guard', '~> 2.13.0'
|
24
|
+
spec.add_development_dependency 'guard-rspec', '~> 4.6.4'
|
25
|
+
spec.add_development_dependency 'pry'
|
26
|
+
spec.add_dependency 'rails', '>= 4.2'
|
27
|
+
spec.add_dependency 'rspec-rails', '~> 3.4'
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,167 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rspec-apib
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Paul Spieker
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-08-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: guard
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 2.13.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 2.13.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: guard-rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 4.6.4
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 4.6.4
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rails
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '4.2'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '4.2'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rspec-rails
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '3.4'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '3.4'
|
111
|
+
description:
|
112
|
+
email:
|
113
|
+
- p.spieker@duenos.de
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".codeclimate.yml"
|
119
|
+
- ".dockerignore"
|
120
|
+
- ".envrc"
|
121
|
+
- ".gitignore"
|
122
|
+
- ".rspec"
|
123
|
+
- ".rubocop.yml"
|
124
|
+
- ".ruby-gemset"
|
125
|
+
- ".ruby-version"
|
126
|
+
- ".travis.yml"
|
127
|
+
- CODE_OF_CONDUCT.md
|
128
|
+
- Dockerfile
|
129
|
+
- Gemfile
|
130
|
+
- Guardfile
|
131
|
+
- LICENSE.txt
|
132
|
+
- README.md
|
133
|
+
- Rakefile
|
134
|
+
- bin/console
|
135
|
+
- bin/setup
|
136
|
+
- docker-compose.yml
|
137
|
+
- lib/rspec/apib.rb
|
138
|
+
- lib/rspec/apib/configuration.rb
|
139
|
+
- lib/rspec/apib/recorder.rb
|
140
|
+
- lib/rspec/apib/version.rb
|
141
|
+
- lib/rspec/apib/writer.rb
|
142
|
+
- rspec-apib.gemspec
|
143
|
+
homepage: https://github.com/spieker/rspec-apib
|
144
|
+
licenses:
|
145
|
+
- MIT
|
146
|
+
metadata: {}
|
147
|
+
post_install_message:
|
148
|
+
rdoc_options: []
|
149
|
+
require_paths:
|
150
|
+
- lib
|
151
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
152
|
+
requirements:
|
153
|
+
- - ">="
|
154
|
+
- !ruby/object:Gem::Version
|
155
|
+
version: '0'
|
156
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
157
|
+
requirements:
|
158
|
+
- - ">="
|
159
|
+
- !ruby/object:Gem::Version
|
160
|
+
version: '0'
|
161
|
+
requirements: []
|
162
|
+
rubyforge_project:
|
163
|
+
rubygems_version: 2.5.1
|
164
|
+
signing_key:
|
165
|
+
specification_version: 4
|
166
|
+
summary: Generates API Blueprint from request specs
|
167
|
+
test_files: []
|