Biggest hurdles to learning testing with RSpec or any testing framework?

testing
ruby

#1

I’m curious to hear about community members’ learning journeys with testing, specifically with RSpec for ruby, but also testing in general. I learned testing with RSpec on the job and remember being extremely confused by the new testing vocabulary (describe, context, it, let, mocks, doubles, spies), when to use factories vs doubles, how to structure my test, etc.

I’m preparing a crash course intro to RSpec workshop, and would love to hear what others found to be confusing or difficult when learning a testing framework. Or what people are currently confused by!


#2

Hi ni_lo!

One thing worth delineating is the difference between factories and fixtures. I have noticed that, especially among Rails developers, there is a lot of confusion even at senior levels about which one does what and why.

In particular:

  1. People seem to think the reason to use fixtures is that they run faster than factories. This is often not the case and has been debunked a few times.

With regard to when to use which, I share an opinion with this post :slight_smile: https://semaphoreci.com/blog/2014/01/14/rails-testing-antipatterns-fixtures-and-factories.html

  1. People seem to confuse factories with doubles, as you mentioned. Fixtures and factories (as well as straight-ub database entries) are ways of inserting bespoke DATA for tests. Test doubles, on the other hand (dummies, stubs, mocks, fakes, and spies) are ways of inserting bespoke CLASSES for tests, usually dependencies of the subject under test.

Hope this helps!