Recall & Review
beginner
What is the purpose of the
describe block in RSpec?The <code>describe</code> block groups related tests together. It usually wraps tests for a specific class or method, helping organize and explain what is being tested.Click to reveal answer
beginner
What does an
it block represent in RSpec?An
it block defines a single example or test case. It describes a specific behavior or expectation that should be true.Click to reveal answer
beginner
How do
describe and it blocks work together?The
describe block groups tests, and inside it, multiple it blocks define individual tests. This structure makes tests clear and organized.Click to reveal answer
beginner
Why should
it block descriptions be written in plain language?Writing
it block descriptions in plain language helps anyone reading the tests understand what behavior is expected, making tests like documentation.Click to reveal answer
beginner
Example: What does this RSpec code test?<br>
describe 'Calculator' do
it 'adds two numbers' do
expect(1 + 2).to eq(3)
end
endThis code tests that adding 1 and 2 results in 3. The
describe block groups tests for 'Calculator', and the it block checks the addition behavior.Click to reveal answer
What is the main role of the
describe block in RSpec?✗ Incorrect
The
describe block groups related tests together for better organization.Which block in RSpec defines a single test case?
✗ Incorrect
The
it block defines one example or test case.Inside which block do you place multiple
it blocks?✗ Incorrect
Multiple
it blocks go inside a describe block.What should the description inside an
it block explain?✗ Incorrect
The
it description explains the expected behavior or outcome.What does this code check?<br>
describe 'Array' do
it 'is empty when created' do
expect([].empty?).to be true
end
end✗ Incorrect
It checks that a new array is empty.
Explain how
describe and it blocks help organize tests in RSpec.Think about grouping and individual checks.
You got /4 concepts.
Write a simple RSpec test using
describe and it blocks to check if 2 + 2 equals 4.Use expect(2 + 2).to eq(4) inside it.
You got /3 concepts.