Sha256: fe2c56c993612a249b57bf3f5fb532a17db9e75318de1f58ea13b31e6bd215f3
Contents?: true
Size: 1.29 KB
Versions: 3
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 = $2.to_sym else behaviour_type = :default end return BEHAVIOUR_CLASSES[behaviour_type].new(*args, &block) end end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
rspec-1.0.6 | lib/spec/dsl/behaviour_factory.rb |
rspec-1.0.7 | lib/spec/dsl/behaviour_factory.rb |
rspec-1.0.8 | lib/spec/dsl/behaviour_factory.rb |