Sha256: 518c7ebae9309e7fc8eabef6d302bcc03706cfb6589a0b80d13c516cc62acf73

Contents?: true

Size: 1.74 KB

Versions: 21

Compression:

Stored size: 1.74 KB

Contents

module Spec
  module Example
    class ExampleGroupFactory
      class << self
        def reset
          @example_group_types = nil
          default(ExampleGroup)
        end

        # 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 
        # <tt>spec/farm</tt> to create example group instances of type
        # Spec::Farm::Example::FarmExampleGroup.
        def register(id, example_group_class)
          @example_group_types[id] = example_group_class
        end
        
        # Sets the default ExampleGroup class
        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

        def get(id=nil)
          if @example_group_types.values.include?(id)
            id
          else
            @example_group_types[id]
          end
        end
        
        def create_example_group(*args, &block)
          opts = Hash === args.last ? args.last : {}
          if opts[:shared]
            SharedExampleGroup.new(*args, &block)
          else
            superclass = determine_superclass(opts)
            superclass.describe(*args, &block)
          end
        end

        protected

        def determine_superclass(opts)
          id = if opts[:type]
            opts[:type]
          elsif opts[:spec_path] =~ /spec(\\|\/)(#{@example_group_types.keys.join('|')})/
            $2 == '' ? nil : $2.to_sym
          end
          get(id)
        end

      end
      self.reset
    end
  end
end

Version data entries

21 entries across 21 versions & 4 rubygems

Version Path
picolena-0.0.99 app_generators/picolena/templates/vendor/plugins/rspec/lib/spec/example/example_group_factory.rb
picolena-0.1.0 rails_plugins/rspec/lib/spec/example/example_group_factory.rb
picolena-0.1.1 rails_plugins/rspec/lib/spec/example/example_group_factory.rb
picolena-0.1.2 rails_plugins/rspec/lib/spec/example/example_group_factory.rb
picolena-0.1.3 rails_plugins/rspec/lib/spec/example/example_group_factory.rb
picolena-0.1.4 rails_plugins/rspec/lib/spec/example/example_group_factory.rb
picolena-0.1.5 rails_plugins/rspec/lib/spec/example/example_group_factory.rb
rspec-1.1.0 lib/spec/example/example_group_factory.rb
rspec-1.1.1 lib/spec/example/example_group_factory.rb
rspec-1.1.3 lib/spec/example/example_group_factory.rb
rspec-1.1.2 lib/spec/example/example_group_factory.rb
spree-0.2.0 vendor/plugins/rspec/lib/spec/example/example_group_factory.rb
typo-5.0.1 vendor/plugins/rspec/lib/spec/example/example_group_factory.rb
typo-5.0.2 vendor/plugins/rspec/lib/spec/example/example_group_factory.rb
typo-5.0.3.98.1 vendor/plugins/rspec/lib/spec/example/example_group_factory.rb
typo-5.0.3.98 vendor/plugins/rspec/lib/spec/example/example_group_factory.rb
typo-5.0 vendor/plugins/rspec/lib/spec/example/example_group_factory.rb
typo-5.1.2 vendor/plugins/rspec/lib/spec/example/example_group_factory.rb
typo-5.1.1 vendor/plugins/rspec/lib/spec/example/example_group_factory.rb
typo-5.1.3 vendor/plugins/rspec/lib/spec/example/example_group_factory.rb