from a backend controller, I need to make an HTTP GET request to an external service (KeyBase) to validate user input. What’s the library the Discourse uses to do this? I tried with Faraday, but I expect a json response and faraday_middleware is not an available gem.
I was able to get Faraday to work, but the tests are failing with a very strange error, it looks like Faraday is not able to make a request in the test. Is that possible? Is there something I am expected to do to be able to make external requests in tests?
EDIT: to be more clear: the request works fine in the actual page, but not in the tests.
We use https://github.com/bblimke/webmock so pretty much anything should work, if you simply need a simple HTTP get, this class has simple example of how we use FinalDestination class that wraps stuff for you.
Thank you my struggle with this specific issue was that I couldn’t find a spec to learn from I found stub_request and tried to use it, but I think I got into one of the strange issues with Faraday you mentioned because the spec kept failing
One question: so I should keep bin/rake autospec running while I am working on the plug-in and it will automatically pick the changes and run the tests again?
Yes, there is also a fantastic trick I use I highly recommend.
Say I am working on something_spec.rb in the plugin I will edit in:
it "I am working on this spec" do
Then I save it … and I am well focused on the broken specs. Then I improve the spec, leaving the “boom” at the end so autospec stays focused, saving other files and the spec file as I go. autospec stays focused and keeps running as needed.