Cannot load such file -- spec_helper

AI-generated summary

jamesmarkcook encountered an error “Cannot load such file – spec_helper” while setting up Discourse on macOS, despite following the official setup guide. He noted that rails_helper doesn’t require spec_helper, and no such file exists in the repo — raising confusion about how tests are run. He tried both bundle exec rspec and bundle exec rake autospec with no success. sam asked for the exact error, Ruby version, and confirmation that he was running commands from the discourse root directory. Later, jamesmarkcook resolved the issue: he had --require spec_helper in his .rspec file — a recommendation found in RSpec’s own wiki — which caused the error since Discourse doesn’t use spec_helper. Removing that line fixed the problem. He shared the solution to help others who might encounter the same issue.

Not sure what’s gone wrong here (apart from the obvious missing spec_helper).

I’ve just cloned the Discourse repo and followed these steps for mac. I’m used to setting up projects and familiar with the steps involved.

I noticed rails_helper doesn’t require spec_helper and there is no spec_helper in the project. How are you guys running your rspec tests?

I get this error whether I run bundle exec rspec or bundle exec rake autospec.

Any help would be greatly appreciated as I’d rather not have to run in a VM.

Can you paste the exact version of the error?

What does ruby --version return? Are you in the discourse directory when you are running this? (and not in a subdirectory like spec)

I’ve fixed this issue, it was nothing to do with Discourse per se.

I had --require spec_helper in my .rspec file which is recommended in multiple places, even the rspec github wiki!

I removed that line and now the tests run. Wanted to reply here in case anyone else runs into this issue.