Bird
0
0

What is wrong with this TDD workflow snippet in Ruby?

medium📝 Debug Q14 of 15
Ruby - Testing with RSpec and Minitest
What is wrong with this TDD workflow snippet in Ruby?
class TestCalculator < Minitest::Test
  def test_multiply
    calc = Calculator.new
    assert_equal 6, calc.multiply(2, 3)
  end
end

class Calculator
  def multiply(a, b)
    a - b
  end
end
AThe test method name is incorrect
Bassert_equal arguments are reversed
CCalculator class is missing
DThe multiply method subtracts instead of multiplies
Step-by-Step Solution
Solution:
  1. Step 1: Compare method implementation with test expectation

    The test expects multiply(2, 3) to return 6, but the method subtracts a - b.
  2. Step 2: Identify the error cause

    Subtracting 2 - 3 gives -1, which will fail the test expecting 6.
  3. Final Answer:

    The multiply method subtracts instead of multiplies -> Option D
  4. Quick Check:

    Method logic must match test expectation [OK]
Quick Trick: Check method logic matches test assertions [OK]
Common Mistakes:
  • Confusing subtraction with multiplication
  • Ignoring method implementation details
  • Assuming test method name affects test result

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes