Class: Spec::Example::ExampleGroupFactory

Class | Spec::Example::ExampleGroupFactory
In: | lib/spec/example/example_group_factory.rb
Parent: | Object

### Methods

create_example_group default determine_superclass get register reset

### Public Class methods

create_example_group(*args, &block)

[Source]

        # File lib/spec/example/example_group_factory.rb, line 37
    37:         def create_example_group(*args, &block)
    38:           opts = Hash === args.last ? args.last : {}
    39:           if opts[:shared]
    40:             SharedExampleGroup.new(*args, &block)
    41:           else
    42:             superclass = determine_superclass(opts)
    43:             superclass.describe(*args, &block)
    44:           end
    45:         end

default(example_group_class)

Sets the default ExampleGroup class

[Source]

        # File lib/spec/example/example_group_factory.rb, line 23
    23:         def default(example_group_class)
    24:           old = @example_group_types
    25:           @example_group_types = Hash.new(example_group_class)
    26:           @example_group_types.merge(old) if old
    27:         end

get(id=nil)

[Source]

        # File lib/spec/example/example_group_factory.rb, line 29
    29:         def get(id=nil)
    30:           if @example_group_types.values.include?(id)
    31:             id
    32:           else
    33:             @example_group_types[id]
    34:           end
    35:         end

register(id, example_group_class)

Registers an example group class `klass` with the symbol `type`. For example:

      Spec::Example::ExampleGroupFactory.register(:farm, Spec::Farm::Example::FarmExampleGroup)

This will cause Main#describe from a file living in `spec/farm` to create example group instances of type Spec::Farm::Example::FarmExampleGroup.

[Source]

        # File lib/spec/example/example_group_factory.rb, line 18
    18:         def register(id, example_group_class)
    19:           @example_group_types[id] = example_group_class
    20:         end

reset()

[Source]

       # File lib/spec/example/example_group_factory.rb, line 5
    5:         def reset
    6:           @example_group_types = nil
    7:           default(ExampleGroup)
    8:         end

### Protected Class methods

determine_superclass(opts)

[Source]

        # File lib/spec/example/example_group_factory.rb, line 49
    49:         def determine_superclass(opts)
    50:           id = if opts[:type]
    51:             opts[:type]
    52:           elsif opts[:spec_path] =~ /spec(\\|\/)(#{@example_group_types.keys.join('|')})/
    53:             $2 == '' ? nil : $2.to_sym
    54:           end
    55:           get(id)
    56:         end

[Validate]