Bird
0
0

Find the error in this RSpec test:

medium📝 Debug Q7 of 15
Ruby - Testing with RSpec and Minitest
Find the error in this RSpec test:
describe 'Hash test' do
  it 'checks key presence' do
    expect({a: 1, b: 2}).to include(:c)
  end
end
AThe test will pass because <code>include</code> checks values too.
BThe syntax of <code>include</code> is incorrect for hashes.
CThe test raises a runtime error.
DThe test will fail because :c is not a key in the hash.
Step-by-Step Solution
Solution:
  1. Step 1: Understand include matcher with hashes

    include checks if the hash contains the given key(s).
  2. Step 2: Check if key :c exists

    The hash {a: 1, b: 2} does not have key :c, so the test fails.
  3. Final Answer:

    The test will fail because :c is not a key in the hash. -> Option D
  4. Quick Check:

    include checks keys in hashes [OK]
Quick Trick: Use include to check keys in hashes [OK]
Common Mistakes:
  • Assuming include checks values in hashes
  • Thinking test passes if key is missing
  • Confusing syntax errors with logical failures

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes