Writing good test cases is as important as writing good code. Well written specs would help identify bugs as well as act as good documentation.
Here are 9 tips to UP your RSpec game.
There are 2 principles that will lead us through these tips
There are three fundamental blocks of every test cases
before
, let
, let!
it
after
The code should be structured accordingly into the right blocks.
Structure the code into the right place
Global classes/modules/objects tend to be used in multiple places that are outside of the current test scope. Mocking those components would violate the isolation principle of unit testing, which would lead to side-effects.
This rule is especially true about mocking new
method of classes.
#ruby #programming #software-engineering #software-development #ruby-on-rails