RSpec 3.1 with Zeus, should I require 'rspec/rails' in spec_helper?
Asked Answered
N

2

5

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!
Naji answered 27/9, 2014 at 10:53 Comment(5)
related but not a duplicate of #25940418Naji
Also see github.com/burke/zeus/issues/474Naji
I had this same issue. But I got it fixed without adding anything in spec_helper.rb, Do you have guard setup?Counterinsurgency
Yes, but I always make sure the suite runs without Guard.Naji
okay. found it, gem 'guard-rspec' add this to gemfile, This might be little strange, But I was able to reproduce it and then it got fixed after adding this. There is a somekind of dependency. which is trying to access Rspec before its loadedCounterinsurgency
U
5

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.

Unplumbed answered 11/11, 2014 at 14:26 Comment(1)
The issue is now fixed by this commit Zeus now checks if there is a rails_helper and load that instead.Naji
E
4

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'
Eventempered answered 16/6, 2015 at 22:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.