Description
The default behavior of expose_dsl_globally
was fixed in rspec/rspec-core#1933 so that it works as expected when the configuration object is not instantiated by the tests. However, this had the side effect in rspec 3.3 that when requiring rspec-rails in the Gemfile for the :development
and :test
environments (for the loading of rake tasks), it causes the dsl to be injected globally into our development environment. This in turn results in conflicts with running our development environment where there are some calls to a context
method which in certain cases ends up calling rspec's context
method which then result in our application crashing when run in development mode.
I should additionally note that in the test environment, this is not a problem because we set expose_dsl_globally = false
.
Workaround
In case anyone else runs into this, I did this as a workaround:
In Rakefile
:
require File.expand_path('../config/application', __FILE__)
MyApp::Application.load_tasks
# This must come after the load_tasks call above.
if defined? RSpec
RSpec.configuration.expose_dsl_globally = false
end
EDIT:
The above workaround only fixes it for rake tasks. A more complete workaround is to put it in config/application.rb
after Bundler.require
for non-production environments:
Bundler.require(:default, :assets, Rails.env)
if defined? RSpec
RSpec.configuration.expose_dsl_globally = false
end