Client Unit Tests
Explore writing client unit tests for external service integrations in Rails. Understand how to design adapters, use VCR to mock HTTP requests, and test user data interactions like retrieving Twitter avatar URLs. This lesson guides you through structuring tests to ensure your application handles third-party APIs effectively while maintaining clean code design.
Clients in external service testing
VCR is set up. Now, let’s make the Twitter integration work. As it stands, the test fails because the user data is not in the view at all. The test suggests that the user email and the Twitter avatar should be in the view, so let’s add them to the view file.
Design decisions
We have a design decision to make about how the application should interact with Twitter. There are many options, ranging from calling the gem and service directly from the view to placing the interaction within the User class.
Our design here tends toward more objects and structure ...