Bird
0
0

You want to test a method that calls an external API. How can mocking help in this scenario?

hard📝 Application Q8 of 15
Ruby - Testing with RSpec and Minitest
You want to test a method that calls an external API. How can mocking help in this scenario?
ARemove the API call from the method
BMock the API client to return fixed data without real calls
CRewrite the API to be faster
DUse real API calls in every test
Step-by-Step Solution
Solution:
  1. Step 1: Identify problem with real API calls

    Real API calls slow tests and depend on external systems.
  2. Step 2: Use mocking to simulate API client

    Mocking the client returns fixed data instantly, isolating tests from external factors.
  3. Final Answer:

    Mock the API client to return fixed data without real calls -> Option B
  4. Quick Check:

    Mock external calls for fast, reliable tests [OK]
Quick Trick: Mock external services to isolate tests [OK]
Common Mistakes:
  • Trying to speed up API itself
  • Removing needed API calls
  • Using real calls in tests

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes