Skip to content

handle_response matchers doesnt handle exceptions #19

@vjustov

Description

@vjustov

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
end

and 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
end

i 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
end

Although 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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions