Bird
0
0

What will be the output of this RSpec test snippet?

medium📝 Predict Output Q13 of 15
Ruby - Testing with RSpec and Minitest
What will be the output of this RSpec test snippet?
describe 'Number test' do
  it 'checks if number is odd' do
    number = 7
    expect(number.odd?).to be true
  end
end
AThe test passes because 7 is odd.
BThe test fails because 7 is not odd.
CSyntaxError due to incorrect matcher usage.
DThe test passes but warns about deprecated syntax.
Step-by-Step Solution
Solution:
  1. Step 1: Understand the code logic

    The variable number is set to 7, which is an odd number.
  2. Step 2: Analyze the expectation

    expect(number.odd?).to be true checks if number.odd? returns true, which it does for 7.
  3. Final Answer:

    The test passes because 7 is odd. -> Option A
  4. Quick Check:

    odd? returns true for odd numbers [OK]
Quick Trick: odd? returns true for odd numbers, expect that [OK]
Common Mistakes:
  • Assuming 7 is even
  • Confusing be true with eq true
  • Thinking syntax is wrong here

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes