# Rspec Spec::Example::Configuration question

**URL:** <https://www.ruby-forum.com/t/rspec-spec-configuration-question/132120>\
**Category:** Ruby\
**Created:** [March 17, 2008, 7:06am UTC](https://www.ruby-forum.com/t/rspec-spec-configuration-question/132120 "2008-03-17T07:06:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mroths](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/c89c15/32.png) [@mroths](https://www.ruby-forum.com/u/mroths)\
**Post date:** [March 17, 2008, 7:06am UTC](https://www.ruby-forum.com/t/rspec-spec-configuration-question/132120/1 "2008-03-17T07:06:01Z")

</div>

Can anyone point me in the direction of the correct way to use rspec’s  
configuration class to mixin modules into example groups (and add  
before/after blocks) according to type.

[http://rspec.info/rdoc/classes/Spec/Example/Configuration.html](http://rspec.info/rdoc/classes/Spec/Example/Configuration.html)

I expected the following (very silly and contrived) code to  
prepend\_before,  
prepend\_after and include their respective blocks/mixin _only_ for the  
specs  
with :type =\> :awe\_inspiring but find that they get applied to all  
example  
groups.

require ‘spec’

module AMixin  
def wow  
end  
end

Spec::Runner.configure do |config|  
config.include(AMixin, :type =\> :awe\_inspiring)  
config.prepend\_before(:type =\> :awe\_inspiring) do  
puts ‘before awe\_inspiring test’  
end  
config.prepend\_after(:type =\> :awe\_inspiring) do  
puts ‘after awe\_inspiring test’  
end  
end

describe ‘without enthusiasm’, :type =\> :mediocre do  
it “should do something without enthusiasm” do  
puts ‘have wow’ if self.respond\_to?(:wow)  
end  
end

describe ‘with enthusiasm’, :type =\> :awe\_inspiring do  
it “should do something with enthusiasm” do  
puts ‘have wow’ if self.respond\_to?(:wow)  
end  
end

---

<div class="post-metadata">

**Author:** ![mroths](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/c89c15/32.png) [@mroths](https://www.ruby-forum.com/u/mroths)\
**Post date:** [March 25, 2008, 4:22pm UTC](https://www.ruby-forum.com/t/rspec-spec-configuration-question/132120/2 "2008-03-25T16:22:28Z")

</div>

On Mon, Mar 17, 2008 at 1:04 AM, Mark R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Can anyone point me in the direction of the correct way to use rspec’s  
> configuration class to mixin modules into example groups (and add  
> before/after blocks) according to type.
> 
> [http://rspec.info/rdoc/classes/Spec/Example/Configuration.html](http://rspec.info/rdoc/classes/Spec/Example/Configuration.html)
> 
> I expected the following (very silly and contrived) code to prepend\_before,  
> prepend\_after and include their respective blocks/mixin _only_ for the specs  
> with :type =\> :awe\_inspiring but find that they get applied to all example  
> groups.

:type =\> :whatever is _not_ an arbitrary tagging system. It supports  
creating your own custom types of ExampleGroups. If it can’t find one  
registered with the key, it gives you the default.

> ```
> puts 'before awe_inspiring test'
> 
> ```
> 
> end
> 
> describe ‘with enthusiasm’, :type =\> :awe\_inspiring do  
> it “should do something with enthusiasm” do  
> puts ‘have wow’ if self.respond\_to?(:wow)  
> end  
> end

You should be able to do something like this:

class AweInspiring \< Spec::Example::ExampleGroup  
def wow;end  
Spec::Example::ExampleGroupFactory.register(:awe\_inspiring, self)  
end

Now you could use describe ‘with enthusiasm’, :type =\> :awe\_inspiring  
do and not have to worry about setting up the config to mix modules  
in.

HTH,  
David
