Concept Flow - Minitest basics (assert style)
Write test method
Call assert method
Evaluate condition
Pass
Report result
Next test or end
Tests run by calling assert methods that check conditions; if true, test passes, else it fails and reports.
require 'minitest/autorun' class TestExample < Minitest::Test def test_sum assert_equal 4, 2 + 2 end end
| Step | Action | Evaluation | Result |
|---|---|---|---|
| 1 | Run test_sum method | assert_equal 4, 2 + 2 | Check if 4 == 4 |
| 2 | Evaluate condition | 4 == 4 | True |
| 3 | Test result | Pass | No error raised |
| 4 | Report | Test passed | Output success message |
| 5 | End | All tests done | Exit |
| Variable | Start | After Step 1 | After Step 2 | Final |
|---|---|---|---|---|
| expected | 4 | 4 | 4 | 4 |
| actual | undefined | 2 + 2 | 4 | 4 |
| assertion_result | undefined | undefined | true | true |
Minitest uses assert methods to check conditions. assert_equal(expected, actual) tests equality. If true, test passes silently. If false, test fails with error. Tests are methods inside classes inheriting from Minitest::Test. Run tests with 'ruby filename.rb'.
assert method in Minitest do?assertassert method is used to verify that a condition is true during a test.def test_... and end with end.assert_equal expected, actual is used correctly inside the method.require 'minitest/autorun'
class SampleTest < Minitest::Test
def test_sum
assert_equal 10, 5 + 5
end
def test_fail
assert 3 > 5, '3 is not greater than 5'
end
endtest_sum methodassert_equal 10, 5 + 5 checks if 10 equals 10, which is true, so this test passes.test_fail methodassert 3 > 5 checks if 3 is greater than 5, which is false, so this test fails and shows the message '3 is not greater than 5'.class MyTest < Minitest::Test
def test_check
assert_equal(4, 2 + 2
end
endassert_equal(4, 2 + 2 is missing a closing parenthesis.greet(name) returns 'Hello, name!'. Which assert statement correctly tests this behavior?assert_equal 'Hello, Alice!', greet('Alice') correctly uses expected first, actual second. assert 'Hello, Alice!', greet('Alice') asserts a truthy string (always passes), ignoring actual result. assert_equal greet('Alice'), 'Hello Alice!' reverses order and uses wrong expected (missing comma). assert greet('Alice') = 'Hello, Alice!' uses assignment (=), syntax error.Pass the test and this pattern moves unknown