ghost_writer 0.4.2 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +5 -0
- data/.travis.yml +10 -1
- data/README.md +1 -1
- data/Rakefile +24 -3
- data/gemfiles/rspec2.gemfile +5 -0
- data/gemfiles/rspec3.gemfile +5 -0
- data/ghost_writer.gemspec +5 -3
- data/lib/ghost_writer.rb +16 -15
- data/lib/ghost_writer/document.rb +7 -4
- data/lib/ghost_writer/document_index.rb +0 -3
- data/lib/ghost_writer/index_writer/templates/rack.erb +1 -1
- data/lib/ghost_writer/version.rb +1 -1
- data/spec/lib/ghost_writer_spec.rb +19 -16
- data/spec/spec_helper.rb +11 -2
- metadata +45 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1dc0e5d084163ec03337241b84977a9e80c28756
|
4
|
+
data.tar.gz: 1e81c300e26e4b3f33333dd3e773e3c7a5b08b33
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 355426a71839e8a7af4513a2b4c0e096de8bb386c6c3e8ec486b95048f4e6e48c474a22a4a5dd79fec19ba27e7748092cbb8357df99b1faa0cefcda7bf010e73
|
7
|
+
data.tar.gz: 44e85808ba039ede8e92e095e2cdc9123b1d886d24f64eac3fcb46c021cabb1b83ffa0fb2d5709e009b735c27ecabdb429ba26fd880aef56618cc04a5952eee1
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -1,8 +1,17 @@
|
|
1
1
|
language: ruby
|
2
|
-
script: "bundle exec rake spec build"
|
3
2
|
rvm:
|
4
3
|
- 1.9.3
|
5
4
|
- 2.0.0
|
5
|
+
- 2.1
|
6
|
+
|
7
|
+
gemfile:
|
8
|
+
- gemfiles/rspec2.gemfile
|
9
|
+
- gemfiles/rspec3.gemfile
|
10
|
+
|
11
|
+
matrix:
|
12
|
+
allow_failures:
|
13
|
+
- rvm: 1.9.3
|
14
|
+
|
6
15
|
notifications:
|
7
16
|
email:
|
8
17
|
on_success: never
|
data/README.md
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/ghost_writer.png)](http://badge.fury.io/rb/ghost_writer)
|
4
4
|
[![Code Climate](https://codeclimate.com/github/joker1007/ghost_writer.png)](https://codeclimate.com/github/joker1007/ghost_writer)
|
5
5
|
|
6
|
-
Generate API examples from params and response of controller specs
|
6
|
+
Generate API examples from params and response of controller/request specs
|
7
7
|
|
8
8
|
## Installation
|
9
9
|
|
data/Rakefile
CHANGED
@@ -1,6 +1,27 @@
|
|
1
1
|
require "bundler/gem_tasks"
|
2
|
-
require "rspec/core/rake_task"
|
3
2
|
|
4
|
-
|
5
|
-
|
3
|
+
task :default => [:spec]
|
4
|
+
begin
|
5
|
+
require 'rspec/core/rake_task'
|
6
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
7
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
8
|
+
spec.rspec_opts = ['-c -f d']
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
namespace :spec do
|
13
|
+
%w(rspec2 rspec3).each do |gemfile|
|
14
|
+
desc "Run Tests by #{gemfile}.gemfile"
|
15
|
+
task gemfile do
|
16
|
+
sh "BUNDLE_GEMFILE='gemfiles/#{gemfile}.gemfile' bundle install --path .bundle"
|
17
|
+
sh "BUNDLE_GEMFILE='gemfiles/#{gemfile}.gemfile' bundle exec rake -t spec"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
desc "Run All Tests"
|
22
|
+
task :all do
|
23
|
+
%w(rspec2 rspec3).each do |gemfile|
|
24
|
+
Rake::Task["spec:#{gemfile}"].invoke
|
25
|
+
end
|
26
|
+
end
|
6
27
|
end
|
data/ghost_writer.gemspec
CHANGED
@@ -19,12 +19,14 @@ Gem::Specification.new do |gem|
|
|
19
19
|
gem.require_paths = ["lib"]
|
20
20
|
|
21
21
|
gem.add_dependency "activesupport", ">= 3.0.0"
|
22
|
-
gem.add_dependency "rspec-rails", "
|
22
|
+
gem.add_dependency "rspec-rails", ">= 2.12"
|
23
23
|
gem.add_dependency "trollop"
|
24
|
-
gem.add_dependency "
|
24
|
+
gem.add_dependency "oj"
|
25
|
+
gem.add_dependency "json"
|
25
26
|
|
26
|
-
gem.add_development_dependency "rspec-rails", "~> 2.12"
|
27
27
|
gem.add_development_dependency 'rake', ['>= 0']
|
28
28
|
gem.add_development_dependency 'rails', ['>= 3.2.9', '< 5']
|
29
|
+
gem.add_development_dependency 'sqlite3'
|
29
30
|
gem.add_development_dependency 'tapp'
|
31
|
+
gem.add_development_dependency 'pry'
|
30
32
|
end
|
data/lib/ghost_writer.rb
CHANGED
@@ -2,6 +2,8 @@ require "ghost_writer/version"
|
|
2
2
|
require "ghost_writer/document"
|
3
3
|
require "ghost_writer/document_index"
|
4
4
|
require "active_support/concern"
|
5
|
+
require "oj"
|
6
|
+
require "json"
|
5
7
|
|
6
8
|
module GhostWriter
|
7
9
|
extend ActiveSupport::Concern
|
@@ -27,10 +29,10 @@ module GhostWriter
|
|
27
29
|
|
28
30
|
def generate_api_doc
|
29
31
|
if output_flag
|
30
|
-
unless File.exist?(
|
31
|
-
FileUtils.mkdir_p(
|
32
|
+
unless File.exist?(output_dir)
|
33
|
+
FileUtils.mkdir_p(output_dir)
|
32
34
|
end
|
33
|
-
document_index = GhostWriter::DocumentIndex.new(
|
35
|
+
document_index = GhostWriter::DocumentIndex.new(output_dir + "#{DOCUMENT_INDEX_FILENAME}", document_group, GhostWriter.output_format)
|
34
36
|
document_index.write_file(format: output_format)
|
35
37
|
document_group.each do |output, docs|
|
36
38
|
docs.sort_by!(&:location)
|
@@ -49,11 +51,7 @@ module GhostWriter
|
|
49
51
|
end
|
50
52
|
|
51
53
|
def output_dir
|
52
|
-
@output_dir ? @output_dir : DEFAULT_OUTPUT_DIR
|
53
|
-
end
|
54
|
-
|
55
|
-
def output_path
|
56
|
-
Rails.root + "doc" + output_dir
|
54
|
+
@output_dir ? Pathname(@output_dir) : Pathname(DEFAULT_OUTPUT_DIR)
|
57
55
|
end
|
58
56
|
|
59
57
|
def output_format
|
@@ -61,10 +59,10 @@ module GhostWriter
|
|
61
59
|
end
|
62
60
|
end
|
63
61
|
|
64
|
-
def collect_example
|
65
|
-
output =
|
62
|
+
def collect_example(example)
|
63
|
+
output = doc_dir + doc_name(example)
|
66
64
|
document = GhostWriter::Document.new(output, {
|
67
|
-
title: "#{described_class} #{doc_name.titleize}",
|
65
|
+
title: "#{described_class} #{doc_name(example).titleize}",
|
68
66
|
description: example.full_description.dup,
|
69
67
|
location: example.location.dup,
|
70
68
|
request_method: request.env["REQUEST_METHOD"],
|
@@ -81,10 +79,10 @@ module GhostWriter
|
|
81
79
|
|
82
80
|
private
|
83
81
|
def doc_dir
|
84
|
-
GhostWriter.
|
82
|
+
GhostWriter.output_dir + described_class.to_s.underscore
|
85
83
|
end
|
86
84
|
|
87
|
-
def doc_name
|
85
|
+
def doc_name(example)
|
88
86
|
metadata = example.metadata[:generate_api_doc] || example.metadata[:ghost_writer]
|
89
87
|
case metadata
|
90
88
|
when String, Symbol
|
@@ -95,11 +93,14 @@ module GhostWriter
|
|
95
93
|
end
|
96
94
|
|
97
95
|
included do
|
98
|
-
after do
|
96
|
+
after do |example_or_group|
|
97
|
+
example = example_or_group.is_a?(RSpec::Core::Example) ?
|
98
|
+
example_or_group :
|
99
|
+
example_or_group.example
|
99
100
|
target_type = example.metadata[:type] == :controller || example.metadata[:type] == :request
|
100
101
|
target_metadata = example.metadata[:generate_api_doc] || example.metadata[:ghost_writer]
|
101
102
|
if target_type && target_metadata
|
102
|
-
collect_example if GhostWriter.output_flag
|
103
|
+
collect_example(example) if GhostWriter.output_flag
|
103
104
|
end
|
104
105
|
end
|
105
106
|
end
|
@@ -6,7 +6,7 @@ class GhostWriter::Document
|
|
6
6
|
|
7
7
|
def initialize(basename, attrs)
|
8
8
|
@basename = basename
|
9
|
-
@relative_path =
|
9
|
+
@relative_path = basename
|
10
10
|
@title = attrs[:title]
|
11
11
|
@description = attrs[:description]
|
12
12
|
@location = attrs[:location]
|
@@ -26,7 +26,10 @@ class GhostWriter::Document
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def serialized_params
|
29
|
-
|
29
|
+
Oj.dump(param_example)
|
30
|
+
rescue NoMemoryError, StandardError
|
31
|
+
puts "Param serialize error: #{param_example.inspect} of #{description} at #{location}"
|
32
|
+
param_example.inspect
|
30
33
|
end
|
31
34
|
|
32
35
|
def response_body
|
@@ -54,13 +57,13 @@ class GhostWriter::Document
|
|
54
57
|
def arrange_json(body)
|
55
58
|
return body unless response_format == "json"
|
56
59
|
|
57
|
-
data =
|
60
|
+
data = Oj.load(body)
|
58
61
|
if data.is_a?(Array) || data.is_a?(Hash)
|
59
62
|
JSON.pretty_generate(data)
|
60
63
|
else
|
61
64
|
data
|
62
65
|
end
|
63
|
-
rescue
|
66
|
+
rescue Oj::Error
|
64
67
|
body
|
65
68
|
end
|
66
69
|
end
|
@@ -7,7 +7,7 @@ class MockServer
|
|
7
7
|
case [request.request_method, request.path_info, params]
|
8
8
|
<% document_group.each do |output, docs| -%>
|
9
9
|
<% docs.each do |d| -%>
|
10
|
-
when [<%= d.request_method.inspect %>, <%= d.path_info.inspect %>, recursive_to_s(<%=
|
10
|
+
when [<%= d.request_method.inspect %>, <%= d.path_info.inspect %>, recursive_to_s(<%= Oj.load(d.serialized_params).inspect %>)]
|
11
11
|
[200, {"Content-Type" => <%= d.content_type.inspect %>}, [(<<BODY)]]
|
12
12
|
<%= d.response_body %>
|
13
13
|
BODY
|
data/lib/ghost_writer/version.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
|
-
class AnonymousController
|
3
|
+
class AnonymousController < ActionController::Base
|
4
4
|
end
|
5
5
|
|
6
6
|
describe GhostWriter do
|
7
7
|
|
8
8
|
let(:group) do
|
9
|
-
RSpec::Core::ExampleGroup.describe do
|
9
|
+
RSpec::Core::ExampleGroup.describe AnonymousController, type: :controller do
|
10
10
|
include RSpec::Rails::ControllerExampleGroup
|
11
11
|
include GhostWriter
|
12
12
|
|
@@ -38,7 +38,7 @@ describe GhostWriter do
|
|
38
38
|
it "first spec", generate_api_doc: true do
|
39
39
|
begin
|
40
40
|
get :index, param1: "value"
|
41
|
-
response.
|
41
|
+
expect(response).to be_success
|
42
42
|
rescue Exception => e
|
43
43
|
p e
|
44
44
|
end
|
@@ -47,7 +47,7 @@ describe GhostWriter do
|
|
47
47
|
it "second spec", generate_api_doc: true do
|
48
48
|
begin
|
49
49
|
get :index, param1: "value"
|
50
|
-
response.
|
50
|
+
expect(response).to be_success
|
51
51
|
rescue Exception => e
|
52
52
|
p e
|
53
53
|
end
|
@@ -58,7 +58,7 @@ describe GhostWriter do
|
|
58
58
|
it "returns a Resource json", generate_api_doc: true do
|
59
59
|
begin
|
60
60
|
get :show, id: 1, format: :json, param1: "value", params2: ["value1", "value2"]
|
61
|
-
response.
|
61
|
+
expect(response).to be_success
|
62
62
|
rescue Exception => e
|
63
63
|
p e
|
64
64
|
end
|
@@ -81,11 +81,12 @@ describe GhostWriter do
|
|
81
81
|
it "generate api doc file" do
|
82
82
|
group.run(NullObject.new)
|
83
83
|
GhostWriter.generate_api_doc
|
84
|
-
|
85
|
-
|
86
|
-
doc_body
|
87
|
-
doc_body.
|
88
|
-
doc_body.
|
84
|
+
path = Pathname("api_examples") + "anonymous_controller" + "index.md"
|
85
|
+
expect(path).to be_exist
|
86
|
+
doc_body = File.read(path)
|
87
|
+
expect(doc_body).to match(/# AnonymousController Index/)
|
88
|
+
expect(doc_body).to match(/first spec/)
|
89
|
+
expect(doc_body).to match(/second spec/)
|
89
90
|
end
|
90
91
|
|
91
92
|
context "Given github_base_url" do
|
@@ -94,7 +95,8 @@ describe GhostWriter do
|
|
94
95
|
GhostWriter.github_base_url = github_base_url
|
95
96
|
group.run(NullObject.new)
|
96
97
|
GhostWriter.generate_api_doc
|
97
|
-
|
98
|
+
path = Pathname("api_examples") + "#{GhostWriter::DOCUMENT_INDEX_FILENAME}.md"
|
99
|
+
expect(File.read(path)).to match(/#{github_base_url}/)
|
98
100
|
end
|
99
101
|
end
|
100
102
|
end
|
@@ -107,7 +109,7 @@ describe GhostWriter do
|
|
107
109
|
it "does not generate api doc file" do
|
108
110
|
group.run(NullObject.new)
|
109
111
|
GhostWriter.generate_api_doc
|
110
|
-
|
112
|
+
expect(Pathname("api_examples") + "anonymous_controller" + "index.md").not_to be_exist
|
111
113
|
end
|
112
114
|
end
|
113
115
|
end
|
@@ -128,14 +130,15 @@ describe GhostWriter do
|
|
128
130
|
ENV["GENERATE_API_DOC"] = "1"
|
129
131
|
group.run(NullObject.new)
|
130
132
|
GhostWriter.generate_api_doc
|
131
|
-
|
132
|
-
|
133
|
+
path = Pathname(output_dir) + "anonymous_controller" + "index.md"
|
134
|
+
expect(path).to be_exist
|
135
|
+
expect(File.read(path)).to match(/# AnonymousController Index/)
|
133
136
|
end
|
134
137
|
end
|
135
138
|
|
136
139
|
def clear_output(dirname)
|
137
|
-
if File.exist?(
|
138
|
-
FileUtils.rm_r(
|
140
|
+
if File.exist?(dirname)
|
141
|
+
FileUtils.rm_r(dirname)
|
139
142
|
end
|
140
143
|
end
|
141
144
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -2,11 +2,20 @@ ENV["RAILS_ENV"] = "test"
|
|
2
2
|
|
3
3
|
$:.unshift File.dirname(__FILE__)
|
4
4
|
|
5
|
-
require
|
5
|
+
require 'pry'
|
6
|
+
|
7
|
+
require 'rails/all'
|
6
8
|
|
9
|
+
ActiveRecord::Base.establish_connection(
|
10
|
+
adapter: "sqlite3",
|
11
|
+
database: ":memory:"
|
12
|
+
)
|
13
|
+
|
14
|
+
require "rails_app/config/environment"
|
7
15
|
I18n.load_path << File.expand_path("../support/locale/en.yml", __FILE__)
|
8
16
|
|
9
|
-
require
|
17
|
+
require 'rspec/rails'
|
18
|
+
require 'ghost_writer'
|
10
19
|
|
11
20
|
class NullObject
|
12
21
|
private
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ghost_writer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- joker1007
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-05-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -28,16 +28,16 @@ dependencies:
|
|
28
28
|
name: rspec-rails
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '2.
|
33
|
+
version: '2.12'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '2.
|
40
|
+
version: '2.12'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: trollop
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -53,7 +53,7 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: oj
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - ">="
|
@@ -67,19 +67,19 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: json
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - "
|
73
|
+
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
76
|
-
type: :
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - "
|
80
|
+
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
82
|
+
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: rake
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -114,6 +114,20 @@ dependencies:
|
|
114
114
|
- - "<"
|
115
115
|
- !ruby/object:Gem::Version
|
116
116
|
version: '5'
|
117
|
+
- !ruby/object:Gem::Dependency
|
118
|
+
name: sqlite3
|
119
|
+
requirement: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
type: :development
|
125
|
+
prerelease: false
|
126
|
+
version_requirements: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0'
|
117
131
|
- !ruby/object:Gem::Dependency
|
118
132
|
name: tapp
|
119
133
|
requirement: !ruby/object:Gem::Requirement
|
@@ -128,6 +142,20 @@ dependencies:
|
|
128
142
|
- - ">="
|
129
143
|
- !ruby/object:Gem::Version
|
130
144
|
version: '0'
|
145
|
+
- !ruby/object:Gem::Dependency
|
146
|
+
name: pry
|
147
|
+
requirement: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - ">="
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '0'
|
152
|
+
type: :development
|
153
|
+
prerelease: false
|
154
|
+
version_requirements: !ruby/object:Gem::Requirement
|
155
|
+
requirements:
|
156
|
+
- - ">="
|
157
|
+
- !ruby/object:Gem::Version
|
158
|
+
version: '0'
|
131
159
|
description: Generate API examples from params and response of controller specs
|
132
160
|
email:
|
133
161
|
- kakyoin.hierophant@gmail.com
|
@@ -143,6 +171,8 @@ files:
|
|
143
171
|
- README.md
|
144
172
|
- Rakefile
|
145
173
|
- bin/ghost_writer
|
174
|
+
- gemfiles/rspec2.gemfile
|
175
|
+
- gemfiles/rspec3.gemfile
|
146
176
|
- ghost_writer.gemspec
|
147
177
|
- lib/ghost_writer.rb
|
148
178
|
- lib/ghost_writer/document.rb
|
@@ -225,7 +255,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
225
255
|
version: '0'
|
226
256
|
requirements: []
|
227
257
|
rubyforge_project:
|
228
|
-
rubygems_version: 2.
|
258
|
+
rubygems_version: 2.2.2
|
229
259
|
signing_key:
|
230
260
|
specification_version: 4
|
231
261
|
summary: Generate API examples from params and response of controller specs
|
@@ -270,3 +300,4 @@ test_files:
|
|
270
300
|
- spec/rails_app/test/test_helper.rb
|
271
301
|
- spec/rails_app/test/unit/.gitkeep
|
272
302
|
- spec/spec_helper.rb
|
303
|
+
has_rdoc:
|