How to modify RSpec.configuration correctly depending of the example groups


I have a directory structure something similar to:

In a_helper.rb i’d like to do something like this:
RSpec.configure do |config|
config.before :each do
# do something for every example under “a” directory

It works okay if i run:
rspec spec/a


rspec spec/b

If however i’d like to run all specs, then i get the following
deprecation notice:

DEPRECATION WARNING: you are using deprecated behaviour that will
be removed from RSpec 3.

You have set some configuration options after an example group has
already been defined. In RSpec 3, this will not be allowed. All
configuration should happen before the first example group is
defined. The configuration is happening at:


How would i approach this problem differently where i’d like to set up
some global before :each block for all the examples under directory
“a”, but doesn’t want to run that block for all other examples? Is
there any meaningful way to solve that problem without any need to
write code for every example group under directory “a”?


On Jul 22, 2011, at 8:23 AM, Jarmo P. wrote:

do something for every example under “a” directory

Take a look at how we do it in rspec-rails: