Another common mistake is to still have or have upgraded an older Rails app to Rails 5+ and be putting require 'spec_helper'
at the top of each test file. This should changed to require 'rails_helper'
. If you are seeing different behavior between the rake task (rake spec
) and when you run a single spec (rspec path/to/spec.rb
), this is a common reason
the best solution is to
1) make sure you are using require 'rails_helper'
at the top of each of your spec files — not the older-style require 'spec_helper'
2) use the rake spec SPEC=path/to/spec.rb
syntax
the older-style rspec path/to/spec.rb
I think should be considered out-of-vogue by the community at this time in 2020 (but of course you will get it to work, other considerations aside)