Module: Spec::Example::ExampleGroupFactory::ClassMethods
- Included in:
- Spec::Example::ExampleGroupFactory
- Defined in:
- lib/spec/example/example_group_factory.rb
Instance Method Summary collapse
- #[](key) ⇒ Object
- #assign_scope(scope, args) ⇒ Object
- #create_example_group(*args, &block) ⇒ Object
-
#create_shared_example_group(*args, &example_group_block) ⇒ Object
:nodoc:.
-
#default(example_group_class) ⇒ Object
Sets the default ExampleGroup class.
- #example_group_creation_listeners ⇒ Object
-
#register(key, example_group_class) ⇒ Object
Registers an example group class
klass
with the symboltype
. - #register_example_group(klass) ⇒ Object
- #reset ⇒ Object
Instance Method Details
#[](key) ⇒ Object
61 62 63 |
# File 'lib/spec/example/example_group_factory.rb', line 61 def [](key) @example_group_types[key] end |
#assign_scope(scope, args) ⇒ Object
65 66 67 |
# File 'lib/spec/example/example_group_factory.rb', line 65 def assign_scope(scope, args) args.last[:scope] = scope end |
#create_example_group(*args, &block) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/spec/example/example_group_factory.rb', line 26 def create_example_group(*args, &block) raise ArgumentError if args.empty? raise ArgumentError unless block Spec::Example::add_spec_path_to(args) superclass = determine_superclass(args.last) superclass.describe(*args, &block) end |
#create_shared_example_group(*args, &example_group_block) ⇒ Object
:nodoc:
21 22 23 24 |
# File 'lib/spec/example/example_group_factory.rb', line 21 def create_shared_example_group(*args, &example_group_block) # :nodoc: ::Spec::Example::add_spec_path_to(args) ::Spec::Example::SharedExampleGroup.register(*args, &example_group_block) end |
#default(example_group_class) ⇒ Object
Sets the default ExampleGroup class
53 54 55 56 57 58 59 |
# File 'lib/spec/example/example_group_factory.rb', line 53 def default(example_group_class) Spec.__send__ :remove_const, :ExampleGroup if Spec.const_defined?(:ExampleGroup) Spec.const_set(:ExampleGroup, example_group_class) old = @example_group_types @example_group_types = Hash.new(example_group_class) @example_group_types.merge!(old) if old end |
#example_group_creation_listeners ⇒ Object
11 12 13 |
# File 'lib/spec/example/example_group_factory.rb', line 11 def example_group_creation_listeners @example_group_creation_listeners ||= [] end |
#register(key, example_group_class) ⇒ Object
Registers an example group class klass
with the symbol type
. For example:
Spec::Example::ExampleGroupFactory.register(:farm, FarmExampleGroup)
With that you can append a hash with :type => :farm to the describe method and it will load an instance of FarmExampleGroup.
describe Pig, :type => :farm do
...
If you don’t use the hash explicitly, describe
will implicitly use an instance of FarmExampleGroup for any file loaded from the ./spec/farm
directory.
48 49 50 |
# File 'lib/spec/example/example_group_factory.rb', line 48 def register(key, example_group_class) @example_group_types[key.to_sym] = example_group_class end |
#register_example_group(klass) ⇒ Object
15 16 17 18 19 |
# File 'lib/spec/example/example_group_factory.rb', line 15 def register_example_group(klass) example_group_creation_listeners.each do |listener| listener.register_example_group(klass) end end |
#reset ⇒ Object
6 7 8 9 |
# File 'lib/spec/example/example_group_factory.rb', line 6 def reset @example_group_types = nil default(ExampleGroup) end |