Adding testing dependencies for plugins

I’m writing a plugin that calls to an external api. In the past I’ve used VCR to record requests & responses so I don’t hammer the service every 15 seconds as my tests autorun.

I’ve seen that I can use gem 'vcr', '5.0.0' in my plugin.rb, but I’m not sure what the best way is to ensure this dependency is only requested in test environments.

Does anyone else use VCR or something similar when testing plugins that call external APIs? How do you manage the dependency?

We stub requests to external APIs is quite a few places. Here’s one example:

https://github.com/discourse/discourse-chat-integration/blob/master/spec/lib/discourse_chat/provider/slack/slack_provider_spec.rb#L77

If you really want to add a plugin dev-only dependency, you should be able to do something like gem 'vcr', '5.0.0' if Rails.env.development?

5 Likes

Thanks, I’d rather stick to ‘the discourse way’ for now, so I’ll do that instead :slight_smile:

3 Likes