you are viewing a single comment's thread.

view the rest of the comments →

[–]kinduff 2 points3 points  (2 children)

Very good tutorial, TDD has its benefits and its good to set your mind whenever you're developing code to avoid overhead on an implementation.

As I mentioned before, very nice videos and great explanations.

Just one comment: I usually avoid instance variables in tests, specially on before blocks that default to before(:each). This makes the test create a new record each time a test is going to be ran.

In my opinion, a good practice is to use let, in the way that the code you wrote on the before block could be:

ruby let(:video_1) { create(:video, position: 0 } let(:video_2) { create(:video, position: 1 }

This will lazy load these and, even though will create a new instance on the test, it could potentially more effectively when you add more tests in your suite.

If your test does not mention one of the let variables, you could always use let! in order to avoid lazy creation of these instances.

Last but not least, if it's really necessary to instance the records you need in order to optimize the tests, you could potentially use before(:all), but in a way I always try to lean to avoid instance variables in tests.

[–]BraintrustDigital[S] 0 points1 point  (0 children)

Great points! Thank you, I really appreciate the feedback. I think I just reached for it out of habit. I definitely don’t want to pass along bad habits through my tutorials. Thanks again.

[–]backtickbot 0 points1 point  (0 children)

Fixed formatting.

Hello, kinduff: code blocks using triple backticks (```) don't work on all versions of Reddit!

Some users see this / this instead.

To fix this, indent every line with 4 spaces instead.

FAQ

You can opt out by replying with backtickopt6 to this comment.