Ruby · 23 Jun 2021

How to test raise_error matcher if it gets an error

The problem with raise_error matcher in RSpec is common and it can be fixed in easy way.

Let's say we have situation like below:

subject(:service_call) { CarService.call }

it { expect(service_call).to raise_error(CarDatabaseConnectionError) }

If we call it like this it will get us an error.

  1) CarUpdateService when fail 
     Failure/Error: raise CarDatabaseConnectionError
     
     CarDatabaseConnectionError:
       Can't connect with a custom car database.

Why it didn't pass the spec?

The problem is here:

Read more