[rspec-users] Aspects in RSpec 1.0.5

Ashley Moran work at ashleymoran.me.uk
Wed Jun 27 10:38:51 EDT 2007


Forgot post this when I did it...

For anyone else that used the "aspect" method of the rspec-ext gem,  
here's a New World version of the code to drop into spec_helper.rb.   
(I'm assuming rspec-ext hasn't been updated since I did this a week  
or two ago)

   module Spec
     module DSL

       module BehaviourEval
         module ModuleMethods
           def aspect(name,&block)
             Behaviour.aspect << name.to_s
             yield
             Behaviour.aspect.pop
           end
         end
       end

       class Behaviour
         @@aspect = []
         def self.aspect
           @@aspect
         end
         def self.aspect=(new_aspect)
           @@aspect = new_aspect
         end
         alias :original_initialize :initialize
         def initialize(*args,&context_block)
           result = original_initialize(*args, &context_block)
           @name = "(#{self.class.aspect.join("/")}) #{@name}" unless  
self.class.aspect.empty?
           result
         end
       end

     end
   end

Ashley



More information about the rspec-users mailing list