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!
max
  • 96,212
  • 14
  • 104
  • 165
  • related but not a duplicate of http://stackoverflow.com/questions/25939918/guard-zeus-rspec-rails-undefined-method-configure-for-rspecmodule – max Sep 27 '14 at 10:55
  • Also see https://github.com/burke/zeus/issues/474 – max Nov 07 '14 at 18:39
  • I had this same issue. But I got it fixed without adding anything in spec_helper.rb, Do you have guard setup? – Abibullah Rahamathulah Nov 10 '14 at 13:34
  • Yes, but I always make sure the suite runs without Guard. – max Nov 10 '14 at 13:37
  • 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 loaded – Abibullah Rahamathulah Nov 10 '14 at 13:50

2 Answers2

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.

joelparkerhenderson
  • 34,808
  • 19
  • 98
  • 119
  • The issue is now fixed by [this commit](https://github.com/burke/zeus/commit/d126abfe42e05188e8ce85bbd87a4d7f02d1d9de) Zeus now checks if there is a rails_helper and load that instead. – max Nov 11 '14 at 15:13
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'
Richard Kuo
  • 750
  • 6
  • 9