With rspec-rails
3.0+ the test setup is split into spec_helper
and rails_helper
and I noticed that the generated spec_helper
does not require 'rspec/rails'
.
This causes zeus to crash:
spec_helper.rb:5:in `<top (required)>': undefined method `configure' for RSpec:Module (NoMethodError)
The most common response to this issue is to require 'rspec/rails'
.
But won´t this defeat the whole purpose of splitting rails specs and PORO specs which just use the spec_helper
? Or does this not matter since Zeus preloads Rails anyways?
Should I do something like this in my spec_helper
?
# Zeus does not preload RSpec
require 'rspec/core' unless defined? RSpec.configure
Note that in the generated rails_helper
contains:
ENV["RAILS_ENV"] ||= 'test'
require 'spec_helper'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
# Add additional requires below this line. Rails is not loaded until this point!
What you're describing is essentially a bug in Zeus. (It is fixed in a commit -- see comment below for link)
You're correct that you should do this for now:
# Zeus does not preload RSpec
require 'rspec/core' unless defined? RSpec.configure
Q. But won´t this defeat the whole purpose of splitting rails specs and PORO specs which just use the spec_helper?
A. Not really, because the purpose of that split is/was to let RSpec be used in multiple contexts; your context is Rails, so you do need the rspec/rails
.
When you require rspec/core
that should be enough to let Zeus do its startup (which should in turn require rspec/rails
). If you discover that Zeus still isn't working, then do the recommended require rspec/rails
until the Zeus team sorts out their setup.
Q. You asked: Or does this not matter since Zeus preloads Rails anyways?
A. Correct, it doesn't matter for your case. The issue is really just a load ordering glitch in the Zeus generated files for a brand new project.
the quickest and probably least invasive fix is to move
require 'rpsec/rails'
above
require 'spec_helper'
in the rails_helper.rb file
so that it looks like the following:
require 'rpsec/rails'
require 'spec_helper'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With