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.
data/spec/opushon_spec.rb CHANGED
@@ -1,353 +1,343 @@
1
1
  require_relative 'spec_helper'
2
2
 
3
3
  describe Opushon do
4
- describe '.load' do
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
- let :options_issues do
16
- Opushon.load('{
17
- "GET": {
18
- "title": "List issues",
19
- "description": "List all issues across all the authenticated user\'s visible repositories.",
20
- "query_string": {
21
- "page": {
22
- "type": "number",
23
- "description": "Identify the page to return.",
24
- "min": 1,
25
- "max": null,
26
- "step": 1
27
- },
28
- "per_page": {
29
- "type": "number",
30
- "description": "Indicate the number of issues per page.",
31
- "min": 1,
32
- "max": 100,
33
- "step": 1
34
- },
35
- "state": {
36
- "description": "Indicates the state of the issues to return.",
37
- "options": {
38
- "open": "Open",
39
- "closed": "Closed",
40
- "all": "All"
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
- "default": "open",
43
- "multiple": true,
44
- "nullifiable": true
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
- "parameters": {
48
- "created_at": {
49
- "type": "string",
50
- "description": "The datetime that the resource was created at.",
51
- "nullifiable": false
52
- },
53
- "title": {
54
- "type": "string",
55
- "description": "The title of the resource.",
56
- "maxlen": 255,
57
- "nullifiable": false
58
- },
59
- "body": {
60
- "type": "string",
61
- "description": "The body of the resource.",
62
- "maxlen": 10000,
63
- "nullifiable": true
64
- },
65
- "state": {
66
- "type": "string",
67
- "description": "Indicates the state of the issue.",
68
- "maxlen": 255,
69
- "options": {
70
- "open": "Open",
71
- "closed": "Closed",
72
- "all": "All"
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
- "multiple": false,
75
- "nullifiable": false
76
- }
77
- },
78
- "example": [
79
- {
80
- "created_at": "2014-01-01T01:01:01Z",
81
- "title": "Found a bug",
82
- "body": "I\'m having a problem with this.",
83
- "state": "open"
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
- "example": {
116
- "title": "Found a bug",
117
- "body": "I\'m having a problem with this.",
118
- "labels": [
119
- "label_1",
120
- "label_2"
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
- options_issues.to_h.must_equal({
165
- "GET"=>{
166
- "title"=>"List issues",
167
- "description"=>"List all issues across all the authenticated user's visible repositories.",
168
- "query_string"=>{
169
- "page"=>{
170
- "nullifiable"=>true,
171
- "multiple"=>false,
172
- "description"=>"Identify the page to return.",
173
- "options"=>nil,
174
- "default"=>0,
175
- "type"=>"number",
176
- "min"=>1,
177
- "max"=>nil,
178
- "step"=>1
179
- },
180
- "per_page"=>{
181
- "nullifiable"=>true,
182
- "multiple"=>false,
183
- "description"=>"Indicate the number of issues per page.",
184
- "options"=>nil,
185
- "default"=>0,
186
- "type"=>"number",
187
- "min"=>1,
188
- "max"=>100,
189
- "step"=>1
190
- },
191
- "state"=>{
192
- "nullifiable"=>true,
193
- "multiple"=>true,
194
- "description"=>"Indicates the state of the issues to return.",
195
- "options"=>{
196
- "open"=>"Open",
197
- "closed"=>"Closed",
198
- "all"=>"All"
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
- "default"=>"",
201
- "type"=>"string",
202
- "minlen"=>nil,
203
- "maxlen"=>nil,
204
- "pattern"=>nil
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
- "parameters"=>{
208
- "created_at"=>{
209
- "nullifiable"=>false,
210
- "multiple"=>false,
211
- "description"=>"The datetime that the resource was created at.",
212
- "options"=>nil,
213
- "default"=>"",
214
- "type"=>"string",
215
- "minlen"=>nil,
216
- "maxlen"=>nil,
217
- "pattern"=>nil
218
- },
219
- "title"=>{
220
- "nullifiable"=>false,
221
- "multiple"=>false,
222
- "description"=>"The title of the resource.",
223
- "options"=>nil,
224
- "default"=>"",
225
- "type"=>"string",
226
- "minlen"=>nil,
227
- "maxlen"=>255,
228
- "pattern"=>nil
229
- },
230
- "body"=>{
231
- "nullifiable"=>true,
232
- "multiple"=>false,
233
- "description"=>"The body of the resource.",
234
- "options"=>nil,
235
- "default"=>"",
236
- "type"=>"string",
237
- "minlen"=>nil,
238
- "maxlen"=>10000,
239
- "pattern"=>nil
240
- },
241
- "state"=>{
242
- "nullifiable"=>false,
243
- "multiple"=>false,
244
- "description"=>"Indicates the state of the issue.",
245
- "options"=>{
246
- "open"=>"Open",
247
- "closed"=>"Closed",
248
- "all"=>"All"
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
- "default"=>"",
251
- "type"=>"string",
252
- "minlen"=>nil,
253
- "maxlen"=>255,
254
- "pattern"=>nil
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
- "example"=>[
258
- {
259
- "created_at"=>"2014-01-01T01:01:01Z",
260
- "title"=>"Found a bug",
261
- "body"=>"I'm having a problem with this.",
262
- "state"=>"open"
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
- "default"=>"",
303
- "type"=>"string",
304
- "minlen"=>nil,
305
- "maxlen"=>nil,
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
- Opushon.dump({
346
- DELETE: {
347
- title: 'Delete issues',
348
- description: 'Remove every issues.'
349
- }
350
- }).must_equal('{"DELETE":{"title":"Delete issues","description":"Remove every issues."}}')
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