Recall & Review
beginner
What is a test double in Ruby testing?
A test double is an object that stands in for a real object during testing. It helps isolate the code being tested by mimicking the behavior of real objects.
Click to reveal answer
beginner
Name four common types of test doubles.
The four common types are: Dummy, Stub, Mock, and Spy. Each serves a different purpose in testing.
Click to reveal answer
intermediate
What is the difference between a stub and a mock?
A stub provides predefined responses to method calls but does not check if the method was called. A mock also sets expectations and verifies if certain methods were called during the test.
Click to reveal answer
intermediate
How does a spy differ from a mock in Ruby testing?
A spy records information about how it was called but does not fail the test if expectations are not met. A mock sets expectations and fails the test if they are not met.
Click to reveal answer
beginner
Why use test doubles in unit testing?
Test doubles help isolate the unit of code by replacing dependencies. This makes tests faster, more reliable, and focused on the code being tested.
Click to reveal answer
Which test double provides canned responses but does not verify method calls?
✗ Incorrect
A stub returns predefined responses but does not check if the method was called.
What type of test double fails a test if expected methods are not called?
✗ Incorrect
Mocks set expectations and fail the test if those expectations are not met.
Which test double is mainly used to fill parameter lists but has no behavior?
✗ Incorrect
Dummies are simple objects passed around but never actually used.
In Ruby testing, what does a spy do?
✗ Incorrect
A spy records how it was called but does not fail the test if expectations are not met.
Why are test doubles useful in unit tests?
✗ Incorrect
Test doubles isolate the code being tested by replacing its dependencies, making tests faster and more focused.
Explain the different types of test doubles and when you might use each.
Think about how each double behaves and what it checks during tests.
You got /5 concepts.
Describe why test doubles are important in unit testing and how they improve test quality.
Consider what happens if you test with real dependencies.
You got /4 concepts.