Vonage / vonage-ruby-sdk

Vonage REST API client for Ruby. API support for SMS, Voice, Text-to-Speech, Numbers, Verify (2FA) and more.
https://developer.vonage.com
Apache License 2.0
216 stars 108 forks source link

Test mode - Stubbing the API #73

Closed adambutler closed 5 years ago

adambutler commented 7 years ago

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.

timcraft commented 7 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.

mheap commented 7 years ago

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

timcraft commented 5 years ago

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:

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.