@@ -64,8 +64,43 @@ class Dummy
64
64
expect ( app2 . inheritable_setting . to_hash [ :namespace_stackable ] ) . to eq ( :mount_path => [ '/app1' , '/app2' ] )
65
65
end
66
66
end
67
- xdescribe '.route' do
68
- it 'does some thing'
67
+
68
+ describe '.route' do
69
+ before do
70
+ allow ( subject ) . to receive ( :endpoints ) . and_return ( [ ] )
71
+ allow ( subject ) . to receive ( :route_end )
72
+ allow ( subject ) . to receive ( :reset_validations! )
73
+ end
74
+
75
+ it 'marks end of the route' do
76
+ expect ( subject ) . to receive ( :route_end )
77
+ subject . route ( :any )
78
+ end
79
+
80
+ it 'resets validations' do
81
+ expect ( subject ) . to receive ( :reset_validations! )
82
+ subject . route ( :any )
83
+ end
84
+
85
+ it 'defines a new endpoint' do
86
+ expect { subject . route ( :any ) }
87
+ . to change { subject . endpoints . count } . from ( 0 ) . to ( 1 )
88
+ end
89
+
90
+ it 'generates correct endpoint options' do
91
+ allow ( subject ) . to receive ( :route_setting ) . with ( :description ) . and_return ( fiz : 'baz' )
92
+ allow ( Grape ::DSL ::Configuration ) . to receive ( :stacked_hash_to_hash ) . and_return ( nuz : 'naz' )
93
+
94
+ expect ( Grape ::Endpoint ) . to receive ( :new ) do |inheritable_setting , endpoint_options |
95
+ puts endpoint_options
96
+ expect ( endpoint_options [ :method ] ) . to eq :get
97
+ expect ( endpoint_options [ :path ] ) . to eq '/foo'
98
+ expect ( endpoint_options [ :for ] ) . to eq subject
99
+ expect ( endpoint_options [ :route_options ] ) . to eq ( foo : 'bar' , fiz : 'baz' , params : { nuz : 'naz' } )
100
+ end . and_yield
101
+
102
+ subject . route ( :get , '/foo' , { foo : 'bar' } , &proc { } )
103
+ end
69
104
end
70
105
71
106
describe '.get' do
@@ -117,32 +152,90 @@ class Dummy
117
152
end
118
153
end
119
154
120
- xdescribe '.namespace' do
121
- it 'does some thing'
155
+ describe '.namespace' do
156
+ let ( :new_namespace ) { Object . new }
157
+
158
+ it 'creates a new namespace with given name and options' do
159
+ expect ( subject ) . to receive ( :within_namespace ) . and_yield
160
+ expect ( subject ) . to receive ( :nest ) . and_yield
161
+ expect ( Namespace ) . to receive ( :new ) . with ( :foo , foo : 'bar' ) . and_return ( new_namespace )
162
+ expect ( subject ) . to receive ( :namespace_stackable ) . with ( :namespace , new_namespace )
163
+
164
+ subject . namespace :foo , foo : 'bar' , &proc { }
165
+ end
166
+
167
+ it 'calls #joined_space_path on Namespace' do
168
+ result_of_namspace_stackable = Object . new
169
+ allow ( subject ) . to receive ( :namespace_stackable ) . and_return ( result_of_namspace_stackable )
170
+ expect ( Namespace ) . to receive ( :joined_space_path ) . with ( result_of_namspace_stackable )
171
+ subject . namespace
172
+ end
122
173
end
123
174
124
- xdescribe '.group' do
125
- it 'does some thing'
175
+ describe '.group' do
176
+ it 'is alias to #namespace' do
177
+ expect ( subject . method ( :group ) ) . to eq subject . method ( :namespace )
178
+ end
126
179
end
127
180
128
- xdescribe '.resource' do
129
- it 'does some thing'
181
+ describe '.resource' do
182
+ it 'is alias to #namespace' do
183
+ expect ( subject . method ( :resource ) ) . to eq subject . method ( :namespace )
184
+ end
130
185
end
131
186
132
- xdescribe '.resources' do
133
- it 'does some thing'
187
+ describe '.resources' do
188
+ it 'is alias to #namespace' do
189
+ expect ( subject . method ( :resources ) ) . to eq subject . method ( :namespace )
190
+ end
134
191
end
135
192
136
- xdescribe '.segment' do
137
- it 'does some thing'
193
+ describe '.segment' do
194
+ it 'is alias to #namespace' do
195
+ expect ( subject . method ( :segment ) ) . to eq subject . method ( :namespace )
196
+ end
138
197
end
139
198
140
- xdescribe '.routes' do
141
- it 'does some thing'
199
+ describe '.routes' do
200
+ let ( :routes ) { Object . new }
201
+
202
+ it 'returns value received from #prepare_routes' do
203
+ expect ( subject ) . to receive ( :prepare_routes ) . and_return ( routes )
204
+ expect ( subject . routes ) . to eq routes
205
+ end
206
+
207
+ context 'when #routes was already called once' do
208
+ before do
209
+ allow ( subject ) . to receive ( :prepare_routes ) . and_return ( routes )
210
+ subject . routes
211
+ end
212
+ it 'it does not call prepare_routes again' do
213
+ expect ( subject ) . to_not receive ( :prepare_routes )
214
+ expect ( subject . routes ) . to eq routes
215
+ end
216
+ end
142
217
end
143
218
144
- xdescribe '.route_param' do
145
- it 'does some thing'
219
+ describe '.route_param' do
220
+ it 'calls #namespace with given params' do
221
+ expect ( subject ) . to receive ( :namespace ) . with ( ':foo' , { } ) . and_yield
222
+ subject . route_param ( 'foo' , { } , &proc { } )
223
+ end
224
+
225
+ let ( :regex ) { /(.*)/ }
226
+ let! ( :options ) { { requirements : regex } }
227
+ it 'nests requirements option under param name' do
228
+ expect ( subject ) . to receive ( :namespace ) do |param , options |
229
+ expect ( options [ :requirements ] [ :foo ] ) . to eq regex
230
+ end
231
+ subject . route_param ( 'foo' , options , &proc { } )
232
+ end
233
+
234
+ it 'does not modify options parameter' do
235
+ allow ( subject ) . to receive ( :namespace )
236
+ expect { subject . route_param ( 'foo' , options , &proc { } ) }
237
+ . to_not change { options }
238
+ end
146
239
end
147
240
148
241
describe '.versions' do
0 commit comments