opushon 0.0.1 → 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 +4 -4
- data/Rakefile +1 -2
- data/VERSION.semver +1 -1
- data/lib/opushon/error/min_is_greater_than_max_error.rb +8 -0
- data/lib/opushon/error/minlen_is_longer_than_maxlen_error.rb +8 -0
- data/lib/opushon/instance.rb +4 -13
- data/lib/opushon/option_object.rb +19 -39
- data/lib/opushon/parameter/base.rb +47 -0
- data/lib/opushon/parameter/input.rb +34 -0
- data/lib/opushon/parameter/output.rb +10 -0
- data/lib/opushon/parameter.rb +9 -0
- data/lib/opushon/restricted_value.rb +35 -0
- data/lib/opushon/type/array.rb +10 -0
- data/lib/opushon/type/base.rb +12 -5
- data/lib/opushon/type/boolean.rb +0 -3
- data/lib/opushon/type/hash.rb +10 -0
- data/lib/opushon/type/number.rb +15 -13
- data/lib/opushon/type/string.rb +18 -13
- data/lib/opushon/verb.rb +0 -2
- data/lib/opushon/version.rb +2 -0
- data/opushon.gemspec +0 -1
- data/spec/opushon/parameter/input_spec.rb +161 -0
- data/spec/opushon/parameter/output_spec.rb +108 -0
- data/spec/opushon/parameter/spec_helper.rb +1 -0
- data/spec/opushon/restricted_value_spec.rb +42 -0
- data/spec/opushon_spec.rb +313 -323
- data/spec/support/immutable.rb +13 -13
- metadata +19 -18
- data/lib/opushon/attribute.rb +0 -29
- data/lib/opushon/option.rb +0 -14
data/spec/opushon_spec.rb
CHANGED
@@ -1,353 +1,343 @@
|
|
1
1
|
require_relative 'spec_helper'
|
2
2
|
|
3
3
|
describe Opushon do
|
4
|
-
|
5
|
-
let :options_account do
|
6
|
-
Opushon.load('{
|
7
|
-
"DELETE": {
|
8
|
-
"title": "Delete account",
|
9
|
-
"description": "Remove my account please!!",
|
10
|
-
"foo": "bar"
|
11
|
-
}
|
12
|
-
}')
|
13
|
-
end
|
4
|
+
subject { Opushon }
|
14
5
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
"
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
6
|
+
describe '.load' do
|
7
|
+
let :opushon_string do
|
8
|
+
'{
|
9
|
+
"GET": {
|
10
|
+
"title": "List issues",
|
11
|
+
"description": "List all issues across all the authenticated user\'s visible repositories.",
|
12
|
+
"parameters": {
|
13
|
+
"input": {
|
14
|
+
"page": {
|
15
|
+
"type": "number",
|
16
|
+
"description": "Identify the page to return.",
|
17
|
+
"min": 1,
|
18
|
+
"max": null
|
19
|
+
},
|
20
|
+
"per_page": {
|
21
|
+
"type": "number",
|
22
|
+
"description": "Indicate the number of issues per page.",
|
23
|
+
"min": 1,
|
24
|
+
"max": 100
|
25
|
+
},
|
26
|
+
"state": {
|
27
|
+
"description": "Indicates the state of the issues to return.",
|
28
|
+
"restricted_values": [
|
29
|
+
{
|
30
|
+
"value": "open",
|
31
|
+
"title": "Open"
|
32
|
+
},
|
33
|
+
{
|
34
|
+
"value": "closed",
|
35
|
+
"title": "Closed"
|
36
|
+
},
|
37
|
+
{
|
38
|
+
"value": "all",
|
39
|
+
"title": "All"
|
40
|
+
}
|
41
|
+
],
|
42
|
+
"nullifiable": true
|
43
|
+
}
|
44
|
+
},
|
45
|
+
"output": {
|
46
|
+
"created_at": {
|
47
|
+
"type": "string",
|
48
|
+
"description": "The datetime that the resource was created at.",
|
49
|
+
"nullifiable": false
|
50
|
+
},
|
51
|
+
"title": {
|
52
|
+
"type": "string",
|
53
|
+
"description": "The title of the resource.",
|
54
|
+
"nullifiable": false
|
55
|
+
},
|
56
|
+
"body": {
|
57
|
+
"type": "string",
|
58
|
+
"description": "The body of the resource.",
|
59
|
+
"nullifiable": true
|
60
|
+
},
|
61
|
+
"state": {
|
62
|
+
"type": "string",
|
63
|
+
"description": "Indicates the state of the issue.",
|
64
|
+
"nullifiable": false
|
65
|
+
}
|
66
|
+
}
|
41
67
|
},
|
42
|
-
"
|
43
|
-
|
44
|
-
|
45
|
-
|
68
|
+
"examples": {
|
69
|
+
"input": null,
|
70
|
+
"output": [
|
71
|
+
{
|
72
|
+
"created_at": "2014-01-01T01:01:01Z",
|
73
|
+
"title": "Found a bug",
|
74
|
+
"body": "I\'m having a problem with this.",
|
75
|
+
"state": "open"
|
76
|
+
}
|
77
|
+
]
|
78
|
+
}
|
46
79
|
},
|
47
|
-
"
|
48
|
-
|
49
|
-
"
|
50
|
-
"
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
80
|
+
"POST": {
|
81
|
+
"title": "Create an issue",
|
82
|
+
"description": "Any user with pull access to a repository can create an issue.",
|
83
|
+
"parameters": {
|
84
|
+
"input": {
|
85
|
+
"title": {
|
86
|
+
"query_string": false,
|
87
|
+
"type": "string",
|
88
|
+
"description": "Issue title.",
|
89
|
+
"maxlen": 255,
|
90
|
+
"nullifiable": false
|
91
|
+
},
|
92
|
+
"body": {
|
93
|
+
"query_string": false,
|
94
|
+
"type": "string",
|
95
|
+
"description": "Issue body.",
|
96
|
+
"nullifiable": true
|
97
|
+
},
|
98
|
+
"labels": {
|
99
|
+
"query_string": false,
|
100
|
+
"type": "string",
|
101
|
+
"description": "Labels to associate with this issue.",
|
102
|
+
"nullifiable": true,
|
103
|
+
"restricted_values": [
|
104
|
+
{
|
105
|
+
"value": "label_1",
|
106
|
+
"title": "Java"
|
107
|
+
},
|
108
|
+
{
|
109
|
+
"value": "label_2",
|
110
|
+
"title": "Ruby"
|
111
|
+
},
|
112
|
+
{
|
113
|
+
"value": "label_3",
|
114
|
+
"title": "Elixir"
|
115
|
+
}
|
116
|
+
]
|
117
|
+
}
|
118
|
+
},
|
119
|
+
"output": null
|
73
120
|
},
|
74
|
-
"
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
}
|
85
|
-
]
|
86
|
-
},
|
87
|
-
"POST": {
|
88
|
-
"title": "Create an issue",
|
89
|
-
"description": "Any user with pull access to a repository can create an issue.",
|
90
|
-
"query_string": {},
|
91
|
-
"parameters": {
|
92
|
-
"title": {
|
93
|
-
"type": "string",
|
94
|
-
"description": "Issue title.",
|
95
|
-
"maxlen": 255,
|
96
|
-
"nullifiable": false
|
97
|
-
},
|
98
|
-
"body": {
|
99
|
-
"type": "string",
|
100
|
-
"description": "Issue body.",
|
101
|
-
"nullifiable": true
|
102
|
-
},
|
103
|
-
"labels": {
|
104
|
-
"type": "string",
|
105
|
-
"description": "Labels to associate with this issue.",
|
106
|
-
"multiple": true,
|
107
|
-
"nullifiable": true,
|
108
|
-
"options": {
|
109
|
-
"label_1": "Java",
|
110
|
-
"label_2": "Ruby",
|
111
|
-
"label_3": "Elixir"
|
121
|
+
"examples": {
|
122
|
+
"input": {
|
123
|
+
"title": "Found a bug",
|
124
|
+
"body": "I\'m having a problem with this.",
|
125
|
+
"labels": [
|
126
|
+
"label_1",
|
127
|
+
"label_2"
|
128
|
+
]
|
129
|
+
},
|
130
|
+
"output": null
|
112
131
|
}
|
113
|
-
}
|
114
132
|
},
|
115
|
-
"
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
133
|
+
"DELETE": {
|
134
|
+
"title": "Delete issues",
|
135
|
+
"description": "Remove every issues.",
|
136
|
+
"parameters": {
|
137
|
+
"input": null,
|
138
|
+
"output": null
|
139
|
+
},
|
140
|
+
"examples": {
|
141
|
+
"input": null,
|
142
|
+
"output": null
|
143
|
+
}
|
122
144
|
}
|
123
|
-
|
124
|
-
"DELETE": {
|
125
|
-
"title": "Delete issues",
|
126
|
-
"description": "Remove every issues."
|
127
|
-
}
|
128
|
-
}')
|
129
|
-
end
|
130
|
-
|
131
|
-
it 'MUST raise a JSON parser error' do
|
132
|
-
lambda do
|
133
|
-
Opushon.load('{"DELETE":{"title":"Delete issues"')
|
134
|
-
end.must_raise(JSON::ParserError)
|
135
|
-
end
|
136
|
-
|
137
|
-
it 'MUST raise a Opushon syntax error' do
|
138
|
-
lambda do
|
139
|
-
Opushon.load('["BOOM"]')
|
140
|
-
end.must_raise(Opushon::SyntaxError)
|
141
|
-
end
|
142
|
-
|
143
|
-
it 'MUST raise a Opushon verb error' do
|
144
|
-
lambda do
|
145
|
-
Opushon.load('{"BOOM":{}}')
|
146
|
-
end.must_raise(Opushon::VerbError)
|
145
|
+
}'
|
147
146
|
end
|
148
147
|
|
149
148
|
describe '#to_h' do
|
150
|
-
it 'MUST load opushon in to a Ruby data structure' do
|
151
|
-
options_account.to_h.must_equal({
|
152
|
-
'DELETE' => {
|
153
|
-
'title' => 'Delete account',
|
154
|
-
'description' => 'Remove my account please!!',
|
155
|
-
'query_string' => {},
|
156
|
-
'parameters' => {},
|
157
|
-
'example' => nil,
|
158
|
-
'foo' => 'bar'
|
159
|
-
}
|
160
|
-
})
|
161
|
-
end
|
162
|
-
|
163
149
|
it 'MUST load opushon having query_string and parameters' do
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
150
|
+
subject.load(opushon_string).to_h.must_equal({
|
151
|
+
:GET=>{
|
152
|
+
:title=>"List issues",
|
153
|
+
:description=>"List all issues across all the authenticated user's visible repositories.",
|
154
|
+
:parameters=>{
|
155
|
+
:input=>{
|
156
|
+
:page=>{
|
157
|
+
:query_string=>true,
|
158
|
+
:restricted_values=>nil,
|
159
|
+
:title=>"",
|
160
|
+
:description=>"Identify the page to return.",
|
161
|
+
:nullifiable=>true,
|
162
|
+
:type=>"number",
|
163
|
+
:min=>1,
|
164
|
+
:max=>nil
|
165
|
+
},
|
166
|
+
:per_page=>{
|
167
|
+
:query_string=>true,
|
168
|
+
:restricted_values=>nil,
|
169
|
+
:title=>"",
|
170
|
+
:description=>"Indicate the number of issues per page.",
|
171
|
+
:nullifiable=>true,
|
172
|
+
:type=>"number",
|
173
|
+
:min=>1,
|
174
|
+
:max=>100
|
175
|
+
},
|
176
|
+
:state=>{
|
177
|
+
:query_string=>true,
|
178
|
+
:restricted_values=>[
|
179
|
+
{
|
180
|
+
:title=>"Open",
|
181
|
+
:description=>"",
|
182
|
+
:value=>"open"
|
183
|
+
},
|
184
|
+
{
|
185
|
+
:title=>"Closed",
|
186
|
+
:description=>"",
|
187
|
+
:value=>"closed"
|
188
|
+
},
|
189
|
+
{
|
190
|
+
:title=>"All",
|
191
|
+
:description=>"",
|
192
|
+
:value=>"all"
|
193
|
+
}
|
194
|
+
],
|
195
|
+
:title=>"",
|
196
|
+
:description=>"Indicates the state of the issues to return.",
|
197
|
+
:nullifiable=>true,
|
198
|
+
:type=>"string",
|
199
|
+
:minlen=>nil,
|
200
|
+
:maxlen=>nil,
|
201
|
+
:pattern=>nil
|
202
|
+
}
|
203
|
+
},
|
204
|
+
:output=>{
|
205
|
+
:created_at=>{
|
206
|
+
:title=>"",
|
207
|
+
:description=>"The datetime that the resource was created at.",
|
208
|
+
:nullifiable=>false,
|
209
|
+
:type=>"string"
|
210
|
+
},
|
211
|
+
:title=>{
|
212
|
+
:title=>"",
|
213
|
+
:description=>"The title of the resource.",
|
214
|
+
:nullifiable=>false,
|
215
|
+
:type=>"string"
|
216
|
+
},
|
217
|
+
:body=>{
|
218
|
+
:title=>"",
|
219
|
+
:description=>"The body of the resource.",
|
220
|
+
:nullifiable=>true,
|
221
|
+
:type=>"string"
|
222
|
+
},
|
223
|
+
:state=>{
|
224
|
+
:title=>"",
|
225
|
+
:description=>"Indicates the state of the issue.",
|
226
|
+
:nullifiable=>false,
|
227
|
+
:type=>"string"
|
228
|
+
}
|
229
|
+
}
|
199
230
|
},
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
231
|
+
:examples=>{
|
232
|
+
:input=>nil,
|
233
|
+
:output=>[
|
234
|
+
{
|
235
|
+
:created_at=>"2014-01-01T01:01:01Z",
|
236
|
+
:title=>"Found a bug",
|
237
|
+
:body=>"I'm having a problem with this.",
|
238
|
+
:state=>"open"
|
239
|
+
}
|
240
|
+
]
|
241
|
+
}
|
206
242
|
},
|
207
|
-
|
208
|
-
|
209
|
-
"
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
243
|
+
:POST=>{
|
244
|
+
:title=>"Create an issue",
|
245
|
+
:description=>"Any user with pull access to a repository can create an issue.",
|
246
|
+
:parameters=>{
|
247
|
+
:input=>{
|
248
|
+
:title=>{
|
249
|
+
:query_string=>false,
|
250
|
+
:restricted_values=>nil,
|
251
|
+
:title=>"",
|
252
|
+
:description=>"Issue title.",
|
253
|
+
:nullifiable=>false,
|
254
|
+
:type=>"string",
|
255
|
+
:minlen=>nil,
|
256
|
+
:maxlen=>255,
|
257
|
+
:pattern=>nil
|
258
|
+
},
|
259
|
+
:body=>{
|
260
|
+
:query_string=>false,
|
261
|
+
:restricted_values=>nil,
|
262
|
+
:title=>"",
|
263
|
+
:description=>"Issue body.",
|
264
|
+
:nullifiable=>true,
|
265
|
+
:type=>"string",
|
266
|
+
:minlen=>nil,
|
267
|
+
:maxlen=>nil,
|
268
|
+
:pattern=>nil
|
269
|
+
},
|
270
|
+
:labels=>{
|
271
|
+
:query_string=>false,
|
272
|
+
:restricted_values=>[
|
273
|
+
{
|
274
|
+
:title=>"Java",
|
275
|
+
:description=>"",
|
276
|
+
:value=>"label_1"
|
277
|
+
},
|
278
|
+
{
|
279
|
+
:title=>"Ruby",
|
280
|
+
:description=>"",
|
281
|
+
:value=>"label_2"
|
282
|
+
},
|
283
|
+
{
|
284
|
+
:title=>"Elixir",
|
285
|
+
:description=>"",
|
286
|
+
:value=>"label_3"
|
287
|
+
}
|
288
|
+
],
|
289
|
+
:title=>"",
|
290
|
+
:description=>"Labels to associate with this issue.",
|
291
|
+
:nullifiable=>true,
|
292
|
+
:type=>"string",
|
293
|
+
:minlen=>nil,
|
294
|
+
:maxlen=>nil,
|
295
|
+
:pattern=>nil
|
296
|
+
}
|
297
|
+
},
|
298
|
+
:output=>nil
|
249
299
|
},
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
300
|
+
:examples=>{
|
301
|
+
:input=>{
|
302
|
+
:title=>"Found a bug",
|
303
|
+
:body=>"I'm having a problem with this.",
|
304
|
+
:labels=>[
|
305
|
+
"label_1",
|
306
|
+
"label_2"
|
307
|
+
]
|
308
|
+
},
|
309
|
+
:output=>nil
|
310
|
+
}
|
256
311
|
},
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
}
|
264
|
-
]
|
265
|
-
},
|
266
|
-
"POST"=>{
|
267
|
-
"title"=>"Create an issue",
|
268
|
-
"description"=>"Any user with pull access to a repository can create an issue.",
|
269
|
-
"query_string"=>{},
|
270
|
-
"parameters"=>{
|
271
|
-
"title"=>{
|
272
|
-
"nullifiable"=>false,
|
273
|
-
"multiple"=>false,
|
274
|
-
"description"=>"Issue title.",
|
275
|
-
"options"=>nil,
|
276
|
-
"default"=>"",
|
277
|
-
"type"=>"string",
|
278
|
-
"minlen"=>nil,
|
279
|
-
"maxlen"=>255,
|
280
|
-
"pattern"=>nil
|
281
|
-
},
|
282
|
-
"body"=>{
|
283
|
-
"nullifiable"=>true,
|
284
|
-
"multiple"=>false,
|
285
|
-
"description"=>"Issue body.",
|
286
|
-
"options"=>nil,
|
287
|
-
"default"=>"",
|
288
|
-
"type"=>"string",
|
289
|
-
"minlen"=>nil,
|
290
|
-
"maxlen"=>nil,
|
291
|
-
"pattern"=>nil
|
292
|
-
},
|
293
|
-
"labels"=>{
|
294
|
-
"nullifiable"=>true,
|
295
|
-
"multiple"=>true,
|
296
|
-
"description"=>"Labels to associate with this issue.",
|
297
|
-
"options"=>{
|
298
|
-
"label_1"=>"Java",
|
299
|
-
"label_2"=>"Ruby",
|
300
|
-
"label_3"=>"Elixir"
|
312
|
+
:DELETE=>{
|
313
|
+
:title=>"Delete issues",
|
314
|
+
:description=>"Remove every issues.",
|
315
|
+
:parameters=>{
|
316
|
+
:input=>nil,
|
317
|
+
:output=>nil
|
301
318
|
},
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
"pattern"=>nil
|
307
|
-
}
|
308
|
-
},
|
309
|
-
"example"=>{
|
310
|
-
"title"=>"Found a bug",
|
311
|
-
"body"=>"I'm having a problem with this.",
|
312
|
-
"labels"=>[
|
313
|
-
"label_1",
|
314
|
-
"label_2"
|
315
|
-
]
|
319
|
+
:examples=>{
|
320
|
+
:input=>nil,
|
321
|
+
:output=>nil
|
322
|
+
}
|
316
323
|
}
|
317
|
-
},
|
318
|
-
"DELETE"=>{
|
319
|
-
"title"=>"Delete issues",
|
320
|
-
"description"=>"Remove every issues.",
|
321
|
-
"query_string"=>{},
|
322
|
-
"parameters"=>{},
|
323
|
-
"example"=>nil
|
324
|
-
}
|
325
324
|
})
|
326
325
|
end
|
327
326
|
end
|
328
|
-
|
329
|
-
describe '#valid?' do
|
330
|
-
it 'MUST valid the Ruby object o to a Opushon string' do
|
331
|
-
options_issues.valid?(:POST, {
|
332
|
-
"title" => "Found a bug",
|
333
|
-
"body" => "I'm having a problem with this.",
|
334
|
-
"labels" => [
|
335
|
-
"label_1",
|
336
|
-
"label_2"
|
337
|
-
]
|
338
|
-
}).must_equal(true)
|
339
|
-
end
|
340
|
-
end
|
341
327
|
end
|
342
328
|
|
343
329
|
describe '.dump' do
|
344
330
|
it 'MUST dump Ruby object o to a Opushon string' do
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
331
|
+
JSON.load(
|
332
|
+
Opushon.dump({
|
333
|
+
DELETE: {
|
334
|
+
title: 'Delete issues',
|
335
|
+
description: 'Remove every issues.'
|
336
|
+
}
|
337
|
+
})
|
338
|
+
).must_equal(
|
339
|
+
JSON.load("{\"DELETE\":{\"title\":\"Delete issues\",\"description\":\"Remove every issues.\"}}")
|
340
|
+
)
|
351
341
|
end
|
352
342
|
end
|
353
343
|
end
|