[rspec-devel] Feedback on article

aslak hellesoy aslak.hellesoy at gmail.com
Tue Jan 2 12:15:49 EST 2007


On 1/2/07, Nick Sieger <nicksieger at gmail.com> wrote:
> On 1/2/07, aslak hellesoy <aslak.hellesoy at gmail.com> wrote:
> > On 1/2/07, Nick Sieger <nicksieger at gmail.com> wrote:
> > > Hi, I wrote an article [1] outlining some tricks I've developed adding
> > > custom extensions into RSpec.  But they all hinge upon
> > > Spec::Runner::Context#before_context_eval and the
> > > @context_eval_module ivar.  So I was wondering whether this mechanism
> can be
> > > relied on in the future, or whether this is even the best way to wire in
> > > such extensions.  If you have a recommended way I'd love to hear about
> it so
> > > I can incorporate it into my article and make sure I don't highlight the
> > > wrong way of doing things.
> > >
> >
> > Regarding the stability of the API - I'm a little worried about having
> > extensions use private variables.
>
> Agreed.  I was still motivated to post, but I suspected you would think that
> about the monkeypatching and the direct use of the ivar.  I think I'll put a
> small disclaimer at the top of the post, and keep it up to date to follow
> whatever you guys think would be appropriate for an extension point API.
>

That sounds good. We're likely to debate what this API looks like for
a while, because we only get one shot at it ;-) Here is my initial
suggestion/example:

Spec::Runner::Context.extend do |context_eval_module|
  context_eval_module.include StackMethods
end

class Spec::Runner::Context
  def self.extend(&block)
    @@extension_blocks << block
  end

def initialize(name, &context_block)
    @name = name

    @context_eval_module = Module.new
    @context_eval_module.extend ContextEval::ModuleMethods
    @context_eval_module.include ContextEval::InstanceMethods
    @@extension_blocks.each{|b| b.call(@context_eval_module)}
    @context_eval_module.class_eval(&context_block)
  end
end

WDYT?

> /Nick
>
>
> _______________________________________________
> rspec-devel mailing list
> rspec-devel at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-devel
>
>


More information about the rspec-devel mailing list