lundi 19 avril 2021

How to raise timeout error in unittesting

This is first time i am touching ruby, so no sure about correct terminology. I have tried searching for mulitple things, but couldn't find a solution.

I have this code block

domain_response = MyDomain::Api::MyApi::Api.new(parameters: message.to_domain_object, timeout: 1000)
# :nocov:
case (response = domain_response.response)
when MyDomain::Api::MyApi::SuccessResponse
  ## do something
when Domain::ErrorResponses::TimeoutResponse
  ## do something.

now i am trying to testing TimeoutResponse, I have written(tried) this

      it "when api call timesout" do
        expect(MyDomain::Api::MyApi::Api).to{
          receive(:new)
        } raise_error(MyDomain::ErrorResponses::TimeoutResponse)
      end

this gave me error that unexpected identifier.

I have also tried by not providing receive, and it gave me error that block is expected.

Whats the proper way to raise an error that i can test?

Aucun commentaire:

Enregistrer un commentaire