[rspec-users] Custom Example Groups

Matt Wynne matt at mattwynne.net
Sun Apr 19 10:11:25 EDT 2009

On 19 Apr 2009, at 13:58, David Chelimsky wrote:

> Also - you really don't need custom groups for this sort of thing,
> because you can define with_method in a module and extend the
> configuration w/ that module:
>  module WithMethod
>    def with_method(verb)
>      subject { send(verb, description_args.first) }
>      yield
>    end
>  end
>  Spec::Runner.configure {|c| c.extend(WithMethod)}
> Cheers,
> David

Or even (if I'm following this correctly) just define it right there  
inside your describe block:

describe "custom example group" do

   # available in groups
   def self.custom_example_group_method
     puts "hello from a custom example group class"

   # available in examples
   def custom_example_method
     puts "hello from a custom example group instance"


   it "provides access to instance methods" do

Obviously this doesn't give you any re-use yet, but it's usually the  
very first step I take before factoring out a module like David's  
suggested. I've yet to need to take it as far as the custom example  
group class, but I like the concept.

Matt Wynne

More information about the rspec-users mailing list