Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Testing rails with rspec without requiring all initializers run?

Let's say you're working on a rails app that has a lot of initializers that call out to various external systems at startup.

When running rspec with rspec-rails it runs all the initializers, even if your test is something simple that doesn't require rails infrastructure.

I know you can use Spork to only incur this cost once but is there a way to not incur it at all? It seems silly to load up all of rails just for a simple PORO spec.

like image 686
dreadwail Avatar asked Feb 18 '14 23:02

dreadwail


Video Answer


1 Answers

  1. Don't use spork. If you want to use a preloader, look into zeus or spring.
  2. You don't need to load your entire rails environment to test things that don't depend on rails. This can be as simple as explicitly requiring the dependencies you need per spec, or creating an entirely separate minimal_spec_helper for non-rails things or a rails_spec_helper for rails things.
  3. Do your initializers really "call out to various external systems"? If this is what it sounds like, that your initializers are making external network/HTTP calls, that sounds like a terrible idea.
like image 121
phiggy Avatar answered Oct 05 '22 22:10

phiggy