...

/

The Service Integration Test

The Service Integration Test

Learn how to set up and write Twitter service integration tests.

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:

Press + to interact
gem 'twitter'
gem 'vcr', group: :test
gem 'webmock', group: :test

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:

Press + to interact
shared:
api_key: 123
development:
secret_key_base: <your_secret_key_base>
test:
secret_key_base: <your_secret_key_base>
twitter_api_key: "<your_api_key>"
twitter_api_secret: "<your_api_secret_key>"
production:
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>

Note: ...