Skip to content

Commit 1a9cbc4

Browse files
committed
Merge branch 'master' into master
2 parents fa8aac8 + b455477 commit 1a9cbc4

File tree

2 files changed

+31
-19
lines changed

2 files changed

+31
-19
lines changed

lib/grape_entity/entity.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,9 @@ def exec_with_object(options, &block)
527527
end
528528
rescue StandardError => e
529529
# it handles: https://github.com/ruby/ruby/blob/v3_0_0_preview1/NEWS.md#language-changes point 3, Proc
530-
raise Grape::Entity::Deprecated.new e.message, 'in ruby 3.0'
530+
raise Grape::Entity::Deprecated.new e.message, 'in ruby 3.0' if e.is_a?(ArgumentError)
531+
532+
raise e.class, e.message
531533
end
532534

533535
def exec_with_attribute(attribute, &block)

spec/grape_entity/entity_spec.rb

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -262,30 +262,40 @@ class BogusEntity < Grape::Entity
262262
end
263263
end
264264

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'
271269
end
270+
end
272271

273-
subject.expose :that_method_without_args do |object|
274-
object.method_without_args
275-
end
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
276277

277-
subject.expose :that_method_without_args_again, &:method_without_args
278+
object = SomeObject.new
278279

279-
object = SomeObject.new
280+
value = subject.represent(object).value_for(:that_method_without_args)
281+
expect(value).to eq('result')
282+
end
283+
end
280284

281-
value = subject.represent(object).value_for(:that_method_without_args)
282-
expect(value).to eq('result')
285+
context 'with block passed in via &' do
286+
specify do
287+
subject.expose :that_method_without_args_again, &:method_without_args
283288

284-
if RUBY_VERSION.start_with?('3')
285-
expect { subject.represent(object).value_for(:that_method_without_args_again) }.to raise_error Grape::Entity::Deprecated
286-
else
287-
value2 = subject.represent(object).value_for(:that_method_without_args_again)
288-
expect(value2).to eq('result')
289+
object = SomeObject.new
290+
291+
if RUBY_VERSION.start_with?('3')
292+
expect do
293+
subject.represent(object).value_for(:that_method_without_args_again)
294+
end.to raise_error Grape::Entity::Deprecated
295+
else
296+
value2 = subject.represent(object).value_for(:that_method_without_args_again)
297+
expect(value2).to eq('result')
298+
end
289299
end
290300
end
291301
end

0 commit comments

Comments
 (0)