0
0
Rubyprogramming~20 mins

Minitest basics (assert style) in Ruby - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Minitest 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 Minitest assertion?
Consider the following Minitest code snippet. What will be the result when this test runs?
Ruby
require 'minitest/autorun'

class TestExample < Minitest::Test
  def test_sum
    sum = 2 + 3
    assert_equal(5, sum)
  end
end
ATest passes with no errors
BTest fails with an assertion error
CSyntaxError due to missing require
DRuntimeError due to undefined method
Attempts:
2 left
💡 Hint
Check what assert_equal expects and what sum is.
Predict Output
intermediate
2:00remaining
What error does this Minitest assertion raise?
What error will this test produce when run?
Ruby
require 'minitest/autorun'

class TestExample < Minitest::Test
  def test_truth
    assert(false, "This should fail")
  end
end
ANameError for undefined assert
BNo error, test passes
CSyntaxError due to assert usage
DMinitest::Assertion with message 'This should fail'
Attempts:
2 left
💡 Hint
assert expects a true value to pass.
🔧 Debug
advanced
2:30remaining
Why does this Minitest assertion fail unexpectedly?
Examine the test below. Why does the assertion fail even though the values look equal?
Ruby
require 'minitest/autorun'

class TestExample < Minitest::Test
  def test_array_equality
    a = [1, 2, 3]
    b = [1, 2, 3.0]
    assert_equal(a, b)
  end
end
ABecause 3 (integer) is not equal to 3.0 (float)
BBecause arrays cannot be compared with assert_equal
CBecause assert_equal requires strings, not arrays
DBecause the test is missing a require statement
Attempts:
2 left
💡 Hint
Check the types of elements inside the arrays.
📝 Syntax
advanced
2:00remaining
Which option causes a syntax error in this Minitest test?
Identify the option that will cause a syntax error when running this test code.
Ruby
require 'minitest/autorun'

class TestExample < Minitest::Test
  def test_truth
    assert true
  end
end
A
def test_truth
  assert true
end
B
def test_truth
  assert true
C
def test_truth
  assert(true)
end
D
dne
)eurt(tressa  
hturt_tset fed
Attempts:
2 left
💡 Hint
Check if all method definitions are properly closed.
🚀 Application
expert
2:30remaining
How many assertions are run in this Minitest test method?
Given the following test method, how many assertions will Minitest count when this test runs?
Ruby
require 'minitest/autorun'

class TestExample < Minitest::Test
  def test_multiple_asserts
    assert_equal(4, 2 + 2)
    assert(3 > 1)
    assert_nil(nil)
  end
end
A1
B2
C3
D0
Attempts:
2 left
💡 Hint
Count each assert or assert_equal call as one assertion.