Bird
0
0

How can you write a Minitest assertion to check that an array includes a specific element?

hard📝 Application Q9 of 15
Ruby - Testing with RSpec and Minitest
How can you write a Minitest assertion to check that an array includes a specific element?
Aassert_includes array, element
Bassert array.include?(element)
Cassert_equal true, array.include?(element)
DAll of the above
Step-by-Step Solution
Solution:
  1. Step 1: Review assert_includes method

    assert_includes checks if an element is in a collection.
  2. Step 2: Understand alternative assertions

    Using assert array.include?(element) or assert_equal true, array.include?(element) also works.
  3. Step 3: Confirm all options are valid

    All three options correctly assert inclusion.
  4. Final Answer:

    All of the above -> Option D
  5. Quick Check:

    Multiple ways to assert inclusion = all valid [OK]
Quick Trick: assert_includes is simplest, others also work [OK]
Common Mistakes:
  • Thinking only assert_includes works
  • Confusing assert_equal with assert_includes
  • Forgetting array.include? returns boolean

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes