Bird
0
0

Find the bug in this Ruby test double code snippet:

medium📝 Debug Q7 of 15
Ruby - Testing with RSpec and Minitest

Find the bug in this Ruby test double code snippet:

user = double('user')
allow(user).to receive(:email).and_return('test@example.com')
puts user.email_address
AThe <code>and_return</code> value must be a number
BDouble name must be a symbol, not a string
CThe <code>allow</code> method cannot be used with doubles
DMethod <code>email_address</code> is not stubbed, causing an error
Step-by-Step Solution
Solution:
  1. Step 1: Check stubbed method

    Only email is stubbed to return a string.
  2. Step 2: Check method called

    The code calls user.email_address, which is not stubbed, so it raises an error.
  3. Final Answer:

    Method email_address is not stubbed, causing an error -> Option D
  4. Quick Check:

    Unstubbed method call = error [OK]
Quick Trick: Stub every method you call on a double [OK]
Common Mistakes:
  • Confusing double name types
  • Misunderstanding allow usage
  • Assuming return values must be numeric

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes