rspec_api_blueprint_2 0.0.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 +7 -0
- data/.editorconfig +9 -0
- data/.gitignore +17 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +22 -0
- data/README.md +74 -0
- data/Rakefile +1 -0
- data/lib/rspec_api_blueprint/string_extensions.rb +14 -0
- data/lib/rspec_api_blueprint/version.rb +3 -0
- data/lib/rspec_api_blueprint_2.rb +72 -0
- data/rspec_api_blueprint_2.gemspec +25 -0
- metadata +96 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0e05443e1db50779db4bd07a40aa763a799af952
|
4
|
+
data.tar.gz: 27e02fa05104c4dcecb6703e8a5e87c38c3172be
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 47f51a4a09dc95c1a992ba6b901d94036d26d2950a243d5f0185c185621737cbf2e9714e1c34948fd857725ec5ae8b020983d5d2eb81ab3b51d7a379dd303c72
|
7
|
+
data.tar.gz: a5dc41ebb54b551fafaeaf0e4217891468a6dc59df577d6b3b70ddb1148725aca65dfaf669104fb9327f9ab428314db006df974c2e046425c9345339eea6b2d6
|
data/.editorconfig
ADDED
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2018 Dayvson Lima
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Rspec Api Blueprint
|
2
|
+
|
3
|
+
Autogeneration of API documentation using the Blueprint format from request specs.
|
4
|
+
|
5
|
+
You can find more about Blueprint at http://apiblueprint.org
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'rspec_api_blueprint', require: false
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install rspec_api_blueprint
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
In your spec_helper.rb file add
|
24
|
+
|
25
|
+
require 'rspec_api_blueprint'
|
26
|
+
|
27
|
+
Write tests using the following convention:
|
28
|
+
|
29
|
+
- Tests must be placed in `spec/requests` folder or they have to be tagged with `type: :request`
|
30
|
+
- Top level descriptions are named after the model (plural form) followed by the word “Requests”. For a example model called Arena it would be “Arenas Requests”.
|
31
|
+
- Second level descriptions are actions in the form of “VERB path”. For the show action of the Arenas controller it would be “GET /arenas/{id}”.
|
32
|
+
|
33
|
+
Example:
|
34
|
+
|
35
|
+
describe 'Arenas Requests' do
|
36
|
+
describe 'GET /v1/arenas/{id}' do
|
37
|
+
it 'responds with the requested arena' do
|
38
|
+
arena = create :arena, foursquare_id: '5104'
|
39
|
+
get v1_arena_path(arena)
|
40
|
+
|
41
|
+
response.status.should eq(200)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
The output:
|
47
|
+
|
48
|
+
# GET /v1/arenas/{id}
|
49
|
+
|
50
|
+
+ Response 200 (application/json)
|
51
|
+
|
52
|
+
{
|
53
|
+
"arena": {
|
54
|
+
"id": "4e9dbbc2-830b-41a9-b7db-9987735a0b2a",
|
55
|
+
"name": "Clinton St. Baking Co. & Restaurant",
|
56
|
+
"latitude": 40.721294,
|
57
|
+
"longitude": -73.983994,
|
58
|
+
"foursquare_id": "5104"
|
59
|
+
}
|
60
|
+
}
|
61
|
+
|
62
|
+
## Caveats
|
63
|
+
|
64
|
+
401, 403 and 301 statuses are ignored since rspec produces a undesired output.
|
65
|
+
|
66
|
+
TODO: Add option to choose ignored statuses.
|
67
|
+
|
68
|
+
## Contributing
|
69
|
+
|
70
|
+
1. Fork it
|
71
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
72
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
73
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
74
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,14 @@
|
|
1
|
+
unless "".respond_to?(:indent)
|
2
|
+
class String
|
3
|
+
def indent(count, char = ' ')
|
4
|
+
gsub(/([^\n]*)(\n|$)/) do |match|
|
5
|
+
last_iteration = ($1 == "" && $2 == "")
|
6
|
+
line = ""
|
7
|
+
line << (char * count) unless last_iteration
|
8
|
+
line << $1
|
9
|
+
line << $2
|
10
|
+
line
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require "rspec_api_blueprint/version"
|
2
|
+
require "rspec_api_blueprint/string_extensions"
|
3
|
+
|
4
|
+
RSpec.configure do |config|
|
5
|
+
config.before(:suite) do
|
6
|
+
if defined? Rails
|
7
|
+
api_docs_folder_path = File.join(Rails.root, '/api_docs/')
|
8
|
+
else
|
9
|
+
api_docs_folder_path = File.join(File.expand_path('.'), '/api_docs/')
|
10
|
+
end
|
11
|
+
|
12
|
+
Dir.mkdir(api_docs_folder_path) unless Dir.exists?(api_docs_folder_path)
|
13
|
+
|
14
|
+
Dir.glob(File.join(api_docs_folder_path, '*')).each do |f|
|
15
|
+
File.delete(f)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
config.after(:each, type: :request) do |example|
|
20
|
+
if response
|
21
|
+
example_group = example.metadata[:example_group]
|
22
|
+
example_groups = []
|
23
|
+
|
24
|
+
while example_group
|
25
|
+
example_groups << example_group
|
26
|
+
example_group = example_group[:parent_example_group]
|
27
|
+
end
|
28
|
+
|
29
|
+
action = example_groups[-2][:description_args].first if example_groups[-2]
|
30
|
+
example_groups[-1][:description_args].first.match(/(\w+)\sRequests/)
|
31
|
+
file_name = $1.underscore
|
32
|
+
|
33
|
+
if defined? Rails
|
34
|
+
file = File.join(Rails.root, "/api_docs/#{file_name}.txt")
|
35
|
+
else
|
36
|
+
file = File.join(File.expand_path('.'), "/api_docs/#{file_name}.txt")
|
37
|
+
end
|
38
|
+
|
39
|
+
File.open(file, 'a') do |f|
|
40
|
+
# Resource & Action
|
41
|
+
f.write "# #{action}\n\n"
|
42
|
+
|
43
|
+
# Request
|
44
|
+
request_body = request.body.read
|
45
|
+
authorization_header = request.env ? request.env['Authorization'] : request.headers['Authorization']
|
46
|
+
|
47
|
+
if request_body.present? || authorization_header.present?
|
48
|
+
f.write "+ Request #{request.content_type}\n\n"
|
49
|
+
|
50
|
+
# Request Headers
|
51
|
+
if authorization_header.present?
|
52
|
+
f.write "+ Headers\n\n".indent(4)
|
53
|
+
f.write "Authorization: #{authorization_header}\n\n".indent(12)
|
54
|
+
end
|
55
|
+
|
56
|
+
# Request Body
|
57
|
+
if request_body.present? && request.content_type == 'application/json'
|
58
|
+
f.write "+ Body\n\n".indent(4) if authorization_header
|
59
|
+
f.write "#{JSON.pretty_generate(JSON.parse(request_body))}\n\n".indent(authorization_header ? 12 : 8)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
# Response
|
64
|
+
f.write "+ Response #{response.status} #{response.content_type}\n\n"
|
65
|
+
|
66
|
+
if response.body.present? && response.content_type =~ /application\/json/
|
67
|
+
f.write "#{JSON.pretty_generate(JSON.parse(response.body))}\n\n".indent(8)
|
68
|
+
end
|
69
|
+
end unless response.status == 401 || response.status == 403 || response.status == 301
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rspec_api_blueprint/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rspec_api_blueprint_2"
|
8
|
+
spec.version = RspecApiBlueprint::VERSION
|
9
|
+
spec.authors = ["Dayvson Lima"]
|
10
|
+
spec.email = ["dayvsonlima31@gmail.com"]
|
11
|
+
spec.description = %q{Autogeneration of documentation from request specs}
|
12
|
+
spec.summary = %q{Autogeneration of documentation from request specs}
|
13
|
+
spec.homepage = "https://github.com/dayvsonlima/rspec_api_blueprint_2"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
|
24
|
+
spec.add_dependency 'rspec-rails'
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rspec_api_blueprint_2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dayvson Lima
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-05-04 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.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec-rails
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Autogeneration of documentation from request specs
|
56
|
+
email:
|
57
|
+
- dayvsonlima31@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".editorconfig"
|
63
|
+
- ".gitignore"
|
64
|
+
- Gemfile
|
65
|
+
- LICENSE.txt
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- lib/rspec_api_blueprint/string_extensions.rb
|
69
|
+
- lib/rspec_api_blueprint/version.rb
|
70
|
+
- lib/rspec_api_blueprint_2.rb
|
71
|
+
- rspec_api_blueprint_2.gemspec
|
72
|
+
homepage: https://github.com/dayvsonlima/rspec_api_blueprint_2
|
73
|
+
licenses:
|
74
|
+
- MIT
|
75
|
+
metadata: {}
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options: []
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
requirements: []
|
91
|
+
rubyforge_project:
|
92
|
+
rubygems_version: 2.6.11
|
93
|
+
signing_key:
|
94
|
+
specification_version: 4
|
95
|
+
summary: Autogeneration of documentation from request specs
|
96
|
+
test_files: []
|