Module: Spec::Example::ExampleGroupFactory::ClassMethods
- Included in:
- Spec::Example::ExampleGroupFactory
- Defined in:
- lib/gems/rspec-1.1.12/lib/spec/example/example_group_factory.rb
Instance Method Summary collapse
- #assign_scope(scope, args) ⇒ Object
- #create_example_group(*args, &block) ⇒ Object
- #create_shared_example_group(*args, &block) ⇒ Object
-
#default(example_group_class) ⇒ Object
Sets the default ExampleGroup class.
- #get(key = nil) ⇒ Object
- #include_constants_in(context, &block) ⇒ Object
-
#register(key, example_group_class) ⇒ Object
Registers an example group class
klass
with the symboltype
. -
#registered_or_ancestor_of_registered?(example_group_classes) ⇒ Boolean
:nodoc:.
- #reset ⇒ Object
Instance Method Details
#assign_scope(scope, args) ⇒ Object
72 73 74 |
# File 'lib/gems/rspec-1.1.12/lib/spec/example/example_group_factory.rb', line 72 def assign_scope(scope, args) args.last[:scope] = scope end |
#create_example_group(*args, &block) ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/gems/rspec-1.1.12/lib/spec/example/example_group_factory.rb', line 52 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, &block) ⇒ Object
60 61 62 63 |
# File 'lib/gems/rspec-1.1.12/lib/spec/example/example_group_factory.rb', line 60 def create_shared_example_group(*args, &block) Spec::Example::add_spec_path_to(args) SharedExampleGroup.register(*args, &block) end |
#default(example_group_class) ⇒ Object
Sets the default ExampleGroup class
38 39 40 41 42 |
# File 'lib/gems/rspec-1.1.12/lib/spec/example/example_group_factory.rb', line 38 def default(example_group_class) old = @example_group_types @example_group_types = Hash.new(example_group_class) @example_group_types.merge!(old) if old end |
#get(key = nil) ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/gems/rspec-1.1.12/lib/spec/example/example_group_factory.rb', line 44 def get(key=nil) if @example_group_types.values.include?(key) key else @example_group_types[key] end end |
#include_constants_in(context, &block) ⇒ Object
65 66 67 68 69 70 |
# File 'lib/gems/rspec-1.1.12/lib/spec/example/example_group_factory.rb', line 65 def include_constants_in(context, &block) if (Spec::Ruby.version.to_f >= 1.9 && Module === context && !(Class === context)) return lambda {include context;instance_eval(&block)} end block 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.
33 34 35 |
# File 'lib/gems/rspec-1.1.12/lib/spec/example/example_group_factory.rb', line 33 def register(key, example_group_class) @example_group_types[key] = example_group_class end |
#registered_or_ancestor_of_registered?(example_group_classes) ⇒ Boolean
:nodoc:
10 11 12 13 14 15 16 17 |
# File 'lib/gems/rspec-1.1.12/lib/spec/example/example_group_factory.rb', line 10 def registered_or_ancestor_of_registered?(example_group_classes) # :nodoc: example_group_classes.each do |example_group_class| return false unless registered_types.any? do |registered_type| registered_type.ancestors.include? example_group_class end end return true end |
#reset ⇒ Object
5 6 7 8 |
# File 'lib/gems/rspec-1.1.12/lib/spec/example/example_group_factory.rb', line 5 def reset @example_group_types = nil default(ExampleGroup) end |