Bird
0
0

Given this Ruby code snippet, what will be the test output?

medium📝 Predict Output Q5 of 15
Ruby - Testing with RSpec and Minitest
Given this Ruby code snippet, what will be the test output?
require 'minitest/autorun'

class StringTest < Minitest::Test
  def test_length
    assert_equal 4, 'ruby'.length
  end
end
A1 runs, 1 failure
BRuntime error
CNo tests found
D1 runs, 0 failures
Step-by-Step Solution
Solution:
  1. Step 1: Check the assertion logic

    The string 'ruby' has length 4, so assert_equal 4, 'ruby'.length passes.
  2. Step 2: Understand Minitest output for passing tests

    One test runs and passes, so output shows 1 run, 0 failures.
  3. Final Answer:

    1 runs, 0 failures -> Option D
  4. Quick Check:

    Correct assertion = 0 failures [OK]
Quick Trick: Correct assertions mean zero failures in test output [OK]
Common Mistakes:
  • Miscounting string length
  • Expecting failure when assertion is correct
  • Confusing test run count with failure count

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes