@@ -68,47 +68,95 @@ def app
68
68
GuardedApi
69
69
end
70
70
71
- context 'when a correct token is passed with the request' do
72
- subject do
73
- get '/swagger_doc.json' , { } , 'HTTP_AUTHORIZATION' => '12345'
74
- JSON . parse ( last_response . body )
75
- end
71
+ let ( :endpoint ) { '/swagger_doc.json' }
72
+ let ( :auth_token ) { nil }
73
+
74
+ subject do
75
+ get endpoint , { } , 'HTTP_AUTHORIZATION' => auth_token
76
+ JSON . parse ( last_response . body )
77
+ end
76
78
77
- it 'retrieves swagger-documentation for the endpoint' do
78
- expect ( subject ) . to eq (
79
- 'info' => { 'title' => 'API title' , 'version' => '0.0.1' } ,
80
- 'swagger' => '2.0' ,
81
- 'produces' => [ 'application/xml' , 'application/json' , 'application/octet-stream' , 'text/plain' ] ,
82
- 'host' => 'example.org' ,
83
- 'tags' => [ { 'name' => 'auth' , 'description' => 'Operations about auths' } ] ,
84
- 'paths' => {
85
- '/auth' => {
86
- 'get' => {
87
- 'description' => 'Show endpoint if authenticated' ,
88
- 'produces' => [ 'application/json' ] ,
89
- 'tags' => [ 'auth' ] ,
90
- 'operationId' => 'getAuth' ,
91
- 'responses' => { '200' => { 'description' => 'Show endpoint if authenticated' } }
79
+ context 'accessing the main doc endpoint' do
80
+ let ( :endpoint ) { '/swagger_doc.json' }
81
+
82
+ context 'when a correct token is passed with the request' do
83
+ let ( :auth_token ) { '12345' }
84
+
85
+ it 'retrieves swagger-documentation for the endpoint' do
86
+ expect ( subject ) . to eq (
87
+ 'info' => { 'title' => 'API title' , 'version' => '0.0.1' } ,
88
+ 'swagger' => '2.0' ,
89
+ 'produces' => [ 'application/xml' , 'application/json' , 'application/octet-stream' , 'text/plain' ] ,
90
+ 'host' => 'example.org' ,
91
+ 'tags' => [ { 'name' => 'auth' , 'description' => 'Operations about auths' } ] ,
92
+ 'paths' => {
93
+ '/auth' => {
94
+ 'get' => {
95
+ 'description' => 'Show endpoint if authenticated' ,
96
+ 'produces' => [ 'application/json' ] ,
97
+ 'tags' => [ 'auth' ] ,
98
+ 'operationId' => 'getAuth' ,
99
+ 'responses' => { '200' => { 'description' => 'Show endpoint if authenticated' } }
100
+ }
92
101
}
93
102
}
94
- }
95
- )
103
+ )
104
+ end
105
+ end
106
+
107
+ context 'when a bad token is passed with the request' do
108
+ let ( :auth_token ) { '123456' }
109
+
110
+ it 'does not retrieve swagger-documentation for the endpoint - only the info_object' do
111
+ expect ( subject ) . to eq (
112
+ 'info' => { 'title' => 'API title' , 'version' => '0.0.1' } ,
113
+ 'swagger' => '2.0' ,
114
+ 'produces' => [ 'application/xml' , 'application/json' , 'application/octet-stream' , 'text/plain' ] ,
115
+ 'host' => 'example.org'
116
+ )
117
+ end
96
118
end
97
119
end
98
120
99
- context 'when a bad token is passed with the request' do
100
- subject do
101
- get '/swagger_doc.json' , { } , 'HTTP_AUTHORIZATION' => '123456'
102
- JSON . parse ( last_response . body )
121
+ context 'accessing the tag specific endpoint' do
122
+ let ( :endpoint ) { '/swagger_doc/auth.json' }
123
+
124
+ context 'when a correct token is passed with the request' do
125
+ let ( :auth_token ) { '12345' }
126
+
127
+ it 'retrieves swagger-documentation for the endpoint' do
128
+ expect ( subject ) . to eq (
129
+ 'info' => { 'title' => 'API title' , 'version' => '0.0.1' } ,
130
+ 'swagger' => '2.0' ,
131
+ 'produces' => [ 'application/xml' , 'application/json' , 'application/octet-stream' , 'text/plain' ] ,
132
+ 'host' => 'example.org' ,
133
+ 'tags' => [ { 'name' => 'auth' , 'description' => 'Operations about auths' } ] ,
134
+ 'paths' => {
135
+ '/auth' => {
136
+ 'get' => {
137
+ 'description' => 'Show endpoint if authenticated' ,
138
+ 'produces' => [ 'application/json' ] ,
139
+ 'tags' => [ 'auth' ] ,
140
+ 'operationId' => 'getAuth' ,
141
+ 'responses' => { '200' => { 'description' => 'Show endpoint if authenticated' } }
142
+ }
143
+ }
144
+ }
145
+ )
146
+ end
103
147
end
104
148
105
- it 'does not retrieve swagger-documentation for the endpoint - only the info_object' do
106
- expect ( subject ) . to eq (
107
- 'info' => { 'title' => 'API title' , 'version' => '0.0.1' } ,
108
- 'swagger' => '2.0' ,
109
- 'produces' => [ 'application/xml' , 'application/json' , 'application/octet-stream' , 'text/plain' ] ,
110
- 'host' => 'example.org'
111
- )
149
+ context 'when a bad token is passed with the request' do
150
+ let ( :auth_token ) { '123456' }
151
+
152
+ it 'does not retrieve swagger-documentation for the endpoint - only the info_object' do
153
+ expect ( subject ) . to eq (
154
+ 'info' => { 'title' => 'API title' , 'version' => '0.0.1' } ,
155
+ 'swagger' => '2.0' ,
156
+ 'produces' => [ 'application/xml' , 'application/json' , 'application/octet-stream' , 'text/plain' ] ,
157
+ 'host' => 'example.org'
158
+ )
159
+ end
112
160
end
113
161
end
114
162
end
0 commit comments