The Service Integration Test
Explore testing external service integrations in Rails by writing integration tests using the Twitter API. Understand how to configure VCR and Webmock gems, manage API keys securely, and verify user data like Twitter avatars alongside your application tasks.
We'll cover the following...
Twitter integration testing
We’ll use the Twitter gem to interface with Twitter. We’re also going to need the VCR and Webmock gems in the test environment. We add them to the Gemfile:
Then we’ll also have to reinstall the bundle with bundle install.
Twitter API and secret key
We need a Twitter API key and a secret key, which we can get from the Twitter Application Management page. In Rails 5 or higher, those get placed in the secrets.yml file, which typically is not stored in our code repository, which we’ve put in the config directory:
Note: ...