Bird
0
0

In RSpec, what does the matcher expect(value).to be_nil check for?

easy📝 Conceptual Q1 of 15
Ruby - Testing with RSpec and Minitest
In RSpec, what does the matcher expect(value).to be_nil check for?
AIt checks if <code>value</code> is false.
BIt checks if <code>value</code> is <code>nil</code>.
CIt checks if <code>value</code> is an empty string.
DIt checks if <code>value</code> is zero.
Step-by-Step Solution
Solution:
  1. Step 1: Understand the be_nil matcher

    The be_nil matcher checks if the tested value is exactly nil.
  2. Step 2: Compare options with matcher behavior

    Options A, B, and C describe checks for false, zero, and empty string respectively -- none of which match the be_nil behavior.
  3. Final Answer:

    It checks if value is nil. -> Option B
  4. Quick Check:

    Matcher be_nil = check for nil [OK]
Quick Trick: Use be_nil to check for nil values only [OK]
Common Mistakes:
  • Confusing be_nil with eq(nil) (similar but different in some contexts)
  • Thinking it checks for false or zero
  • Using be_nil to check empty strings

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes