Bird
0
0

Identify the error in the following code snippet:

medium📝 Debug Q6 of 15
Ruby - Testing with RSpec and Minitest
Identify the error in the following code snippet:
let(:value) { 5 }
before do
  value = 10
end
it 'checks value' do
  expect(value).to eq(5)
end
AThe assignment inside before creates a local variable, not changing let value
Blet cannot be used with before hooks
Cvalue is undefined inside before block
DThe test will fail because value is 10
Step-by-Step Solution
Solution:
  1. Step 1: Understand variable assignment in before

    Assigning value = 10 inside before creates a local variable, not changing the let method.
  2. Step 2: Check test expectation

    The value method from let still returns 5, so test expects 5 and passes.
  3. Final Answer:

    The assignment inside before creates a local variable, not changing let value -> Option A
  4. Quick Check:

    Assignment in before is local, does not override let [OK]
Quick Trick: Assigning to let name in before creates local variable [OK]
Common Mistakes:
  • Assuming before assignment changes let value
  • Thinking let variables are normal variables
  • Expecting test to fail due to assignment

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes