[rspec-devel] New Stub API Implemented

David Chelimsky dchelimsky at gmail.com
Sat Sep 30 08:51:17 EDT 2006


On 9/29/06, Brian Takita <brian.takita at gmail.com> wrote:
> What about having listeners on setup and teardown?
> For example, a plugin of any nature can register on the setup and teardown
> events for each spec.

That's a great idea in terms of the events themselves. Frees up each
framework to plug in on its own terms. In fact, that's a great way for
any other sort of plugin to work.

The only other requirement would be that the plugin would have to make
its methods available within the Specification. I guess they could
just do Spec::Runner::Specification.include.

I'm thinking we should tweak our own framework to plug in in this way.
That will teach us a lot about how well it works before we publish a
plugin mechanism. I'll take a crack at that over the next few days.

Cheers,
David

> On 9/29/06, David Chelimsky <dchelimsky at gmail.com> wrote:
> >
> > On 9/29/06, James Mead <jamesmead44 at gmail.com> wrote:
> > > I've now had requests from several people for a way of using Mocha (&
> > > Stubba) without a dependency on Test::Unit so it can interoperate with
> other
> > > testing frameworks. Given that this is the reason the current versions
> of
> > > Mocha and RSpec don't play together, I thought you might be interested
> to
> > > know I'm in the middle of making the necessary (relatively minor)
> changes to
> > > make this possible.
> >
> > James,
> >
> > That's awesome news. Thanks.
> >
> > Our plan here is to continue to have an integrated stubbing/mocking
> > framework that is invoked by default, but allow other frameworks to be
> > plugged in. To make that work most effectively, rspec needs some hook
> > into Mocha/Stubba (and vice versa) so that the verification of mocks
> > and resetting of stubs is seamless. Here's my current thinking:
> >
> > rspec would support a runtime configuration bit that allows users to
> > choose a mock framework. Something like this:
> >
> > Spec::Mock.plugin = 'mocha'
> >
> > In each specification, RSpec includes a module named
> > Spec::Mock::Plugin (or something like that) provided by mocha. This
> > would provide spec writers access to mocha's API.
> >
> > The plugin would have to support two methods for rspec: one to assign
> > a mock registry and one to verify a mock. Something like this:
> >
> > module Spec
> >   module Mock
> >     module Plugin
> >       attr_writer :mock_registry
> >       def verify mock
> >         #do whatever mocha does to verify the mock
> >         #raise an exception if verification fails
> >       end
> >       include XXX #module w/ mock creation methods, etc
> >     end
> >   end
> > end
> >
> > It would then be mocha's job to call "mock_registry.register mock" as
> > each mock is created and rspec's job to call verify(mock) at the end
> > of each specification.
> >
> > Is this too complex? The thing I like about it is that rspec can make
> > a few changes and any framework can offer itself up as a plugin w/
> > little effort.
> >
> > Thoughts?
> >
> > David


More information about the rspec-devel mailing list