Bird
0
0

What is the main purpose of stubbing in Ruby testing?

easy📝 Conceptual Q11 of 15
Ruby - Testing with RSpec and Minitest
What is the main purpose of stubbing in Ruby testing?
ATo check if a method was called with specific arguments
BTo slow down tests by adding delays
CTo run the actual method code during tests
DTo replace a method's return value with a fake one
Step-by-Step Solution
Solution:
  1. Step 1: Understand stubbing concept

    Stubbing means replacing a method's output with a fake value to control test behavior.
  2. Step 2: Differentiate from mocking

    Mocking checks method calls, but stubbing focuses on return values.
  3. Final Answer:

    To replace a method's return value with a fake one -> Option D
  4. Quick Check:

    Stubbing = fake return value [OK]
Quick Trick: Stubs fake returns; mocks check calls [OK]
Common Mistakes:
  • Confusing stubs with mocks
  • Thinking stubs run real code
  • Believing stubs slow tests

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes