Search⌘ K
AI Features

Adapter Tests

Understand how to write adapter tests that validate interactions with external services by using VCR to record HTTP requests. Explore how to isolate adapter behavior from client dependencies, manage Twitter API integration, and ensure your tests run efficiently by replaying recorded responses.

Adapter tests

The adapter tests work between the adapter and the server, using VCR as a medium:

shared:
  api_key: 123
development:
  secret_key_base: {{secret_key_base_development}}
test:
  secret_key_base: {{secret_key_base_test}}
  twitter_api_key: "{{twitter_api_key}}"
  twitter_api_secret: "{{twitter_api_secret}}"
production:
  secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
Adding "AvatarAdapter" block to avatar_adapter_spec.rb file in spec/models/ directory

This test has no dependency on the client, which is shown passing in a double rather than an actual User instance. Using a VCR cassette, we create a new adapter and assert that the adapter provides the expected URL when queried. The test also doesn’t have a particular dependency on the Twitter gem, beyond the ...