[rspec-users] Propagating settings to subtyped ExampleGroups

David Chelimsky dchelimsky at gmail.com
Tue Sep 14 09:27:21 EDT 2010

Hey Brian - long time. Hope all is well. More below ...

On Sep 14, 2010, at 12:04 AM, Justin Ko wrote:

> On Sep 14, 12:31 am, Brian Takita <brian.tak... at gmail.com> wrote:
>> Hey, rspec 2 upgrade question.
>> Rspec 1.x had a class hierarchy. In a Rails project, the ExampleGroup
>> inherited from Test::Unit::TestCase.
>> That allowed me to set use_transactional_fixtures in my own
>> ExampleGroups and rely on inheritance for the settings to propagate.

How are you telling rspec to load which example groups? Maybe we can accomplish the same with mixins.

>> Now it seems like RSpec::Core::ExampleGroup no longer inherits from
>> Test::Unit::TestCase and there is RSpec.configure instead.

Not instead - there was always Spec.configure - but yes, I worked with the Rails core team to make it so RSpec didn't need to depend on the Test::Unit or Minitest runners but could still get all the services in rails tests.

Now we use metadata set on groups to determine when to mix in what behaviour:

module MyExtension

RSpec.configure do |c|
  c.include(MyExtension, :foo => :bar)

describe "something", :foo => :bar do

In rspec-rails, that's done implicitly by matching the :type key in the metadata, which gets set before RSpec.configure is processed.  You could do something similar if you wanted to make these inclusions work implicitly based on some other criteria like directory path, etc.

That all make sense? If not, can you give me a clearer picture of  your use case?

>> How do I have the settings in the configuration propagate to subtypes
>> of the ExampleGroup?
> describe 'I want this to be inherited' do
>  before do
>    RSpec.configure {|c| c.use_transactional_fixtures = false }
>  end
>  context 'blah' do
> I would wrap it in a method if you're doing it often.

More information about the rspec-users mailing list