restspec 0.0.3 → 0.0.4
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 +4 -4
- data/.travis.yml +1 -0
- data/README.md +1 -1
- data/ROADMAP.md +1 -2
- data/bin/restspec +4 -3
- data/examples/store-api-tests/Gemfile.lock +4 -4
- data/examples/store-api-tests/api.md +107 -70
- data/lib/restspec/endpoints/namespace.rb +1 -1
- data/lib/restspec/runners/docs/docs_runner.rb +66 -0
- data/lib/restspec/runners/docs/templates/docs.md.erb +22 -0
- data/lib/restspec/runners/install/install_runner.rb +50 -0
- data/lib/restspec/version.rb +1 -1
- data/restspec.gemspec +1 -1
- data/spec/restspec/endpoints/namespace_spec.rb +6 -0
- metadata +22 -24
- data/lib/restspec/doc_generators/markdown.rb +0 -65
- data/lib/restspec/runners/docs.rb +0 -20
- data/lib/restspec/runners/installer.rb +0 -48
- data/spec/restspec/doc_generators/markdown_spec.rb +0 -88
- /data/{bin → lib/restspec/runners/install}/templates/Gemfile +0 -0
- /data/{bin → lib/restspec/runners/install}/templates/custom_macros.rb +0 -0
- /data/{bin → lib/restspec/runners/install}/templates/restspec_config.rb +0 -0
- /data/{bin → lib/restspec/runners/install}/templates/spec_helper.rb +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b14366420ef12b0045f219c192a5346c0ff20e67
|
4
|
+
data.tar.gz: 579f30c0dfb646bbd366cb1a279e663df4894fb8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d73c7968b21b7370351c196ba873554366f08cf15c71c3d85dffea7a49a56a096592fd7c92fb6edb1c0e35869d2f71d461d97b24fde0ae393aa2d42a752a7281
|
7
|
+
data.tar.gz: 6c12400eae60a5ea62fc2eabf2551f536c0e95dd217adf64556fd414b6b896505f028181984cc08a01a1ae4b064eb1dfe6d26d6c46e8f49da4ade60278a60c94
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -186,4 +186,4 @@ Because the scope of this library is not small, we couldn't make a first release
|
|
186
186
|
|
187
187
|
## Contribute
|
188
188
|
|
189
|
-
Please be sure to have the [EditorConfig](http://editorconfig.org/) plugin in your text editor to follow the guidelines proposed in the [.editorconfig](https://github.com/platanus/restspec/blob/master/.editorconfig) file. To contribute, please send us a PR and make sure that the current tests keeps working after that. You can help to complete the unit tests too.
|
189
|
+
Please be sure to have the [EditorConfig](http://editorconfig.org/) plugin in your text editor to follow the guidelines proposed in the [.editorconfig](https://github.com/platanus/restspec/blob/master/.editorconfig) file. To contribute, please send us a PR and make sure that the current tests keeps working after that. You can help to complete the unit tests too.
|
data/ROADMAP.md
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
# For 0.0.x
|
2
2
|
- 100% Test coverage.
|
3
3
|
- Find a way to avoid example value clashes when using resource tests.
|
4
|
+
- Document DateType and DateTimeType
|
4
5
|
|
5
6
|
# For 0.1 (They require more thoughts)
|
6
7
|
- Research pagination strategies and integrating them with `schema_id`.
|
7
8
|
- Provide a method for cookie-based authentication.
|
8
9
|
- Research some way to generate markdown from a mix of the schemas and endpoints. (Like Apiary and others)
|
9
|
-
+ Generate whatever kind of markdown.
|
10
|
-
+ Generate Apiary Apib type.
|
11
10
|
+ Add a way to add texts to some points of the documentation.
|
12
11
|
+ TODO:
|
13
12
|
* Untie Schema for Schema Response Body. DELETEs don't return string, they usually returns NO CONTENT. Indeed: nothing.
|
data/bin/restspec
CHANGED
@@ -6,11 +6,12 @@ $LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)
|
|
6
6
|
require 'thor'
|
7
7
|
require 'thor/group'
|
8
8
|
require 'pathname'
|
9
|
-
require 'restspec/runners/
|
10
|
-
require 'restspec/runners/docs'
|
9
|
+
require 'restspec/runners/install/install_runner'
|
10
|
+
require 'restspec/runners/docs/docs_runner'
|
11
11
|
|
12
12
|
class RestspecCLI < Thor
|
13
|
-
register(
|
13
|
+
register(Restspec::InstallRunner, 'install', 'install [your_test_folder]', 'Type restspec install for more help.')
|
14
|
+
# register(Restspec::DocsRunner, 'docs', 'docs [your_docs_location]', 'Type restspec docs for more help.')
|
14
15
|
end
|
15
16
|
|
16
17
|
RestspecCLI.start(ARGV)
|
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: ~/dev/projects/ruby/restspec
|
3
3
|
specs:
|
4
|
-
restspec (0.0.
|
4
|
+
restspec (0.0.3)
|
5
5
|
activesupport (~> 4.0)
|
6
6
|
faker (~> 1.4)
|
7
7
|
hashie (~> 3.3)
|
@@ -15,11 +15,11 @@ PATH
|
|
15
15
|
GEM
|
16
16
|
remote: https://rubygems.org/
|
17
17
|
specs:
|
18
|
-
activesupport (4.
|
19
|
-
i18n (~> 0.
|
18
|
+
activesupport (4.2.0)
|
19
|
+
i18n (~> 0.7)
|
20
20
|
json (~> 1.7, >= 1.7.7)
|
21
21
|
minitest (~> 5.1)
|
22
|
-
thread_safe (~> 0.
|
22
|
+
thread_safe (~> 0.3, >= 0.3.4)
|
23
23
|
tzinfo (~> 1.1)
|
24
24
|
coderay (1.1.0)
|
25
25
|
diff-lcs (1.2.5)
|
@@ -1,107 +1,144 @@
|
|
1
1
|
# API
|
2
|
+
## Hello World
|
2
3
|
|
3
4
|
## Products
|
5
|
+
|
4
6
|
### Create [POST /products]
|
5
|
-
Returns schema **product**:
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
|
11
|
-
|
12
|
-
|
|
13
|
-
|
|
8
|
+
Returns schema **product**
|
9
|
+
|
10
|
+
|
11
|
+
| Attribute | Type | Example |
|
12
|
+
|-------------|:--------------------------:|---------------:|
|
13
|
+
| name | string | libero |
|
14
|
+
| code | string | expedita |
|
15
|
+
| price | decimal | 49.18 |
|
16
|
+
| category_id | schema_id | 1 |
|
17
|
+
| category | embedded_schema | {:name=>"rerum"} |
|
18
|
+
| created_at | date_time | 2014-12-15T12:37:23-05:00 |
|
19
|
+
| updated_at | date_time | 2014-12-14T18:01:19-05:00 |
|
14
20
|
|
15
21
|
### Index [GET /products]
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
|
21
|
-
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
|
23
|
+
Returns schema **product**
|
24
|
+
|
25
|
+
|
26
|
+
| Attribute | Type | Example |
|
27
|
+
|-------------|:--------------------------:|---------------:|
|
28
|
+
| name | string | voluptatum |
|
29
|
+
| code | string | blanditiis |
|
30
|
+
| price | decimal | 77.09 |
|
31
|
+
| category_id | schema_id | 2 |
|
32
|
+
| category | embedded_schema | {:name=>"ipsam"} |
|
33
|
+
| created_at | date_time | 2014-12-11T18:07:45-05:00 |
|
34
|
+
| updated_at | date_time | 2014-12-20T22:30:23-05:00 |
|
25
35
|
|
26
36
|
### Show [GET /products/:id]
|
27
|
-
Returns schema **product**:
|
28
37
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
|
33
|
-
|
34
|
-
|
|
35
|
-
|
|
38
|
+
Returns schema **product**
|
39
|
+
|
40
|
+
|
41
|
+
| Attribute | Type | Example |
|
42
|
+
|-------------|:--------------------------:|---------------:|
|
43
|
+
| name | string | distinctio |
|
44
|
+
| code | string | blanditiis |
|
45
|
+
| price | decimal | 55.84 |
|
46
|
+
| category_id | schema_id | 4 |
|
47
|
+
| category | embedded_schema | {:name=>"iure"} |
|
48
|
+
| created_at | date_time | 2014-12-07T13:39:53-05:00 |
|
49
|
+
| updated_at | date_time | 2014-12-07T13:45:22-05:00 |
|
36
50
|
|
37
51
|
### Update [PUT /products/:id]
|
38
|
-
Returns schema **product**:
|
39
52
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
|
44
|
-
|
45
|
-
|
|
46
|
-
|
|
53
|
+
Returns schema **product**
|
54
|
+
|
55
|
+
|
56
|
+
| Attribute | Type | Example |
|
57
|
+
|-------------|:--------------------------:|---------------:|
|
58
|
+
| name | string | sit |
|
59
|
+
| code | string | ut |
|
60
|
+
| price | decimal | 85.80 |
|
61
|
+
| category_id | schema_id | 5 |
|
62
|
+
| category | embedded_schema | {:name=>"qui"} |
|
63
|
+
| created_at | date_time | 2014-12-02T15:11:53-05:00 |
|
64
|
+
| updated_at | date_time | 2014-11-29T13:55:04-05:00 |
|
47
65
|
|
48
66
|
### Destroy [DELETE /products/:id]
|
49
|
-
Returns schema **product**:
|
50
67
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
|
55
|
-
|
56
|
-
|
|
57
|
-
|
|
68
|
+
Returns schema **product**
|
69
|
+
|
70
|
+
|
71
|
+
| Attribute | Type | Example |
|
72
|
+
|-------------|:--------------------------:|---------------:|
|
73
|
+
| name | string | aut |
|
74
|
+
| code | string | illo |
|
75
|
+
| price | decimal | 81.59 |
|
76
|
+
| category_id | schema_id | 3 |
|
77
|
+
| category | embedded_schema | {:name=>"quis"} |
|
78
|
+
| created_at | date_time | 2014-11-25T07:30:09-05:00 |
|
79
|
+
| updated_at | date_time | 2014-11-30T22:45:02-05:00 |
|
58
80
|
|
59
81
|
|
60
82
|
## Categories
|
83
|
+
|
61
84
|
### Create [POST /categories]
|
62
|
-
Returns schema **category**:
|
63
85
|
|
64
|
-
|
65
|
-
|
66
|
-
|
86
|
+
Returns schema **category**
|
87
|
+
|
88
|
+
|
89
|
+
| Attribute | Type | Example |
|
90
|
+
|-------------|:--------------------------:|---------------:|
|
91
|
+
| name | string | voluptate |
|
67
92
|
|
68
93
|
### Index [GET /categories]
|
69
|
-
Returns schema **category**:
|
70
94
|
|
71
|
-
|
72
|
-
|
73
|
-
|
95
|
+
Returns schema **category**
|
96
|
+
|
97
|
+
|
98
|
+
| Attribute | Type | Example |
|
99
|
+
|-------------|:--------------------------:|---------------:|
|
100
|
+
| name | string | odit |
|
74
101
|
|
75
102
|
### Show [GET /categories/:id]
|
76
|
-
Returns schema **category**:
|
77
103
|
|
78
|
-
|
79
|
-
|
80
|
-
|
104
|
+
Returns schema **category**
|
105
|
+
|
106
|
+
|
107
|
+
| Attribute | Type | Example |
|
108
|
+
|-------------|:--------------------------:|---------------:|
|
109
|
+
| name | string | explicabo |
|
81
110
|
|
82
111
|
### Update [PUT /categories/:id]
|
83
|
-
Returns schema **category**:
|
84
112
|
|
85
|
-
|
86
|
-
|
87
|
-
|
113
|
+
Returns schema **category**
|
114
|
+
|
115
|
+
|
116
|
+
| Attribute | Type | Example |
|
117
|
+
|-------------|:--------------------------:|---------------:|
|
118
|
+
| name | string | quos |
|
88
119
|
|
89
120
|
### Destroy [DELETE /categories/:id]
|
90
|
-
Returns schema **category**:
|
91
121
|
|
92
|
-
|
93
|
-
|
94
|
-
|
122
|
+
Returns schema **category**
|
123
|
+
|
124
|
+
|
125
|
+
| Attribute | Type | Example |
|
126
|
+
|-------------|:--------------------------:|---------------:|
|
127
|
+
| name | string | fuga |
|
95
128
|
|
96
129
|
### Products [GET /categories/:id/products]
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
|
102
|
-
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
130
|
+
|
131
|
+
Returns schema **product**
|
132
|
+
|
133
|
+
|
134
|
+
| Attribute | Type | Example |
|
135
|
+
|-------------|:--------------------------:|---------------:|
|
136
|
+
| name | string | eos |
|
137
|
+
| code | string | odit |
|
138
|
+
| price | decimal | 41.37 |
|
139
|
+
| category_id | schema_id | 8 |
|
140
|
+
| category | embedded_schema | {:name=>"et"} |
|
141
|
+
| created_at | date_time | 2014-11-24T12:34:34-05:00 |
|
142
|
+
| updated_at | date_time | 2014-11-25T02:07:06-05:00 |
|
106
143
|
|
107
144
|
|
@@ -18,7 +18,7 @@ module Restspec
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def add_anonymous_children_namespace
|
21
|
-
anonymous_namespace = Namespace.
|
21
|
+
anonymous_namespace = Namespace.new('')
|
22
22
|
anonymous_namespace.parent_namespace = self
|
23
23
|
children_namespaces << anonymous_namespace
|
24
24
|
anonymous_namespace
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'tilt'
|
2
|
+
require 'erb'
|
3
|
+
|
4
|
+
module Restspec
|
5
|
+
class DocsRunner < Thor::Group
|
6
|
+
TEMPLATE_BY_EXTENSION = {
|
7
|
+
'.md' => 'docs.md.erb'
|
8
|
+
}
|
9
|
+
|
10
|
+
argument :file, :default => 'api_docs.md'
|
11
|
+
|
12
|
+
def generate_docs
|
13
|
+
require 'restspec'
|
14
|
+
require config_file
|
15
|
+
|
16
|
+
File.write(file, read_template(extension))
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def read_template(extension)
|
22
|
+
template_file_name = "templates/#{template_name}"
|
23
|
+
template_file = Pathname.new(File.dirname(__FILE__)).join(template_file_name)
|
24
|
+
|
25
|
+
Tilt.new(template_file).render(TemplateContext.new)
|
26
|
+
end
|
27
|
+
|
28
|
+
def extension
|
29
|
+
match = file.match(/\.[\w]+$/)
|
30
|
+
raise NoValidExtensionError if match.blank?
|
31
|
+
match[0]
|
32
|
+
end
|
33
|
+
|
34
|
+
def template_name
|
35
|
+
TEMPLATE_BY_EXTENSION.fetch(extension) do
|
36
|
+
raise NoValidExtensionError
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def config_file
|
41
|
+
Pathname.new(Dir.pwd).join('spec/api/restspec/restspec_config.rb')
|
42
|
+
end
|
43
|
+
|
44
|
+
class TemplateContext
|
45
|
+
def namespace_store
|
46
|
+
Restspec::NamespaceStore
|
47
|
+
end
|
48
|
+
|
49
|
+
def endpoints_store
|
50
|
+
Restspec::EndpointStore
|
51
|
+
end
|
52
|
+
|
53
|
+
def schema_store
|
54
|
+
Restspec::SchemaStore
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
class NoValidExtensionError < StandardError
|
59
|
+
ERROR_MESSAGE = "ERROR: The file passed as argument does not include a valid extension"
|
60
|
+
|
61
|
+
def initialize(msg = ERROR_MESSAGE)
|
62
|
+
super(msg)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# API
|
2
|
+
## Hello World
|
3
|
+
|
4
|
+
<% namespace_store.each do |namespace| %>
|
5
|
+
## <%= namespace.name.capitalize %>
|
6
|
+
|
7
|
+
<% namespace.all_endpoints.each do |endpoint| %>
|
8
|
+
### <%= endpoint.name.capitalize %> [<%= endpoint.method.upcase %> <%= endpoint.full_path %>]
|
9
|
+
|
10
|
+
Returns schema **<%= endpoint.schema_name %>**
|
11
|
+
|
12
|
+
<% schema = schema_store.get(endpoint.schema_name) %>
|
13
|
+
|
14
|
+
| Attribute | Type | Example |
|
15
|
+
|-------------|:--------------------------:|---------------:|
|
16
|
+
<% schema.attributes.each do |name, attribute| %>
|
17
|
+
| <%= name %> | <%= attribute.type.to_s %> | <%= attribute.type.example_for(attribute) %> |
|
18
|
+
<% end %>
|
19
|
+
|
20
|
+
<% end %>
|
21
|
+
|
22
|
+
<% end %>
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module Restspec
|
2
|
+
class InstallRunner < Thor::Group
|
3
|
+
include Thor::Actions
|
4
|
+
|
5
|
+
argument :project
|
6
|
+
|
7
|
+
class_option :api_prefix, :desc => "api prefix to use", :required => true
|
8
|
+
|
9
|
+
def self.source_root
|
10
|
+
File.dirname(__FILE__)
|
11
|
+
end
|
12
|
+
|
13
|
+
def create_project_dir
|
14
|
+
empty_directory project
|
15
|
+
end
|
16
|
+
|
17
|
+
def copy_gemfile
|
18
|
+
copy_file 'templates/Gemfile', "#{project}/Gemfile"
|
19
|
+
end
|
20
|
+
|
21
|
+
def create_spec_folders
|
22
|
+
empty_directory "#{project}/spec"
|
23
|
+
empty_directory "#{project}/spec/api"
|
24
|
+
empty_directory "#{project}/spec/support"
|
25
|
+
end
|
26
|
+
|
27
|
+
def create_spec_helper
|
28
|
+
template 'templates/spec_helper.rb', "#{project}/spec/spec_helper.rb"
|
29
|
+
end
|
30
|
+
|
31
|
+
def create_rspec_config
|
32
|
+
template 'templates/restspec_config.rb', "#{project}/spec/api/restspec/restspec_config.rb"
|
33
|
+
end
|
34
|
+
|
35
|
+
def create_api_dsl_files
|
36
|
+
create_file "#{project}/spec/api/restspec/api_endpoints.rb"
|
37
|
+
create_file "#{project}/spec/api/restspec/api_schemas.rb"
|
38
|
+
create_file "#{project}/spec/api/restspec/api_requirements.rb"
|
39
|
+
end
|
40
|
+
|
41
|
+
def create_support_files
|
42
|
+
create_file "#{project}/spec/support/custom_matchers.rb"
|
43
|
+
copy_file "templates/custom_macros.rb", "#{project}/spec/support/custom_macros.rb"
|
44
|
+
end
|
45
|
+
|
46
|
+
def install_gems
|
47
|
+
inside(project) { run 'bundle install' }
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/lib/restspec/version.rb
CHANGED
data/restspec.gemspec
CHANGED
@@ -18,7 +18,6 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_development_dependency "bundler", "~> 1.7"
|
22
21
|
spec.add_development_dependency "rake", "~> 10.0"
|
23
22
|
spec.add_development_dependency "pry", "~> 0.10"
|
24
23
|
spec.add_development_dependency "guard", "~> 2.8"
|
@@ -34,4 +33,5 @@ Gem::Specification.new do |spec|
|
|
34
33
|
spec.add_dependency "rspec-its", "~> 1.0"
|
35
34
|
spec.add_dependency "rspec-collection_matchers", "~> 1.0"
|
36
35
|
spec.add_dependency "thor", "~> 0.19"
|
36
|
+
spec.add_dependency "tilt", "~> 2.0"
|
37
37
|
end
|
@@ -25,6 +25,12 @@ describe Namespace do
|
|
25
25
|
namespace.children_namespaces.size
|
26
26
|
}.by(1)
|
27
27
|
end
|
28
|
+
|
29
|
+
it "doesn't add a namespace to the namespace store" do
|
30
|
+
expect { namespace.add_anonymous_children_namespace }.to_not change {
|
31
|
+
Restspec::NamespaceStore.size
|
32
|
+
}
|
33
|
+
end
|
28
34
|
end
|
29
35
|
|
30
36
|
describe '#add_endpoint' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: restspec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- juliogarciag
|
@@ -10,20 +10,6 @@ bindir: bin
|
|
10
10
|
cert_chain: []
|
11
11
|
date: 2014-12-20 00:00:00.000000000 Z
|
12
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.7'
|
20
|
-
type: :development
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ~>
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '1.7'
|
27
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: rake
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
@@ -234,6 +220,20 @@ dependencies:
|
|
234
220
|
- - ~>
|
235
221
|
- !ruby/object:Gem::Version
|
236
222
|
version: '0.19'
|
223
|
+
- !ruby/object:Gem::Dependency
|
224
|
+
name: tilt
|
225
|
+
requirement: !ruby/object:Gem::Requirement
|
226
|
+
requirements:
|
227
|
+
- - ~>
|
228
|
+
- !ruby/object:Gem::Version
|
229
|
+
version: '2.0'
|
230
|
+
type: :runtime
|
231
|
+
prerelease: false
|
232
|
+
version_requirements: !ruby/object:Gem::Requirement
|
233
|
+
requirements:
|
234
|
+
- - ~>
|
235
|
+
- !ruby/object:Gem::Version
|
236
|
+
version: '2.0'
|
237
237
|
description: RSpec macros, helpers and matchers to work with APIs
|
238
238
|
email:
|
239
239
|
- julioggonz@gmail.com
|
@@ -254,10 +254,6 @@ files:
|
|
254
254
|
- ROADMAP.md
|
255
255
|
- Rakefile
|
256
256
|
- bin/restspec
|
257
|
-
- bin/templates/Gemfile
|
258
|
-
- bin/templates/custom_macros.rb
|
259
|
-
- bin/templates/restspec_config.rb
|
260
|
-
- bin/templates/spec_helper.rb
|
261
257
|
- docs/endpoints.md
|
262
258
|
- docs/helpers.md
|
263
259
|
- docs/macros.md
|
@@ -384,7 +380,6 @@ files:
|
|
384
380
|
- examples/store-api/vendor/assets/stylesheets/.keep
|
385
381
|
- lib/restspec.rb
|
386
382
|
- lib/restspec/configuration.rb
|
387
|
-
- lib/restspec/doc_generators/markdown.rb
|
388
383
|
- lib/restspec/endpoints/dsl.rb
|
389
384
|
- lib/restspec/endpoints/endpoint.rb
|
390
385
|
- lib/restspec/endpoints/namespace.rb
|
@@ -403,8 +398,13 @@ files:
|
|
403
398
|
- lib/restspec/rspec/matchers/have_status.rb
|
404
399
|
- lib/restspec/rspec/matchers/include_where.rb
|
405
400
|
- lib/restspec/rspec/shared_examples.rb
|
406
|
-
- lib/restspec/runners/docs.rb
|
407
|
-
- lib/restspec/runners/
|
401
|
+
- lib/restspec/runners/docs/docs_runner.rb
|
402
|
+
- lib/restspec/runners/docs/templates/docs.md.erb
|
403
|
+
- lib/restspec/runners/install/install_runner.rb
|
404
|
+
- lib/restspec/runners/install/templates/Gemfile
|
405
|
+
- lib/restspec/runners/install/templates/custom_macros.rb
|
406
|
+
- lib/restspec/runners/install/templates/restspec_config.rb
|
407
|
+
- lib/restspec/runners/install/templates/spec_helper.rb
|
408
408
|
- lib/restspec/schema/attribute.rb
|
409
409
|
- lib/restspec/schema/attribute_example.rb
|
410
410
|
- lib/restspec/schema/checker.rb
|
@@ -434,7 +434,6 @@ files:
|
|
434
434
|
- lib/restspec/values/super_hash.rb
|
435
435
|
- lib/restspec/version.rb
|
436
436
|
- restspec.gemspec
|
437
|
-
- spec/restspec/doc_generators/markdown_spec.rb
|
438
437
|
- spec/restspec/endpoints/dsl_spec.rb
|
439
438
|
- spec/restspec/endpoints/endpoint_spec.rb
|
440
439
|
- spec/restspec/endpoints/namespace_spec.rb
|
@@ -477,7 +476,6 @@ signing_key:
|
|
477
476
|
specification_version: 4
|
478
477
|
summary: RSpec macros, helpers and matchers to work with APIs
|
479
478
|
test_files:
|
480
|
-
- spec/restspec/doc_generators/markdown_spec.rb
|
481
479
|
- spec/restspec/endpoints/dsl_spec.rb
|
482
480
|
- spec/restspec/endpoints/endpoint_spec.rb
|
483
481
|
- spec/restspec/endpoints/namespace_spec.rb
|
@@ -1,65 +0,0 @@
|
|
1
|
-
module Restspec
|
2
|
-
module DocGenerators
|
3
|
-
class Markdown
|
4
|
-
attr_reader :markdown_string
|
5
|
-
|
6
|
-
def initialize
|
7
|
-
self.markdown_string = ''
|
8
|
-
end
|
9
|
-
|
10
|
-
def generate
|
11
|
-
generate_app_header
|
12
|
-
|
13
|
-
ns_store.each do |ns|
|
14
|
-
markdown_string << "## #{ns.name.capitalize}\n"
|
15
|
-
generate_endpoints(ns)
|
16
|
-
markdown_string << "\n"
|
17
|
-
end
|
18
|
-
|
19
|
-
markdown_string
|
20
|
-
end
|
21
|
-
|
22
|
-
private
|
23
|
-
|
24
|
-
attr_writer :markdown_string
|
25
|
-
|
26
|
-
def generate_app_header
|
27
|
-
markdown_string << "# API\n\n"
|
28
|
-
end
|
29
|
-
|
30
|
-
def generate_endpoints(ns)
|
31
|
-
ns.all_endpoints.each do |endpoint|
|
32
|
-
markdown_string << "### #{endpoint.name.capitalize} [#{endpoint.method.upcase} #{endpoint.full_path}]\n"
|
33
|
-
markdown_string << "Returns schema **#{endpoint.schema_name}**:\n"
|
34
|
-
|
35
|
-
generate_schema_table(endpoint.schema_name)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
def generate_schema_table(schema_name)
|
40
|
-
schema = schema_store.get(schema_name)
|
41
|
-
|
42
|
-
markdown_string << "
|
43
|
-
| Attribute | Type | Example |
|
44
|
-
|-----------|:-------------:|--------:|
|
45
|
-
#{
|
46
|
-
schema.attributes.map do |name, attribute|
|
47
|
-
"| #{name} | #{attribute.type.to_s} | #{attribute.type.example_for(attribute)} |"
|
48
|
-
end.join("\n")
|
49
|
-
}\n\n"
|
50
|
-
end
|
51
|
-
|
52
|
-
def ns_store
|
53
|
-
Restspec::NamespaceStore.uniq { |ns| ns.name }
|
54
|
-
end
|
55
|
-
|
56
|
-
def endpoints_store
|
57
|
-
Restspec::EndpointStore
|
58
|
-
end
|
59
|
-
|
60
|
-
def schema_store
|
61
|
-
Restspec::SchemaStore
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
class RestspecDocs < Thor::Group
|
2
|
-
include Thor::Actions
|
3
|
-
|
4
|
-
argument :file
|
5
|
-
|
6
|
-
def generate_docs
|
7
|
-
require 'restspec'
|
8
|
-
require config_file
|
9
|
-
require 'restspec/doc_generators/markdown'
|
10
|
-
|
11
|
-
generator = Restspec::DocGenerators::Markdown.new
|
12
|
-
File.write(file, generator.generate)
|
13
|
-
end
|
14
|
-
|
15
|
-
private
|
16
|
-
|
17
|
-
def config_file
|
18
|
-
Pathname.new(Dir.pwd).join('spec/api/restspec/restspec_config.rb')
|
19
|
-
end
|
20
|
-
end
|
@@ -1,48 +0,0 @@
|
|
1
|
-
class RestspecInstaller < Thor::Group
|
2
|
-
include Thor::Actions
|
3
|
-
|
4
|
-
argument :project
|
5
|
-
|
6
|
-
class_option :api_prefix, :desc => "api prefix to use", :required => true
|
7
|
-
|
8
|
-
def self.source_root
|
9
|
-
Pathname.new(File.dirname(__FILE__)).join('../../../bin')
|
10
|
-
end
|
11
|
-
|
12
|
-
def create_project_dir
|
13
|
-
empty_directory project
|
14
|
-
end
|
15
|
-
|
16
|
-
def copy_gemfile
|
17
|
-
copy_file 'templates/Gemfile', "#{project}/Gemfile"
|
18
|
-
end
|
19
|
-
|
20
|
-
def create_spec_folders
|
21
|
-
empty_directory "#{project}/spec"
|
22
|
-
empty_directory "#{project}/spec/api"
|
23
|
-
empty_directory "#{project}/spec/support"
|
24
|
-
end
|
25
|
-
|
26
|
-
def create_spec_helper
|
27
|
-
template 'templates/spec_helper.rb', "#{project}/spec/spec_helper.rb"
|
28
|
-
end
|
29
|
-
|
30
|
-
def create_rspec_config
|
31
|
-
template 'templates/restspec_config.rb', "#{project}/spec/api/restspec/restspec_config.rb"
|
32
|
-
end
|
33
|
-
|
34
|
-
def create_api_dsl_files
|
35
|
-
create_file "#{project}/spec/api/restspec/api_endpoints.rb"
|
36
|
-
create_file "#{project}/spec/api/restspec/api_schemas.rb"
|
37
|
-
create_file "#{project}/spec/api/restspec/api_requirements.rb"
|
38
|
-
end
|
39
|
-
|
40
|
-
def create_support_files
|
41
|
-
create_file "#{project}/spec/support/custom_matchers.rb"
|
42
|
-
copy_file "templates/custom_macros.rb", "#{project}/spec/support/custom_macros.rb"
|
43
|
-
end
|
44
|
-
|
45
|
-
def install_gems
|
46
|
-
inside(project) { run 'bundle install' }
|
47
|
-
end
|
48
|
-
end
|
@@ -1,88 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'restspec'
|
3
|
-
require 'restspec/doc_generators/markdown'
|
4
|
-
|
5
|
-
def clear_stores
|
6
|
-
Restspec::NamespaceStore.clear
|
7
|
-
Restspec::EndpointStore.clear
|
8
|
-
Restspec::SchemaStore.clear
|
9
|
-
end
|
10
|
-
|
11
|
-
def populate_endpoints
|
12
|
-
Restspec::Endpoints::DSL.new.instance_eval do
|
13
|
-
resource :products do
|
14
|
-
schema :product
|
15
|
-
|
16
|
-
collection do
|
17
|
-
post :create
|
18
|
-
get :index do
|
19
|
-
schema :product, without: [:category]
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
member do
|
24
|
-
url_param(:id) { schema_id(:product) }
|
25
|
-
|
26
|
-
get :show
|
27
|
-
put :update
|
28
|
-
delete :destroy
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
resource :categories do
|
33
|
-
schema :category
|
34
|
-
|
35
|
-
collection do
|
36
|
-
post :create
|
37
|
-
get :index
|
38
|
-
end
|
39
|
-
|
40
|
-
member do
|
41
|
-
url_param(:id) { schema_id(:category) }
|
42
|
-
|
43
|
-
get :show
|
44
|
-
put :update
|
45
|
-
delete :destroy
|
46
|
-
|
47
|
-
get :products, '/products' do
|
48
|
-
schema :product
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
def populate_schemas
|
56
|
-
Restspec::Schema::DSL.new.instance_eval do
|
57
|
-
schema :product do
|
58
|
-
attribute :name, string
|
59
|
-
attribute :code, string
|
60
|
-
attribute :price, decimal | decimal_string
|
61
|
-
attribute :category_id, schema_id(:category)
|
62
|
-
attribute :category, embedded_schema(:category), :for => [:checks]
|
63
|
-
end
|
64
|
-
|
65
|
-
schema :category do
|
66
|
-
attribute :name, string
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
describe Restspec::DocGenerators::Markdown do
|
72
|
-
before do
|
73
|
-
clear_stores
|
74
|
-
populate_schemas
|
75
|
-
populate_endpoints
|
76
|
-
end
|
77
|
-
|
78
|
-
let(:generator) { Restspec::DocGenerators::Markdown.new }
|
79
|
-
|
80
|
-
describe '#generate' do
|
81
|
-
it 'only happens for exploration' do
|
82
|
-
# require 'pry'; binding.pry
|
83
|
-
puts "\n" * 3
|
84
|
-
puts generator.generate
|
85
|
-
puts "\n" * 3
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|