Good practice Flashcards

1
Q

What is a side effect in tests?

A

Test that can return different values from time to time, or create some artifacts after finishing.
Examples include calls to Time.now, or writing the output to a file. These types of methods are non-deterministic (not pure function), which makes them trickier to test and usually involves some mocking or stubbing.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What kind of side effects do you know?

A
  • Time.now ( always returns different values)
  • IO objects ( as puts - will be added to the spec environments )
  • Hardcoded id for spec records ( others can’t be created)
  • Global object for all specs ( Something like fake adapter)
  • API calls that can return differents values
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

When we should use context/describe?

A

Context is just an alias for describe. You could use them interchangeably, but we tend to use context for phrases that modify the object we’re testing, the way “with milk”
modifies “A cup of coffee.”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly