Class Spec::DSL::BehaviourFactory
In: lib/spec/dsl/behaviour_factory.rb
Parent: Object

Methods

Constants

BEHAVIOUR_CLASSES = {:default => Spec::DSL::Behaviour}

Public Class methods

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.

[Source]

    # 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

[Source]

    # 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

[Source]

    # File lib/spec/dsl/behaviour_factory.rb, line 21
21:         def remove_behaviour_class(behaviour_type)
22:           BEHAVIOUR_CLASSES.delete(behaviour_type)
23:         end

[Validate]