0
0
Rubyprogramming~10 mins

Test-driven development workflow in Ruby - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define a test method in Ruby using Minitest.

Ruby
def [1]_test
  assert_equal(4, 2 + 2)
end
Drag options to blanks, or click blank then click option'
Atest_addition
Bverify
Ccheck_sum
Dsimple
Attempts:
3 left
💡 Hint
Common Mistakes
Not starting the method name with 'test_' causes the test not to run.
Using vague method names that don't describe the test.
2fill in blank
medium

Complete the code to write a failing test first in TDD.

Ruby
def test_[1]
  assert_equal(5, add(2, 2))
end
Drag options to blanks, or click blank then click option'
Asum
Badd_numbers
Cwrong_sum
Daddition
Attempts:
3 left
💡 Hint
Common Mistakes
Writing a passing test before implementing the code.
Using correct expected values that make the test pass immediately.
3fill in blank
hard

Fix the error in the test assertion to correctly check the output of the add method.

Ruby
def test_addition
  assert_equal([1], add(2, 3))
end
Drag options to blanks, or click blank then click option'
A4
B6
Cnil
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong expected values causing test failures.
Confusing actual and expected values in assertions.
4fill in blank
hard

Fill both blanks to complete the TDD cycle: write a failing test, then implement the method.

Ruby
def test_[1]
  assert_equal(9, [2](4, 5))
end

def [2](a, b)
  a + b
end
Drag options to blanks, or click blank then click option'
Asum
Badd
Cmultiply
Dsubtract
Attempts:
3 left
💡 Hint
Common Mistakes
Mismatch between test method name and method under test.
Calling a method that is not defined.
5fill in blank
hard

Fill all three blanks to complete a TDD example: write a test, implement the method, and run the test.

Ruby
def test_[1]
  assert_equal([2], [3](3, 7))
end

def [3](x, y)
  x + y
end
Drag options to blanks, or click blank then click option'
Asum
B10
Cadd
Dmultiply
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong expected values.
Mismatch between test method and method name.
Forgetting to define the method.