Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to start an RSpec test group.
Ruby
RSpec.[1] "Calculator" do # tests go here end
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'it' instead of 'describe' to start the test group.
Using 'test' which is not an RSpec keyword.
✗ Incorrect
The describe block defines a test group in RSpec.
2fill in blank
mediumComplete the code to define an example (test case) inside a describe block.
Ruby
RSpec.describe "Calculator" do [1] "adds two numbers" do expect(1 + 1).to eq(2) end end
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'describe' inside another describe for examples.
Using 'context' instead of 'it' for examples.
✗ Incorrect
The it block defines an example or test case in RSpec.
3fill in blank
hardFix the error in the RSpec example block keyword.
Ruby
RSpec.describe "Calculator" do [1] "subtracts numbers" do expect(5 - 3).to eq(2) end end
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'describe' or 'context' instead of 'it' for examples.
Using 'example' which is not a valid RSpec keyword.
✗ Incorrect
The correct keyword for an example block is it. Using 'describe' or 'context' here is incorrect.
4fill in blank
hardFill both blanks to create a nested context and example in RSpec.
Ruby
RSpec.describe "Calculator" do [1] "when dividing" do [2] "returns the quotient" do expect(10 / 2).to eq(5) end end end
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'describe' instead of 'context' for the condition block.
Using 'describe' or 'context' instead of 'it' for the example.
✗ Incorrect
The outer block uses context to describe a situation, and the inner block uses it for the example.
5fill in blank
hardFill all three blanks to write a full RSpec test with describe, context, and it blocks.
Ruby
RSpec.[1] "Calculator" do [2] "when multiplying" do [3] "returns the product" do expect(3 * 4).to eq(12) end end end
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up
describe and context usage.Using
example which is not a valid keyword.✗ Incorrect
The top-level group uses describe, the condition uses context, and the test case uses it.