[rspec-users] shared examples sharing methods

Stephen Eley sfeley at gmail.com
Wed Jun 17 17:36:54 EDT 2009

On Wed, Jun 17, 2009 at 11:14 AM, Andrew Premdas<apremdas at gmail.com> wrote:
> What I'd like to do is create a shared_examples group which I can parametize
> a method. So my shared example would perhaps use method named_address=, or
> set_named_address and then groups that behave like "Named address" would be
> able to override this method so it sets the correct address e.g. the last
> billing address

This is horrendously ugly, but I was able to achieve something like
what you're talking about using a combination of instance variables
and 'eval' statements in the shared behavior.  See:


Readable and elegant?  Not really.  But I have to set up a crapload of
these classes layered on top of somebody else's SOAP API, and spec
completeness was more important to me than spec maintainability.

(Also, it didn't occur to me to try macros.)  >8->

Have Fun,
   Steve Eley (sfeley at gmail.com)
   ESCAPE POD - The Science Fiction Podcast Magazine

More information about the rspec-users mailing list