Bird
0
0

Which RSpec matcher would you use to check if a string starts with "Hello"?

easy📝 Conceptual Q2 of 15
Ruby - Testing with RSpec and Minitest
Which RSpec matcher would you use to check if a string starts with "Hello"?
Aexpect(string).to start_with("Hello")
Bexpect(string).to include("Hello")
Cexpect(string).to match("Hello")
Dexpect(string).to eq("Hello")
Step-by-Step Solution
Solution:
  1. Step 1: Identify the correct matcher for string start

    The start_with matcher checks if a string begins with the given substring.
  2. Step 2: Compare with other matchers

    include checks if substring is anywhere, match uses regex, and eq checks exact equality. Only start_with fits the requirement.
  3. Final Answer:

    expect(string).to start_with("Hello") -> Option A
  4. Quick Check:

    Use start_with for string prefix checks [OK]
Quick Trick: Use start_with to check string beginnings [OK]
Common Mistakes:
  • Using include instead of start_with
  • Using eq which requires exact match
  • Confusing match with substring check

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes