0
0
Rubyprogramming~20 mins

Why testing is central to Ruby culture - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Ruby Testing Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this Ruby test code?

Consider this Ruby test using MiniTest. What will be printed when you run it?

Ruby
require 'minitest/autorun'

class TestExample < Minitest::Test
  def test_sum
    assert_equal 5, 2 + 3
  end
end
A1 runs, 1 failure
B1 runs, 0 failures
CSyntaxError
DNo output
Attempts:
2 left
💡 Hint

Check if the assertion matches the sum correctly.

🧠 Conceptual
intermediate
1:30remaining
Why is testing important in Ruby culture?

Which reason best explains why testing is central to Ruby culture?

ABecause Ruby developers value readable, maintainable code and tests help ensure that
BBecause Ruby syntax requires tests to run code
CBecause Ruby does not have error handling without tests
DBecause Ruby programs cannot run without test frameworks installed
Attempts:
2 left
💡 Hint

Think about the role of tests in code quality and collaboration.

🔧 Debug
advanced
2:00remaining
Identify the error in this Ruby test code

What error will this Ruby test code produce when run?

Ruby
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
AZeroDivisionError
BAssertionError
CNo error, tests pass
DSyntaxError
Attempts:
2 left
💡 Hint

Look at the division operation in the second test.

📝 Syntax
advanced
1:30remaining
Which Ruby test code snippet is syntactically correct?

Choose the option with correct Ruby MiniTest syntax.

A
class TestA &lt; Minitest::Test
 def test_one
 assert_equal(4 2 + 2)
 end
end
B
class TestA &lt; Minitest::Test
 def test_one
 assert_equal 4, 2 + 2
 end
C
class TestA &lt; Minitest::Test
 def test_one
 assert_equal 4, 2 + 2
 end
end
D
class TestA &lt; Minitest::Test
 def test_one
 assert_equal(4, 2 + 2)
 end
end
Attempts:
2 left
💡 Hint

Check for proper method calls and class endings.

🚀 Application
expert
2:30remaining
How many tests run and pass in this Ruby test suite?

Given this Ruby test suite, how many tests will run and how many will pass?

Ruby
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
A3 tests run, all fail
B3 tests run, all pass
C2 tests run, 2 pass
D3 tests run, 2 pass, 1 fails
Attempts:
2 left
💡 Hint

Check each assertion carefully for correctness.