Bird
0
0

Why might stubbing a method with a falsy value like false or nil cause unexpected test behavior?

hard📝 Conceptual Q10 of 15
Ruby - Testing with RSpec and Minitest
Why might stubbing a method with a falsy value like false or nil cause unexpected test behavior?
ABecause falsy values cause syntax errors
BBecause stubbing with falsy values is not allowed
CBecause some code checks method truthiness, causing logic to skip
DBecause stubbing only works with strings
Step-by-Step Solution
Solution:
  1. Step 1: Understand falsy values in Ruby

    In Ruby, false and nil are falsy and can affect conditional checks.
  2. Step 2: Recognize impact on tests

    If code uses method result in conditionals, stubbing with falsy values may skip important branches, causing unexpected behavior.
  3. Final Answer:

    Because some code checks method truthiness, causing logic to skip -> Option C
  4. Quick Check:

    Falsy stub values affect conditional logic [OK]
Quick Trick: Beware falsy stub values affecting conditionals [OK]
Common Mistakes:
  • Thinking falsy stubs cause syntax errors
  • Believing stubbing disallows falsy values
  • Assuming only strings can be stubbed

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes