Bird
0
0

What will happen if you run this Minitest code?

medium📝 Predict Output Q5 of 15
Ruby - Testing with RSpec and Minitest
What will happen if you run this Minitest code?
require 'minitest/autorun'

class TestString < Minitest::Test
  def test_length
    assert_equal 4, 'ruby'.length
  end
end
ATest fails because length is incorrect
BTest passes with no failures
CSyntax error due to missing end
DNo tests run because class name is invalid
Step-by-Step Solution
Solution:
  1. Step 1: Check the assertion

    'ruby'.length returns 4, matching the expected value.
  2. Step 2: Confirm test execution

    The class and method are correctly defined, so the test runs and passes.
  3. Final Answer:

    Test passes with no failures -> Option B
  4. Quick Check:

    Correct assertion means test passes [OK]
Quick Trick: String length matches expected value passes test [OK]
Common Mistakes:
  • Assuming length is different
  • Missing 'end' keyword
  • Thinking class name affects test run

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes