Class | Spec::DSL::BehaviourFactory |
In: |
lib/spec/dsl/behaviour_factory.rb
|
Parent: | Object |
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 spec/farm to create behaviour instances of type Spec::Farm::DSL::FarmBehaviour.
# File lib/spec/dsl/behaviour_factory.rb, line 17 17: def add_behaviour_class(behaviour_type, klass) 18: BEHAVIOUR_CLASSES[behaviour_type] = klass 19: end
# File lib/spec/dsl/behaviour_factory.rb, line 25 25: def create(*args, &block) 26: opts = Hash === args.last ? args.last : {} 27: if opts[:shared] 28: behaviour_type = :default 29: elsif opts[:behaviour_type] 30: behaviour_type = opts[:behaviour_type] 31: elsif opts[:spec_path] =~ /spec\/(#{BEHAVIOUR_CLASSES.keys.join('|')})/ 32: behaviour_type = $1.to_sym 33: else 34: behaviour_type = :default 35: end 36: return BEHAVIOUR_CLASSES[behaviour_type].new(*args, &block) 37: end