Bird
0
0

Identify the error in this RSpec mocking code:

medium📝 Debug Q14 of 15
Ruby - Testing with RSpec and Minitest
Identify the error in this RSpec mocking code:
user = double('User')
expect(user).to receive(:login).with('admin')
user.login('guest')
AMissing stub for login method
BThe double is not created correctly
CThe method login is called with wrong argument
DNo error, code is correct
Step-by-Step Solution
Solution:
  1. Step 1: Understand the expectation

    The test expects login to be called with argument 'admin'.
  2. Step 2: Check actual method call

    The method is called with 'guest', which does not match the expectation.
  3. Final Answer:

    The method login is called with wrong argument -> Option C
  4. Quick Check:

    Expect argument mismatch causes failure [OK]
Quick Trick: Match expected arguments exactly in mocks [OK]
Common Mistakes:
  • Calling method with different arguments
  • Confusing stub and expect syntax
  • Ignoring error raised by RSpec

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes