@@ -262,27 +262,50 @@ class BogusEntity < Grape::Entity
262
262
end
263
263
end
264
264
265
- context 'with block passed via &' do
266
- it 'with does not pass options when block is passed via &' do
267
- class SomeObject
268
- def method_without_args
269
- 'result'
270
- end
265
+ describe 'blocks' do
266
+ class SomeObject
267
+ def method_without_args
268
+ 'result'
271
269
end
270
+ end
271
+
272
+ describe 'with block passed in' do
273
+ specify do
274
+ subject . expose :that_method_without_args do |object |
275
+ object . method_without_args
276
+ end
277
+
278
+ object = SomeObject . new
272
279
273
- subject . expose :that_method_without_args do | object |
274
- object . method_without_args
280
+ value = subject . represent ( object ) . value_for ( :that_method_without_args )
281
+ expect ( value ) . to eq ( 'result' )
275
282
end
283
+ end
284
+
285
+ context 'with block passed in via &' do
286
+ if RUBY_VERSION . start_with? ( '3' )
287
+ specify do
288
+ subject . expose :that_method_without_args , &:method_without_args
289
+ subject . expose :method_without_args , as : :that_method_without_args_again
276
290
277
- subject . expose :that_method_without_args_again , &:method_without_args
291
+ object = SomeObject . new
292
+ expect do
293
+ subject . represent ( object ) . value_for ( :that_method_without_args )
294
+ end . to raise_error Grape ::Entity ::Deprecated
278
295
279
- object = SomeObject . new
296
+ value2 = subject . represent ( object ) . value_for ( :that_method_without_args_again )
297
+ expect ( value2 ) . to eq ( 'result' )
298
+ end
299
+ else
300
+ specify do
301
+ subject . expose :that_method_without_args_again , &:method_without_args
280
302
281
- value = subject . represent ( object ) . value_for ( :that_method_without_args )
282
- expect ( value ) . to eq ( 'result' )
303
+ object = SomeObject . new
283
304
284
- value2 = subject . represent ( object ) . value_for ( :that_method_without_args_again )
285
- expect ( value2 ) . to eq ( 'result' )
305
+ value2 = subject . represent ( object ) . value_for ( :that_method_without_args_again )
306
+ expect ( value2 ) . to eq ( 'result' )
307
+ end
308
+ end
286
309
end
287
310
end
288
311
0 commit comments