Consider this Ruby test using MiniTest. What will be printed when you run it?
require 'minitest/autorun' class TestExample < Minitest::Test def test_sum assert_equal 5, 2 + 3 end end
Check if the assertion matches the sum correctly.
The test asserts that 2 + 3 equals 5, which is true, so the test passes with 0 failures.
Which reason best explains why testing is central to Ruby culture?
Think about the role of tests in code quality and collaboration.
Ruby culture emphasizes clean, maintainable code. Testing helps catch bugs early and documents expected behavior, supporting this value.
What error will this Ruby test code produce when run?
require 'minitest/autorun' class TestCalc < Minitest::Test def test_multiply assert_equal 10, 2 * 5 end def test_divide assert_equal 2, 10 / 0 end end
Look at the division operation in the second test.
Dividing by zero raises a ZeroDivisionError in Ruby, causing the test run to error out.
Choose the option with correct Ruby MiniTest syntax.
Check for proper method calls and class endings.
Option C has correct syntax: method call with two arguments, and class properly closed.
Given this Ruby test suite, how many tests will run and how many will pass?
require 'minitest/autorun' class TestMath < Minitest::Test def test_add assert_equal 7, 3 + 4 end def test_subtract assert_equal 2, 5 - 3 end def test_fail assert_equal 10, 5 * 3 end end
Check each assertion carefully for correctness.
The first two tests pass, but the third test expects 10 but 5 * 3 is 15, so it fails.