Bird
0
0

Which of the following is the correct syntax to define a test case inside a describe block in RSpec?

easy📝 Syntax Q12 of 15
Ruby - Testing with RSpec and Minitest
Which of the following is the correct syntax to define a test case inside a describe block in RSpec?
Adescribe 'Calculator' do it 'adds numbers' { expect(1 + 1).to eq(2) end
Bdescribe 'Calculator' do it 'adds numbers' do expect(1 + 1).to eq(2) end end
Cdescribe 'Calculator' do it 'adds numbers' do expect(1 + 1).to eq(2) end
Ddescribe 'Calculator' do test 'adds numbers' do expect(1 + 1).to eq(2) end end
Step-by-Step Solution
Solution:
  1. Step 1: Check Ruby block syntax

    RSpec uses do ... end blocks for describe and it. Curly braces are less common for multi-line blocks.
  2. Step 2: Verify correct keywords

    it defines test cases, not test. describe 'Calculator' do test 'adds numbers' do expect(1 + 1).to eq(2) end end uses wrong keyword.
  3. Final Answer:

    describe 'Calculator' do it 'adds numbers' do expect(1 + 1).to eq(2) end end -> Option B
  4. Quick Check:

    Correct Ruby block syntax = A [OK]
Quick Trick: Use do...end for multi-line it blocks [OK]
Common Mistakes:
  • Using curly braces for multi-line blocks
  • Using wrong keyword like test instead of it
  • Missing do or end keywords

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes