Bird
0
0

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

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

class Calculator
  def add(a, b)
    a + b
  end
end

class TestCalculator < Minitest::Test
  def test_add
    calc = Calculator.new
    assert_equal 5, calc.add(2, 3)
  end
end
A1 test, 0 failures
B1 test, 1 failure
CSyntaxError
DNo tests run
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the test and method

    The add method returns the sum of two numbers. The test expects 5 from adding 2 and 3.
  2. Step 2: Check if test passes

    Since 2 + 3 equals 5, the assertion passes and the test succeeds.
  3. Final Answer:

    1 test, 0 failures -> Option A
  4. Quick Check:

    Correct sum = test passes [OK]
Quick Trick: If method matches test expectation, test passes [OK]
Common Mistakes:
  • Thinking test fails when it actually passes
  • Confusing syntax error with test failure
  • Ignoring the assert_equal expected value

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes