Bird
0
0

What will be the output when running this RSpec test?

medium📝 Predict Output Q13 of 15
Ruby - Testing with RSpec and Minitest
What will be the output when running this RSpec test?
describe 'Math' do
  it 'checks addition' do
    expect(2 + 2).to eq(4)
  end

  it 'checks subtraction' do
    expect(5 - 3).to eq(1)
  end
end
A1 test passed, 1 test failed
B2 tests passed
C2 tests failed
DSyntax error
Step-by-Step Solution
Solution:
  1. Step 1: Evaluate first test case

    expect(2 + 2).to eq(4) is true, so first test passes.
  2. Step 2: Evaluate second test case

    expect(5 - 3).to eq(1) is false because 5 - 3 equals 2, not 1, so second test fails.
  3. Final Answer:

    1 test passed, 1 test failed -> Option A
  4. Quick Check:

    2+2=4 (pass), 5-3=2≠1 (fail) = B [OK]
Quick Trick: Check math inside expect carefully [OK]
Common Mistakes:
  • Assuming both tests pass without checking math
  • Confusing expected and actual values
  • Ignoring test failure details

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes