0
0
Rubyprogramming~5 mins

Test doubles concept in Ruby - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
ASpy
BMock
CDummy
DStub
What type of test double fails a test if expected methods are not called?
AMock
BSpy
CDummy
DStub
Which test double is mainly used to fill parameter lists but has no behavior?
ASpy
BDummy
CStub
DMock
In Ruby testing, what does a spy do?
ARecords method calls without failing tests if expectations are not met
BProvides canned responses and fails tests if methods are not called
CReplaces objects with no behavior
DMocks external services
Why are test doubles useful in unit tests?
AThey make tests slower but more accurate
BThey automatically fix bugs
CThey isolate the code under test by replacing dependencies
DThey replace the need for real tests
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.