Bird
0
0

What will be the output of this RSpec test?

medium📝 Predict Output Q5 of 15
Ruby - Testing with RSpec and Minitest
What will be the output of this RSpec test?
describe 'Number test' do
  it 'checks if number is greater than 10' do
    expect(15).to be > 10
  end
end
AThe test raises a syntax error due to incorrect matcher.
BThe test fails because 15 is not greater than 10.
CThe test fails because <code>be > 10</code> is invalid syntax.
DThe test passes because 15 is greater than 10.
Step-by-Step Solution
Solution:
  1. Step 1: Understand the matcher syntax

    The syntax expect(value).to be > 10 uses Ruby's operator matcher to check if value is greater than 10.
  2. Step 2: Evaluate the condition

    Since 15 is greater than 10, the expectation passes and the test passes.
  3. Final Answer:

    The test passes because 15 is greater than 10. -> Option D
  4. Quick Check:

    Operator matchers work with be > syntax [OK]
Quick Trick: Use be > number to check greater than [OK]
Common Mistakes:
  • Thinking be > is invalid syntax
  • Confusing operator matcher with block syntax
  • Assuming test fails without checking value

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes