| 1 |
module Spec |
| 2 |
module Example |
| 3 |
class ExampleGroupFactory |
| 4 |
class << self |
| 5 |
def reset |
| 6 |
@example_group_types = nil |
| 7 |
default(ExampleGroup) |
| 8 |
end |
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
def register(key, example_group_class) |
| 25 |
@example_group_types[key] = example_group_class |
| 26 |
end |
| 27 |
|
| 28 |
|
| 29 |
def default(example_group_class) |
| 30 |
old = @example_group_types |
| 31 |
@example_group_types = Hash.new(example_group_class) |
| 32 |
@example_group_types.merge!(old) if old |
| 33 |
end |
| 34 |
|
| 35 |
def get(key=nil) |
| 36 |
if @example_group_types.values.include?(key) |
| 37 |
key |
| 38 |
else |
| 39 |
@example_group_types[key] |
| 40 |
end |
| 41 |
end |
| 42 |
|
| 43 |
def create_example_group(*args, &block) |
| 44 |
opts = Hash === args.last ? args.last : {} |
| 45 |
superclass = determine_superclass(opts) |
| 46 |
superclass.describe(*args, &block) |
| 47 |
end |
| 48 |
|
| 49 |
protected |
| 50 |
|
| 51 |
def determine_superclass(opts) |
| 52 |
key = if opts[:type] |
| 53 |
opts[:type] |
| 54 |
elsif opts[:spec_path] =~ /spec(\\|\/)(#{@example_group_types.keys.join('|')})/ |
| 55 |
$2 == '' ? nil : $2.to_sym |
| 56 |
end |
| 57 |
get(key) |
| 58 |
end |
| 59 |
|
| 60 |
end |
| 61 |
self.reset |
| 62 |
end |
| 63 |
end |
| 64 |
end |