rspec_generate_doc 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 151a44bdc19b4f05be2693d500dc376624997f7e
4
+ data.tar.gz: 5db6ea344c7926fc7dc3f54fb861c9482f3049ea
5
+ SHA512:
6
+ metadata.gz: ac4326fb9b2e8175785e00f7a72d98cc3232fc9099561ec96a83f34c8ff5edb20ec1684843243a9e1ab87656f38796f08d3af755efdf732310947217264a8edc
7
+ data.tar.gz: 372ae220dc82d9276655f28abf9133afdf91313b48598c0f03dc9d8eac1a251fb402465f786ef9687ec821fb98fcd71264d35fba7929d73bb4ce4374ede03b1d
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at djok69@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE.md ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+ =====================
3
+
4
+ Copyright (c) 2016 Igor Kutyavin aka Jokius
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in
14
+ all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,78 @@
1
+ Rspec generate doc
2
+ ===
3
+
4
+ This gem help you to generate simple documentation api from Rspec tests.
5
+
6
+ Installation
7
+ ============
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'rspec_generate_doc'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Usage
20
+ =====
21
+
22
+ **Configure**
23
+ ``` ruby
24
+ # spec/rails_helper.rb
25
+ ...
26
+ require 'rspec_generate_doc'
27
+ ..
28
+ RspecGenerateDoc.configure do |config|
29
+ config.docs_dir = 'path/to/docs/dir' # default: "#{Rails.root}/docs"
30
+ config.locale = :ru # default: I18n.default_locale
31
+ end
32
+ ```
33
+
34
+ Example use
35
+
36
+ ``` ruby
37
+ # spec/controllers/user_controller_spec.rb
38
+ ...
39
+ let(:params) do
40
+ {
41
+ id: { description: 'user id', required: true },
42
+ email: { description: 'user email', required: false }
43
+ }
44
+ end
45
+ ...
46
+ ```
47
+ *keys description:*
48
+ id | email - parameter in result
49
+ description - description parameter. Default parent key name
50
+ required - is parameter required? Default false
51
+
52
+ **result**
53
+
54
+ After tests completed file *_user_controller.md* will be created in docs folder. In format to Slate
55
+
56
+ Copyright
57
+ =========
58
+
59
+ Copyright (c) 2016 Igor Kutyavin aka Jokius
60
+
61
+ Permission is hereby granted, free of charge, to any person obtaining
62
+ a copy of this software and associated documentation files (the
63
+ "Software"), to deal in the Software without restriction, including
64
+ without limitation the rights to use, copy, modify, merge, publish,
65
+ distribute, sublicense, and/or sell copies of the Software, and to
66
+ permit persons to whom the Software is furnished to do so, subject to
67
+ the following conditions:
68
+
69
+ The above copyright notice and this permission notice shall be
70
+ included in all copies or substantial portions of the Software.
71
+
72
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
73
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
74
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
75
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
76
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
77
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
78
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "rspec_generate_doc"
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
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,7 @@
1
+ en:
2
+ rspec_api_docs:
3
+ parameter: Parameter
4
+ required: Required
5
+ description: Description
6
+ required_yes: Yes
7
+ required_no: No
@@ -0,0 +1,7 @@
1
+ ru:
2
+ rspec_api_docs:
3
+ parameter: Параметр
4
+ required: Обязательный
5
+ description: Описание
6
+ required_yes: Да
7
+ required_no: Нет
@@ -0,0 +1,21 @@
1
+ require 'fileutils'
2
+
3
+ module RspecGenerateDoc
4
+ class Configuration
5
+ def docs_dir
6
+ @docs_dir || "#{Rails.root}/docs"
7
+ end
8
+
9
+ def docs_dir=(dir)
10
+ @docs_dir = dir
11
+ end
12
+
13
+ def locale
14
+ @locale || I18n.default_locale
15
+ end
16
+
17
+ def locale=(locale)
18
+ @locale = locale
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,77 @@
1
+ require 'fileutils'
2
+
3
+ module RspecGenerateDoc
4
+ class Genarate
5
+ attr_reader :parent, :methods_hash
6
+
7
+ def initialize(parent, methods_hash)
8
+ @parent = parent
9
+ @methods_hash = methods_hash
10
+ I18n.locale = RspecGenerateDoc.configuration.locale
11
+ create_file
12
+ end
13
+
14
+ private
15
+
16
+ def dir
17
+ @dir ||= FileUtils.mkdir_p(RspecGenerateDoc.configuration.docs_dir).join('')
18
+ end
19
+
20
+ def create_file
21
+ file = File.open("#{dir}/_#{parent_name}.md", 'w+')
22
+ file.write file_text
23
+ file.close
24
+ end
25
+
26
+ def parent_name
27
+ @parent_name ||= parent.downcase.split('::').join('_')
28
+ end
29
+
30
+ def file_text
31
+ file_text = "# #{parent}\r\n\r\n"
32
+ methods_hash.each do |key, method|
33
+ response = method[:response]
34
+ request = response.request
35
+ file_text += "##{key.split('#').join(' ')}\r\n\r\n"\
36
+ "```http\r\n"\
37
+ "#{request.request_method} #{request.original_fullpath.split('?').first} HTTP/1.1\r\n"\
38
+ "Host: #{response.request.host}\r\n"\
39
+ "User-Agent: ExampleClient/1.0.0\r\n"\
40
+ "```\r\n\r\n"\
41
+ "```http\r\n"\
42
+ "HTTP/1.1 #{response.status} #{response.status_message}\r\n"
43
+ file_text += "Content-Type: #{response.content_type}\r\n\r\n" if response.content_type.present?
44
+ if response.body.present?
45
+ object = begin
46
+ JSON.parse(response.body)
47
+ rescue
48
+ nil
49
+ end
50
+ body = object.nil? ? response.body : JSON.pretty_generate(object)
51
+ file_text += "#{body}\r\n" if response.body.present?
52
+ end
53
+
54
+ file_text += "```\r\n\r\n"\
55
+ "#{I18n.t(:parameter, scope: :rspec_api_docs)} | #{I18n.t(:required, scope: :rspec_api_docs)} | #{I18n.t(:description, scope: :rspec_api_docs)}\r\n"\
56
+ "-------- | ------- | -------\r\n"
57
+ file_text += params_to_text(request, method[:params])
58
+ file_text += "\r\n\r\n"
59
+ end
60
+
61
+ file_text
62
+ end
63
+
64
+ def params_to_text(request, params)
65
+ file_text = ''
66
+ request.params.except(*%i(controller action format)).each do |name, _|
67
+ hash = params[name.to_sym] || {}
68
+ hash = {} unless hash.is_a? Hash
69
+ required = hash[:required] ? I18n.t(:required_yes, scope: :rspec_api_docs) : I18n.t(:required_no, scope: :rspec_api_docs)
70
+ description = hash[:description] || name
71
+ file_text += "#{name} | #{required} | #{description}\r\n"
72
+ end
73
+
74
+ file_text
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,30 @@
1
+ require 'rspec/rails'
2
+ require 'rspec_generate_doc/generate'
3
+
4
+ module RspecGenerateDoc
5
+ module LibraryHooks
6
+ module Doc
7
+ ::RSpec.configure do |config|
8
+ config.before(:context) do
9
+ @hash = {}
10
+ end
11
+
12
+ config.after(:each) do
13
+ key = self.class.description
14
+ parent = self.class.parent
15
+ loop do
16
+ break if parent.nil? || parent.description == self.class.top_level_description
17
+ key = "#{parent.description} #{key}"
18
+ parent = parent.parent
19
+ end
20
+
21
+ @hash[key] ||= { response: response, params: (try(:params) || @params || {}) }
22
+ end
23
+
24
+ config.after(:context) do
25
+ RspecGenerateDoc::Genarate.new(self.class.top_level_description, @hash)
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,3 @@
1
+ module RspecGenerateDoc
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,21 @@
1
+ require 'rspec/rails'
2
+ require 'rspec_generate_doc/version'
3
+ require 'rspec_generate_doc/configuration'
4
+ require 'rspec_generate_doc/library_hooks/doc'
5
+ require 'rspec_generate_doc/generate'
6
+
7
+ module RspecGenerateDoc
8
+ I18n.load_path.concat Dir[File.expand_path('../../config/locales/*.yml', __FILE__)]
9
+
10
+ ::RSpec.configure do |config|
11
+ config.include RspecGenerateDoc::LibraryHooks::Doc, type: :controller
12
+ end
13
+
14
+ def configure
15
+ yield configuration
16
+ end
17
+
18
+ def configuration
19
+ @configuration ||= Configuration.new
20
+ end
21
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rspec_generate_doc/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'rspec_generate_doc'
8
+ spec.version = RspecGenerateDoc::VERSION
9
+ spec.authors = ["Igor Kutyavin"]
10
+ spec.email = ["djok69@gmail.com"]
11
+
12
+ spec.summary = %q{Generate documentation api of rspec tests}
13
+ spec.homepage = 'https://github.com/jokius/rspec_api_docs'
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 = %w(lib)
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.12'
22
+ spec.add_development_dependency 'rake', '~> 10.0'
23
+ spec.add_dependency 'rspec-rails'
24
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rspec_generate_doc
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Igor Kutyavin
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-11-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.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
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: 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:
56
+ email:
57
+ - djok69@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - CODE_OF_CONDUCT.md
64
+ - Gemfile
65
+ - LICENSE.md
66
+ - README.md
67
+ - Rakefile
68
+ - bin/console
69
+ - bin/setup
70
+ - config/locales/en.yml
71
+ - config/locales/ru.yml
72
+ - lib/rspec_generate_doc.rb
73
+ - lib/rspec_generate_doc/configuration.rb
74
+ - lib/rspec_generate_doc/generate.rb
75
+ - lib/rspec_generate_doc/library_hooks/doc.rb
76
+ - lib/rspec_generate_doc/version.rb
77
+ - rspec_generate_doc.gemspec
78
+ homepage: https://github.com/jokius/rspec_api_docs
79
+ licenses:
80
+ - MIT
81
+ metadata: {}
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubyforge_project:
98
+ rubygems_version: 2.5.2
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: Generate documentation api of rspec tests
102
+ test_files: []