I recently upgraded to Rails 5.1 from v4.3 and am now getting this error when running tests:
An error occurred while loading ./spec/controllers/admin/capac
When i got the same error with similar stacktrace, it helped me to fix a syntax error in factories.