[rspec-devel] Feedback on article

Brian Takita brian.takita at gmail.com
Fri Jan 5 03:03:40 EST 2007


On 1/4/07, Brian Takita <brian.takita 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:
> > > 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?
>
>
> That looks good. It also exposes a missing feature in the Callbacks
> module.
>
> class Spec::Runner::Context
>  class_callback_events :extend
>
>  def initialize(name, &context_block)
>    @name = name
>
>    @context_eval_module = Module.new
>    @context_eval_module.extend ContextEval::ModuleMethods
>    @context_eval_module.include ContextEval::InstanceMethods
>    notify_class_callbacks :extend, @context_eval_module
>    @context_eval_module.class_eval(&context_block)
>  end
> end
>

Is extend a better term than before_context_eval? Is there a better term to
use?

> /Nick
> > >
> > >
> > > _______________________________________________
> > > rspec-devel mailing list
> > > rspec-devel at rubyforge.org
> > > http://rubyforge.org/mailman/listinfo/rspec-devel
> > >
> > >
> > _______________________________________________
> > rspec-devel mailing list
> > rspec-devel at rubyforge.org
> > http://rubyforge.org/mailman/listinfo/rspec-devel
> >
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/rspec-devel/attachments/20070105/9d0d8c56/attachment-0001.html 


More information about the rspec-devel mailing list