Closed adambutler closed 5 years ago
What about mocking the Nexmo::Client
interface (example)? Fast and works without a network connection, as with VCR. There's also webmock, which is what the specs use.
A mock implementation over HTTP isn't a language specific thing, so I would have thought that was best developed independently--if there was a mock Nexmo implementation that could be run locally then all of the client libraries could use it just by supporting an "api_host" config argument.
A standalone mock would be great to share between all client libraries. I've had good experiences with http://www.mbtest.org/ in the past
Closing this because it's a more general client library issue.
For anyone looking to write tests against nexmo-ruby there are at least 3 approaches:
Use a mocking library to mock the nexmo-ruby interface
Use webmock to mock network calls (same as the nexmo-ruby tests)
Use webmock together with vcr to record and replay interactions with the Nexmo API
Some kind of standalone nexmo-mock server similar to stripe-mock that can be used against all the client libraries would offer an alternative, but that's outside the scope of nexmo-ruby.
At RailsConf I had somebody mention to me that testing with the
nexmo-ruby
was made difficult by the library not supporting any test mode.We talked about using VCR for capturing and replaying interactions with the Nexmo API but given that Nexmo does not support a sandbox mode this is a less than ideal solution.
Something we both agreed on is the way that Sidekiq implements a test mode as described here accurately simulating real interactions with Sidekiq without actually using it. This example, however, does not reach out to a public API.
I've had similar frustrations in the past using stripe-ruby and in that case did use VCR. Since Stripe provides a sandbox periodically re-recording the cassettes was reasonable & incurred no cost. Since then a couple of Stripe mock implementations have been created stripe-ruby-mock & fake_stripe ) further improving the testability of this API.
Bundling in such functionality into our gem using the approach taken in Stripe mocking gems would significantly improve the implementation, speed & reliability of testing with Nexmo as well as allowing developers to work offline and not incur charges doing a clean run of their test suite.