Sha256: c5bdc559441aace61476146cb8197069bb37a70c93b61c198dec0d9e05b816d1
Contents?: true
Size: 1.29 KB
Versions: 9
Compression:
Stored size: 1.29 KB
Contents
module Spec module DSL class BehaviourFactory class << self BEHAVIOUR_CLASSES = {:default => Spec::DSL::Behaviour} # Registers a behaviour class +klass+ with the symbol # +behaviour_type+. For example: # # Spec::DSL::BehaviourFactory.add_behaviour_class(:farm, Spec::Farm::DSL::FarmBehaviour) # # This will cause Kernel#describe from a file living in # <tt>spec/farm</tt> to create behaviour instances of type # Spec::Farm::DSL::FarmBehaviour. def add_behaviour_class(behaviour_type, klass) BEHAVIOUR_CLASSES[behaviour_type] = klass end def remove_behaviour_class(behaviour_type) BEHAVIOUR_CLASSES.delete(behaviour_type) end def create(*args, &block) opts = Hash === args.last ? args.last : {} if opts[:shared] behaviour_type = :default elsif opts[:behaviour_type] behaviour_type = opts[:behaviour_type] elsif opts[:spec_path] =~ /spec\/(#{BEHAVIOUR_CLASSES.keys.join('|')})/ behaviour_type = $1.to_sym else behaviour_type = :default end return BEHAVIOUR_CLASSES[behaviour_type].new(*args, &block) end end end end end
Version data entries
9 entries across 9 versions & 2 rubygems