rspec_api_blueprint 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rspec_api_blueprint.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 TODO: Write your name
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'
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
+ - 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”.
30
+ - 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}”.
31
+
32
+ Example:
33
+
34
+ describe 'Arenas Requests' do
35
+ describe 'GET /v1/arenas/{id}' do
36
+ it 'responds with the requested arena' do
37
+ arena = create :arena, foursquare_id: '5104'
38
+ get v1_arena_path(arena)
39
+
40
+ response.status.should eq(200)
41
+ end
42
+ end
43
+ end
44
+
45
+ The output:
46
+
47
+ # GET /v1/arenas/{id}
48
+
49
+ + Response 200 (application/json)
50
+
51
+ {
52
+ "arena": {
53
+ "id": "4e9dbbc2-830b-41a9-b7db-9987735a0b2a",
54
+ "name": "Clinton St. Baking Co. & Restaurant",
55
+ "latitude": 40.721294,
56
+ "longitude": -73.983994,
57
+ "foursquare_id": "5104"
58
+ }
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,3 @@
1
+ module RspecApiBlueprint
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,57 @@
1
+ require "rspec_api_blueprint/version"
2
+
3
+ RSpec.configure do |config|
4
+ config.before(:suite) do
5
+ Dir.glob(File.join(Rails.root, '/docs/', '*')).each do |f|
6
+ File.delete(f)
7
+ end
8
+ end
9
+
10
+ config.after(:each, type: :request) do
11
+ if response
12
+ example_group = example.metadata[:example_group]
13
+ example_groups = []
14
+
15
+ while example_group
16
+ example_groups << example_group
17
+ example_group = example_group[:example_group]
18
+ end
19
+
20
+ action = example_groups[-2][:description_args].first if example_groups[-2]
21
+ example_groups[-1][:description_args].first.match(/(\w+)\sRequests/)
22
+ file_name = $1.underscore
23
+
24
+ File.open(File.join(Rails.root, "/docs/#{file_name}.txt"), 'a') do |f|
25
+ # Resource & Action
26
+ f.write "# #{action}\n\n"
27
+
28
+ # Request
29
+ request_body = request.body.read
30
+ authorization_header = request.headers['Authorization']
31
+
32
+ if request_body.present? || authorization_header.present?
33
+ f.write "+ Request #{request.content_type}\n\n"
34
+
35
+ # Request Headers
36
+ if authorization_header
37
+ f.write "+ Headers\n\n".indent(4)
38
+ f.write "Authorization: #{authorization_header}\n\n".indent(8)
39
+ end
40
+
41
+ # Request Body
42
+ if request_body.present?
43
+ f.write "+ Body\n\n".indent(4)
44
+ f.write "#{JSON.pretty_generate(JSON.parse(request_body))}\n\n".indent(8)
45
+ end
46
+ end
47
+
48
+ # Response
49
+ f.write "+ Response #{response.status} #{response.content_type}\n\n"
50
+
51
+ if response.body.present?
52
+ f.write "#{JSON.pretty_generate(JSON.parse(response.body))}\n\n".indent(4)
53
+ end
54
+ end unless response.status == 401 || response.status == 403 || response.status == 301
55
+ end
56
+ end
57
+ 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"
8
+ spec.version = RspecApiBlueprint::VERSION
9
+ spec.authors = ["Matteo Depalo"]
10
+ spec.email = ["matteodepalo@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 = ""
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,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rspec_api_blueprint
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Matteo Depalo
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-08-24 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec-rails
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: Autogeneration of documentation from request specs
63
+ email:
64
+ - matteodepalo@gmail.com
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - .gitignore
70
+ - Gemfile
71
+ - LICENSE.txt
72
+ - README.md
73
+ - Rakefile
74
+ - lib/rspec_api_blueprint.rb
75
+ - lib/rspec_api_blueprint/version.rb
76
+ - rspec_api_blueprint.gemspec
77
+ homepage: ''
78
+ licenses:
79
+ - MIT
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ segments:
91
+ - 0
92
+ hash: 1961368386880728741
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ segments:
100
+ - 0
101
+ hash: 1961368386880728741
102
+ requirements: []
103
+ rubyforge_project:
104
+ rubygems_version: 1.8.24
105
+ signing_key:
106
+ specification_version: 3
107
+ summary: Autogeneration of documentation from request specs
108
+ test_files: []