[rspec-users] ExampleGroup and SharedExampleGroup relationship(?)

Pat Maddox pergesu at gmail.com
Thu Dec 27 12:21:05 EST 2007


On Dec 27, 2007 8:30 AM, Corey Haines <coreyhaines at gmail.com> wrote:
> I expected to see SharedExampleGroup < ExampleGroup, but, instead, I saw
> SharedExampleGroup < Module. This is incredibly confusing to me. I realize
> that they don't even need to have any relationship to each other since they
> get their shared functionality through the module ExampleGroupMethods, but
> it still seems a bit odd to me that they don't have a hierarchical
> relationship.

Whenever you write an example, RSpec defines a method.  Shared example
groups are basically sugary modules.  They define examples - methods -
that get included into your "real" example groups.

I can't say for sure if there's any deeper meaning to it other than
it's the simplest implementation.  It would be possible to make
SharedExampleGroup be a class, but then when an ExampleGroup uses
it_should_behave_like, it would have to list all the examples in the
SharedExampleGroup, define methods on itself that delegate to the
SEG...as opposed to just mixing in a module :)

I admit I'm pulling all of this out of my ass, btw, but I think it's
right.  I'm sure David will clarify soon.

Pat


More information about the rspec-users mailing list