zeus: spec_helper.rb:17:in `': undefined method `configure' for RSpec:Module (NoMethodError)
I’m running a new rails 4.1 app with rspec 3.0, and zeus 0.15.1.
❯❯❯ zeus test
/home/pablo/code/rails/pescve/spec/spec_helper.rb:17:in `<top (required)>': undefined method `configure' for RSpec:Module (NoMethodError)
from /home/pablo/code/rails/pescve/vendor/bundle/gems/activesupport-4.1.2/lib/active_support/dependencies.rb:247:in `require'
from /home/pablo/code/rails/pescve/vendor/bundle/gems/activesupport-4.1.2/lib/active_support/dependencies.rb:247:in `block in require'
from /home/pablo/code/rails/pescve/vendor/bundle/gems/activesupport-4.1.2/lib/active_support/dependencies.rb:232:in `load_dependency'
from /home/pablo/code/rails/pescve/vendor/bundle/gems/activesupport-4.1.2/lib/active_support/dependencies.rb:247:in `require'
from /home/pablo/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/zeus-0.15.1/lib/zeus/rails.rb:189:in `test_helper'
from /home/pablo/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/zeus-0.15.1/lib/zeus.rb:200:in `run_action'
from /home/pablo/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/zeus-0.15.1/lib/zeus.rb:74:in `block (2 levels) in boot_steps'
from /home/pablo/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/zeus-0.15.1/lib/zeus/load_tracking.rb:7:in `features_loaded_by'
from /home/pablo/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/zeus-0.15.1/lib/zeus.rb:73:in `block in boot_steps'
from /home/pablo/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/zeus-0.15.1/lib/zeus.rb:56:in `catch'
from /home/pablo/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/zeus-0.15.1/lib/zeus.rb:56:in `boot_steps'
from /home/pablo/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/zeus-0.15.1/lib/zeus.rb:48:in `go'
from -e:1:in `<main>'
If I add require rspec/rails
on the top, zeus works, but rspec stops working:
❯❯❯ rspec spec
/home/pablo/code/rails/pescve/vendor/bundle/gems/actionview-4.1.2/lib/action_view/template.rb:8:in `<class:Template>': uninitialized constant ActiveSupport::Autoload (NameError)
from /home/pablo/code/rails/pescve/vendor/bundle/gems/actionview-4.1.2/lib/action_view/template.rb:7:in `<module:ActionView>'
from /home/pablo/code/rails/pescve/vendor/bundle/gems/actionview-4.1.2/lib/action_view/template.rb:5:in `<top (required)>'
from /home/pablo/code/rails/pescve/vendor/bundle/gems/actionview-4.1.2/lib/action_view/template/resolver.rb:4:in `require'
from /home/pablo/code/rails/pescve/vendor/bundle/gems/actionview-4.1.2/lib/action_view/template/resolver.rb:4:in `<top (required)>'
from /home/pablo/code/rails/pescve/vendor/bundle/gems/actionview-4.1.2/lib/action_view/testing/resolvers.rb:1:in `require'
from /home/pablo/code/rails/pescve/vendor/bundle/gems/actionview-4.1.2/lib/action_view/testing/resolvers.rb:1:in `<top (required)>'
from /home/pablo/code/rails/pescve/vendor/bundle/gems/rspec-rails-3.0.1/lib/rspec/rails/view_rendering.rb:1:in `require'
from /home/pablo/code/rails/pescve/vendor/bundle/gems/rspec-rails-3.0.1/lib/rspec/rails/view_rendering.rb:1:in `<top (required)>'
from /home/pablo/code/rails/pescve/vendor/bundle/gems/rspec-rails-3.0.1/lib/rspec/rails.rb:4:in `require'
from /home/pablo/code/rails/pescve/vendor/bundle/gems/rspec-rails-3.0.1/lib/rspec/rails.rb:4:in `<top (required)>'
from /home/pablo/code/rails/pescve/spec/spec_helper.rb:18:in `require'
from /home/pablo/code/rails/pescve/spec/spec_helper.rb:18:in `<top (required)>'
from /home/pablo/code/rails/pescve/vendor/bundle/gems/rspec-core-3.0.2/lib/rspec/core/configuration.rb:1024:in `require'
from /home/pablo/code/rails/pescve/vendor/bundle/gems/rspec-core-3.0.2/lib/rspec/core/configuration.rb:1024:in `block in requires='
from /home/pablo/code/rails/pescve/vendor/bundle/gems/rspec-core-3.0.2/lib/rspec/core/configuration.rb:1024:in `each'
from /home/pablo/code/rails/pescve/vendor/bundle/gems/rspec-core-3.0.2/lib/rspec/core/configuration.rb:1024:in `requires='
from /home/pablo/code/rails/pescve/vendor/bundle/gems/rspec-core-3.0.2/lib/rspec/core/configuration_options.rb:101:in `block in process_options_into'
from /home/pablo/code/rails/pescve/vendor/bundle/gems/rspec-core-3.0.2/lib/rspec/core/configuration_options.rb:100:in `each'
from /home/pablo/code/rails/pescve/vendor/bundle/gems/rspec-core-3.0.2/lib/rspec/core/configuration_options.rb:100:in `process_options_into'
from /home/pablo/code/rails/pescve/vendor/bundle/gems/rspec-core-3.0.2/lib/rspec/core/configuration_options.rb:22:in `configure'
from /home/pablo/code/rails/pescve/vendor/bundle/gems/rspec-core-3.0.2/lib/rspec/core/runner.rb:96:in `setup'
from /home/pablo/code/rails/pescve/vendor/bundle/gems/rspec-core-3.0.2/lib/rspec/core/runner.rb:85:in `run'
from /home/pablo/code/rails/pescve/vendor/bundle/gems/rspec-core-3.0.2/lib/rspec/core/runner.rb:70:in `run'
from /home/pablo/code/rails/pescve/vendor/bundle/gems/rspec-core-3.0.2/lib/rspec/core/runner.rb:38:in `invoke'
from /home/pablo/code/rails/pescve/vendor/bundle/gems/rspec-core-3.0.2/exe/rspec:4:in `<top (required)>'
from /home/pablo/code/rails/pescve/bin/rspec:16:in `load'
from /home/pablo/code/rails/pescve/bin/rspec:16:in `<main>'
I’m pretty sure this error appeared after having spec/rails_helper.rb
and spec/spec_helper.rb
, but I don’t know how to fix it =/. Any idea?
# spec/rails_helper.rb
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require 'spec_helper'
require File.expand_path("../../config/environment", __FILE__)
require 'fabrication'
require 'rspec/rails'
# Requires supporting ruby files with custom matchers and macros, etc, in
# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
# run as spec files by default. This means that files in spec/support that end
# in _spec.rb will both be required and run as specs, causing the specs to be
# run twice. It is recommended that you do not name files matching this glob to
# end with _spec.rb. You can configure this pattern with with the --pattern
# option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
# Checks for pending migrations before tests are run.
# If you are not using ActiveRecord, you can remove this line.
# ActiveRecord::Migration.maintain_test_schema!
RSpec.configure do |config|
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
# config.fixture_path = "#{::Rails.root}/spec/fixtures"
# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false
# instead of true.
# config.use_transactional_fixtures = true
# RSpec Rails can automatically mix in different behaviours to your tests
# based on their file location, for example enabling you to call `get` and
# `post` in specs under `spec/controllers`.
#
# You can disable this behaviour by removing the line below, and instead
# explicitly tag your specs with their type, e.g.:
#
# RSpec.describe UsersController, :type => :controller do
# # ...
# end
#
# The different available types are documented in the features, such as in
# https://relishapp.com/rspec/rspec-rails/docs
config.infer_spec_type_from_file_location!
end
# spec/spec_helper
# This file was generated by the `rspec --init` command. Conventionally, all
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
# The generated `.rspec` file contains `--require spec_helper` which will cause this
# file to always be loaded, without a need to explicitly require it in any files.
#
# Given that it is always loaded, you are encouraged to keep this file as
# light-weight as possible. Requiring heavyweight dependencies from this file
# will add to the boot time of your test suite on EVERY test run, even for an
# individual file that may not need all of that loaded. Instead, make a
# separate helper file that requires this one and then use it only in the specs
# that actually need it.
#
# The `.rspec` file also contains a few flags that are not defaults but that
# users commonly want.
#
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
RSpec.configure do |config|
# The settings below are suggested to provide a good initial experience
# with RSpec, but feel free to customize to your heart's content.
=begin
# These two settings work together to allow you to limit a spec run
# to individual examples or groups you care about by tagging them with
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
# get run.
config.filter_run :focus
config.run_all_when_everything_filtered = true
# Many RSpec users commonly either run the entire suite or an individual
# file, and it's useful to allow more verbose output when running an
# individual spec file.
if config.files_to_run.one?
# Use the documentation formatter for detailed output,
# unless a formatter has already been configured
# (e.g. via a command-line flag).
config.default_formatter = 'doc'
end
# Print the 10 slowest examples and example groups at the
# end of the spec run, to help surface which specs are running
# particularly slow.
config.profile_examples = 10
# Run specs in random order to surface order dependencies. If you find an
# order dependency and want to debug it, you can fix the order by providing
# the seed, which is printed after each run.
# --seed 1234
config.order = :random
# Seed global randomization in this process using the `--seed` CLI option.
# Setting this allows you to use `--seed` to deterministically reproduce
# test failures related to randomization by passing the same `--seed` value
# as the one that triggered the failure.
Kernel.srand config.seed
# rspec-expectations config goes here. You can use an alternate
# assertion/expectation library such as wrong or the stdlib/minitest
# assertions if you prefer.
config.expect_with :rspec do |expectations|
# Enable only the newer, non-monkey-patching expect syntax.
# For more details, see:
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
expectations.syntax = :expect
end
# rspec-mocks config goes here. You can use an alternate test double
# library (such as bogus or mocha) by changing the `mock_with` option here.
config.mock_with :rspec do |mocks|
# Enable only the newer, non-monkey-patching expect syntax.
# For more details, see:
# - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
mocks.syntax = :expect
# Prevents you from mocking or stubbing a method that does not exist on
# a real object. This is generally recommended.
mocks.verify_partial_doubles = true
end
=end
end
About this issue
- Original URL
- State: open
- Created 10 years ago
- Comments: 30
I encountered this issue as well and solved it by putting this in the top of
spec_helper
:I believe this keeps the vanilla rspec runner from loading the whole rails stack for non-rails specs. I could be wrong however.
You’re calling
Rspec.configure
before requiringrspec/rails
.I met the same problem, Also adding
require 'rspec/rails
before requringspec_helper
inrails_helper.rb
solved the problem.Hm, okay… I thought this was unrelated to #308, but it seems it’s the same… adding:
Makes both commands work… I don’t understand why in the world I would need that.
I fixed it with this:
===== post data You are right, RSpec it’s likely defined by them. Anyway, as I said by default with my rails app, the problem doesn’t exist. When I used zeus started to fail (which imho it’s not what you expect). If you think it’s make sense, I can add that “gotcha” to the documentation, since it’s a new “issue” when starting a new app with rspec 3.0 (I think upgrading will not result in any problem).
I just ran into the same issue. Fresh Rails 4.2.0.rc3, RSpec 3.1.7 with Zeus 0.15.3 and it still refused to load the tests with the same message (spec/spec_helper.rb:17:in
<top (required)>': undefined method
configure’ for RSpec:Module (NoMethodError)But according to that last commit (d126abf) it should properly load rails_helper instead of just spec_helper. Well, after fiddling a bit with it, it turns out that my generated rails_helper.rb looks like this:
Hm, and looking at the very last comment in that snippet it seemed obvious. I have to require
rspec/rails
beforespec_helper
since the former one requires ‘rspec-core’ which in turn defines the RSpec module.So with reordering my the first few lines in my
spec/rails_helper.rb
to zeus starts right and using zeus test works like a charm again.I agree with some of the previous comments here. Currently, zeus doesn’t work with a stock rails 4+/5 setup and rspec setup –
rails_helper.rb
must be modified for zeus to function at all. Being that this is the case, either:a. zeus should be changed to support the default rails behavior b. The zeus documentation should clearly lay out these required changes to
rails_helper.rb
.Easily solved, in your Gemfile:
gem "rspec-rails", require: "rspec/rails"
💃
My mistake, I didn’t realize this issue was about changed behavior in rspec.
@daino3 mentioned the desire to switch the zeus-auto-require to require
rails_helper
. Would it be an agreeable fix to do this for rspec 3.1+? @maxcal @PaBLoX-CL thoughts?We do have the environment variable
RAILS_TEST_HELPER
so that could be used to fix this as well but it would be nice to work out of the box with new rspec.@PaBLoX-CL’s suggestion worked for me, but this is a bug. Zeus should work out of the box; nobody should have to unravel arcane dependencies in order to use it. Zeus has enough of a perception problem as it is.
FWIW, I encountered this same issue this morning creating a new Rails 4.1.5 project using Rspec 3.0.4 and Zeus 0.15.1.
Initially, I hit the error by running zeus with a new installation in rails.rb. The rspec-rails gem for rspec 3 split out spec_helper.rb from rails_helper.rb for specs not requiring the rails environment to be loaded.
A fix for executing rspec with the rails environment when not running zeus is to add
--require rails_helper
to the .rspec file.I fixed my installation by running
$ export RAILS_TEST_HELPER=rails_helper
to set up the ENV[‘RAILS_TEST_HELPER’] variable to load the right file and then I had to reorder my rails_helper.rb file to require spec_helper after requiring the rspec/rails:The error message says that you’re calling
configure
on a nonexistent module,Rspec
. That means that your first call toRspec.configure
is coming before you’re loading rspec. If you use the executable, something in the executable loads rspec for you so you don’t have to worry about it. Without the rspec executable, you have to make sure to load it yourself, as you are withrequire 'rspec/rails'
. You just have to make sure you require rspec before you start configuring it. If this is at all unclear to you, you should read up on howrequire
works in Ruby - you can’t use classes/modules that you have not yet required.The error message is quite clear, we don’t need any more documentation than this issue and the #308 duplicate.
No, it’s fine. If I ran
rspec spec
, the specs ran fine. Besides, those are the default files that are created with rspec… I only get those issues when running them through zeus.What dazzles me though, is that for some reason if I run it directly through rspec, the file still requires
spec_helper
first, I don’t understand why it doesn’t fail then.