digitalocean / digitalocean/resource_kit

handle_response matchers doesnt handle exceptions

Open
#19 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Ruby
Stars
138
Forks
60
PR merge metrics
No merged PRs in 30d

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:

``` ruby
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
end
```

and the spec:

``` ruby
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
end
```

i can "accomplish" what i want by going:

``` ruby
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
end
```

Although what's happening makes sense. I think there should be a way to catch any exception that trigger from within the handler.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.