Class: Spec::DSL::BehaviourFactory
- Defined in:
- lib/spec/dsl/behaviour_factory.rb
Constant Summary collapse
Class Method Summary collapse
-
.add_behaviour_class(behaviour_type, klass) ⇒ Object
Registers a behaviour class
klass
with the symbolbehaviour_type
. - .create(*args, &block) ⇒ Object
- .remove_behaviour_class(behaviour_type) ⇒ Object
Class Method Details
.add_behaviour_class(behaviour_type, klass) ⇒ Object
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.
17 18 19 |
# File 'lib/spec/dsl/behaviour_factory.rb', line 17 def add_behaviour_class(behaviour_type, klass) BEHAVIOUR_CLASSES[behaviour_type] = klass end |
.create(*args, &block) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/spec/dsl/behaviour_factory.rb', line 25 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 |
.remove_behaviour_class(behaviour_type) ⇒ Object
21 22 23 |
# File 'lib/spec/dsl/behaviour_factory.rb', line 21 def remove_behaviour_class(behaviour_type) BEHAVIOUR_CLASSES.delete(behaviour_type) end |