@@ -25,6 +25,9 @@ class Base < Grape::API
25
25
26
26
subject { described_class . new ( Api ::Base ) }
27
27
28
+ let ( :api_class ) { subject . send ( :api_class ) }
29
+ let ( :docs_url ) { subject . send ( :urls_for , api_class ) . first }
30
+
28
31
describe '.new' do
29
32
it 'accepts class name as a constant' do
30
33
expect ( described_class . new ( ::Api ::Base ) . send ( :api_class ) ) . to eq ( Api ::Base )
@@ -38,7 +41,7 @@ class Base < Grape::API
38
41
describe '#make_request' do
39
42
describe 'complete documentation' do
40
43
before do
41
- subject . send ( :make_request )
44
+ subject . send ( :make_request , docs_url )
42
45
end
43
46
44
47
describe 'not storing' do
@@ -51,7 +54,7 @@ class Base < Grape::API
51
54
end
52
55
53
56
it 'requests doc url' do
54
- expect ( subject . send ( :url_for ) ) . to eql '/api/swagger_doc'
57
+ expect ( docs_url ) . to eql '/api/swagger_doc'
55
58
end
56
59
end
57
60
@@ -68,10 +71,14 @@ class Base < Grape::API
68
71
describe 'documentation for resource' do
69
72
before do
70
73
ENV [ 'resource' ] = resource
71
- subject . send ( :make_request )
74
+ subject . send ( :make_request , docs_url )
72
75
end
73
76
74
- let ( :response ) { JSON . parse ( subject . send ( :make_request ) ) }
77
+ let ( :response ) do
78
+ JSON . parse (
79
+ subject . send ( :make_request , docs_url )
80
+ )
81
+ end
75
82
76
83
after { ENV . delete ( 'resource' ) }
77
84
@@ -83,7 +90,7 @@ class Base < Grape::API
83
90
end
84
91
85
92
it 'requests doc url' do
86
- expect ( subject . send ( :url_for ) ) . to eql "/api/swagger_doc/#{ resource } "
93
+ expect ( docs_url ) . to eql "/api/swagger_doc/#{ resource } "
87
94
end
88
95
89
96
it 'has only one resource path' do
@@ -115,7 +122,7 @@ class Base < Grape::API
115
122
116
123
describe 'call it' do
117
124
before do
118
- subject . send ( :make_request )
125
+ subject . send ( :make_request , docs_url )
119
126
end
120
127
specify do
121
128
expect ( subject ) . to respond_to :oapi
@@ -128,7 +135,7 @@ class Base < Grape::API
128
135
describe '#file' do
129
136
describe 'no store given' do
130
137
it 'returns swagger_doc.json' do
131
- expect ( subject . send ( :file ) ) . to end_with 'swagger_doc.json'
138
+ expect ( subject . send ( :file , docs_url ) ) . to end_with 'swagger_doc.json'
132
139
end
133
140
end
134
141
@@ -139,7 +146,7 @@ class Base < Grape::API
139
146
before { ENV [ 'store' ] = 'true' }
140
147
141
148
it 'returns swagger_doc.json' do
142
- expect ( subject . send ( :file ) ) . to end_with 'swagger_doc.json'
149
+ expect ( subject . send ( :file , docs_url ) ) . to end_with 'swagger_doc.json'
143
150
end
144
151
end
145
152
@@ -148,7 +155,7 @@ class Base < Grape::API
148
155
before { ENV [ 'store' ] = name }
149
156
150
157
it 'returns swagger_doc.json' do
151
- expect ( subject . send ( :file ) ) . to end_with name
158
+ expect ( subject . send ( :file , docs_url ) ) . to include ( name . split ( '.' ) [ 0 ] )
152
159
end
153
160
end
154
161
end
0 commit comments