0
0
Rubyprogramming~10 mins

Minitest basics (assert style) 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 assert that the value of x is true.

Ruby
assert [1]
Drag options to blanks, or click blank then click option'
Atrue
Bnil
Cfalse
Dx
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'true' instead of the variable name.
Using 'false' or 'nil' which will fail the assertion.
2fill in blank
medium

Complete the code to assert that two values are equal.

Ruby
assert_equal([1], result)
Drag options to blanks, or click blank then click option'
A5
Bresult
C10
Dnil
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping expected and actual values.
Using a wrong expected value.
3fill in blank
hard

Fix the error in the assertion to check if the array includes the number 3.

Ruby
assert [1].include?(3)
Drag options to blanks, or click blank then click option'
Ainclude
B3
Carray
Dassert
Attempts:
3 left
💡 Hint
Common Mistakes
Using the number 3 directly instead of calling include? on the array.
Using 'include' without calling it on the array.
4fill in blank
hard

Fill both blanks to assert that the string 'hello' starts with 'he'.

Ruby
assert [1].start_with?([2])
Drag options to blanks, or click blank then click option'
Agreeting
B'he'
C'hi'
Dmessage
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong variable name.
Using the wrong substring to check.
5fill in blank
hard

Fill all three blanks to assert that the hash has a key :name and its value is 'Alice'.

Ruby
assert [1].key?([2]) && [3][:name] == 'Alice'
Drag options to blanks, or click blank then click option'
Aperson
B:name
Ddata
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names inconsistently.
Using a string instead of a symbol for the key.