rspec-expectations
rspec-expectations copied to clipboard
Allow configuring exceptions raise_error should capture to display webmock errors correctly
I'm doing: expect { call }.to raise_error(/ABORTED/)
this triggers a http request and then it ends up as:
expected /ABORTED/, got #<WebMock::NetConnectNotAllowedError: Real HTTP connections are disabled. Unregistered request: GET h...e.sk/projects/sfn_kubernetes/stages")
but what I want to see is:
WebMock::NetConnectNotAllowedError:
Real HTTP connections are disabled. Unregistered request: GET https://samson.zende.sk/locks with body '{"per_page":100,"page":1}' with headers {'Accept'=>'application/json', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization'=>'Bearer a', 'Content-Type'=>'application/json', 'User-Agent'=>'Ruby'}
You can stub this request with the following snippet:
blah blah
... this does not surface though since raise_error captures Exception and not StandardError like minitest does.
I assume changing the default would be too disruptive, so I'd suggest we make that configureable ?
workaround I'm using atm:
undef :raise_error
undef :raise_exception
def expect_error(regex)
yield
rescue StandardError => e
raise unless e.message.match?(regex)
else
raise "Nothing raised"
end