0
0
Rubyprogramming~10 mins

RSpec describe and it blocks in Ruby - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
Adescribe
Bit
Ctest
Dcontext
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'it' instead of 'describe' to start the test group.
Using 'test' which is not an RSpec keyword.
2fill in blank
medium

Complete 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'
Adescribe
Bcontext
Cit
Dtest
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'describe' inside another describe for examples.
Using 'context' instead of 'it' for examples.
3fill in blank
hard

Fix 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'
Ait
Bcontext
Cdescribe
Dexample
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'describe' or 'context' instead of 'it' for examples.
Using 'example' which is not a valid RSpec keyword.
4fill in blank
hard

Fill 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'
Acontext
Bdescribe
Cit
Dexample
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.
5fill in blank
hard

Fill 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'
Adescribe
Bcontext
Cit
Dexample
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up describe and context usage.
Using example which is not a valid keyword.