-
Notifications
You must be signed in to change notification settings - Fork 62
Open
Description
When using the ActionHandlerMatchers helper to test for a handler that throws an exception, the only way to capture the excaption is encapsulating the test in a begin/rescue block.
the resource:
class FakeResource < ResourceKit::Resource
resources do
default_handler(410) { |response| fail ShopperExpiredException }
default_handler(404) { |response| fail RecordNotFound }
action :find do
path '/api/v1/fake_model/:id'
handler(200) do |response|
FakeMapping.extract_single(response.body, :read)
end
end
end
endand the spec:
describe '404' do
it 'raises a RecordNotFound error' do
expect(described_class).to handle_response(:find).with(status: 404, body: '{"users":[]}') { |handled_response|
expect { handled_response }.to raise_error
}
end
endi can "accomplish" what i want by going:
describe '404' do
it 'raises a RecordNotFound error' do
begin
expect(described_class).to handle_response(:find).with(status: 404, body: '{"users":[]}') { |handled_response|
expect { handled_response }.to raise_error
}
rescue => e
expect(e).to be_a(RecordNotFound)
end
end
endAlthough what's happening makes sense. I think there should be a way to catch any exception that trigger from within the handler.
Metadata
Metadata
Assignees
Labels
No labels