Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"You can stub this request with" formats badly within minitest assert_raises #922

Open
Nakilon opened this issue Dec 28, 2020 · 1 comment

Comments

@Nakilon
Copy link

Nakilon commented Dec 28, 2020

Trying the "webmock/minitest". Here is the test code:

        assert_raises DirectLink::ErrorNotFound do
          DirectLink.imgur "https://imgur.com/a/wwwwwww"
        end

As I remember the "You can stub this request with ..." has to be formatted well so I could copypaste it. But probably due to the assert_raise block it does not format well:

  1) Failure:
DirectLink::./lib::imgur#test_0004_ErrorNotFound when album is empty [unit.test.rb:252]:
[DirectLink::ErrorNotFound] exception expected, not
Class: <WebMock::NetConnectNotAllowedError>
Message: <"Real HTTP connections are disabled. Unregistered request: HEAD https://api.imgur.com/3/album/wwwwwww/0.json with headers {'Accept'=>'*/*', 'Authorization'=>'Client-ID 00000', 'Host'=>'api.imgur.com', 'User-Agent'=>'Ruby'}\n\nYou can stub this request with the following snippet:\n\nstub_request(:head, \"https://api.imgur.com/3/album/wwwwwww/0.json\").\n  with(\n    headers: {\n\t  'Accept'=>'*/*',\n\t  'Authorization'=>'Client-ID 00000',\n\t  'Host'=>'api.imgur.com',\n\t  'User-Agent'=>'Ruby'\n    }).\n  to_return(status: 200, body: \"\", headers: {})\n\n============================================================">
---Backtrace---
/Users/nakilon/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/gems/webmock-3.11.0/lib/webmock/http_lib_adapters/net_http.rb:114:in `request'
...

Or did I forgot something I had to add to make it look good?

@bblimke
Copy link
Owner

bblimke commented Dec 28, 2020

@Nakilon the WebMock::NetConnectNotAllowedError exception is not supposed to be caught by assert_raises, but instead caught as a test error and unchanged message printed.

Looking at Minitest, the exceptions ignored by assert_raises are not configurable,
https://github.com/seattlerb/minitest/blob/dc6ad179ceac3be92375ac1236f0ee19b9f09df4/lib/minitest/assertions.rb#L406
therefore I don't see any easy way of fixing that, apart from monkey patching
assert_raises. Perhaps it's worth opening an issue in Minitest to allow adding
exceptions to be ignored by assert_raises.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants