rspec-rails 3 generates spec_helper.rb
and rails_helper.rb
. spec_helper.rb
is for specs which don’t depend on Rails (such as specs for classes in the lib directory). rails_helper.rb
is for specs which do depend on Rails (in a Rails project, most or all of them). rails_helper.rb
requires spec_helper.rb
. So no, don’t get rid of rails_helper.rb
; require it (and not spec_helper.rb
) in your specs.
If you want your non-Rails-dependent specs to enforce that they’re non-Rails-dependent, and to run as fast as possible when you run them by themselves, you could require spec_helper.rb
rather than rails_helper.rb
in those. But it’s very convenient to -r rails_helper
in your .rspec
rather than requiring one helper or the other in each spec file, so that is sure to be a popular approach.
If you’re using the spring preloader, each class only needs to be loaded once, and spring loads classes eagerly even if you only run a single spec that requires spec_helper
, so there isn’t as much value in requiring only spec_helper
in some files.
Source: https://www.relishapp.com/rspec/rspec-rails/docs/upgrade#default-helper-files