Class: RSpec::Core::SharedExampleGroup::Registry

### Home Classes Methods

### In Files

- lib/rspec/core/shared_example_group.rb

### Parent

Object

### Methods

- ::created_from_caller
- ::included
- #add_const
- #add_group
- #clear
- #shared_example_groups
- #shared_example_groups_for

### Class/Module Index

Quicksearch

- RSpec
- RSpec::Core
- RSpec::Core::BacktraceCleaner
- RSpec::Core::BacktraceFormatter
- RSpec::Core::CommandLine
- RSpec::Core::Configuration
- RSpec::Core::Configuration::MustBeConfiguredBeforeExampleGroupsError
- RSpec::Core::ConfigurationOptions
- RSpec::Core::ConstMissing
- RSpec::Core::DRbCommandLine
- RSpec::Core::DSL
- RSpec::Core::Deprecation
- RSpec::Core::DrbOptions
- RSpec::Core::Example
- RSpec::Core::Example::NotPendingExampleFixed
- RSpec::Core::Example::Procsy
- RSpec::Core::ExampleGroup
- RSpec::Core::Extensions
- RSpec::Core::Extensions::InstanceEvalWithArgs
- RSpec::Core::Extensions::ModuleEvalWithArgs
- RSpec::Core::Extensions::Ordered
- RSpec::Core::Extensions::Ordered::ExampleGroups
- RSpec::Core::Extensions::Ordered::Examples
- RSpec::Core::FilterManager
- RSpec::Core::FilterManager::BackwardCompatibility
- RSpec::Core::FilterManager::Describable
- RSpec::Core::Formatters
- RSpec::Core::Formatters::BaseFormatter
- RSpec::Core::Formatters::BaseTextFormatter
- RSpec::Core::Formatters::DeprecationFormatter
- RSpec::Core::Formatters::DocumentationFormatter
- RSpec::Core::Formatters::Helpers
- RSpec::Core::Formatters::HtmlFormatter
- RSpec::Core::Formatters::HtmlPrinter
- RSpec::Core::Formatters::JsonFormatter
- RSpec::Core::Formatters::ProgressFormatter
- RSpec::Core::Formatters::SnippetExtractor
- RSpec::Core::Formatters::SnippetExtractor::NullConverter
- RSpec::Core::Formatters::TextMateFormatter
- RSpec::Core::Hooks
- RSpec::Core::Hooks::AfterAllHook
- RSpec::Core::Hooks::AfterHook
- RSpec::Core::Hooks::AroundHook
- RSpec::Core::Hooks::AroundHookCollection
- RSpec::Core::Hooks::BeforeHook
- RSpec::Core::Hooks::GroupHookCollection
- RSpec::Core::Hooks::Hook
- RSpec::Core::Hooks::HookCollection
- RSpec::Core::Hooks::HookCollectionAliases
- RSpec::Core::Hooks::RegistersGlobals
- RSpec::Core::MemoizedHelpers
- RSpec::Core::MemoizedHelpers::BeforeAllMemoizedHash
- RSpec::Core::MemoizedHelpers::ClassMethods
- RSpec::Core::Metadata
- RSpec::Core::Metadata::ExampleMetadataHash
- RSpec::Core::Metadata::GroupMetadataHash
- RSpec::Core::Metadata::MetadataHash
- RSpec::Core::MetadataHashBuilder
- RSpec::Core::MetadataHashBuilder::Common
- RSpec::Core::MetadataHashBuilder::WithConfigWarning
- RSpec::Core::MetadataHashBuilder::WithDeprecationWarning
- RSpec::Core::MockFrameworkAdapter
- RSpec::Core::Parser
- RSpec::Core::Pending
- RSpec::Core::Pending::PendingDeclaredInExample
- RSpec::Core::Pending::PendingExampleFixedError
- RSpec::Core::ProjectInitializer
- RSpec::Core::RakeTask
- RSpec::Core::Reporter
- RSpec::Core::RubyProject
- RSpec::Core::Runner
- RSpec::Core::SharedContext
- RSpec::Core::SharedExampleGroup
- RSpec::Core::SharedExampleGroup::Collection
- RSpec::Core::SharedExampleGroup::Registry
- RSpec::Core::SharedExampleGroup::TopLevelDSL
- RSpec::Core::Time
- RSpec::Core::Version
- RSpec::Core::World
- RSpec::Rake
- RSpec::Runner
- Autotest
- Autotest::Rspec2
- Kernel

No matching classes.

# RSpec::Core::SharedExampleGroup::Registry

@private

Used internally to manage the shared example groups and constants. We want to limit the number of methods we add to objects we don't own (main and Module) so this allows us to have helper methods that don't get added to those objects.

### Public Class Methods

created_from_caller(other_caller) click to toggle source

    # File lib/rspec/core/shared_example_group.rb, line 110
    def self.created_from_caller(other_caller)
      @caller_line == other_caller.last
    end

included(kls) click to toggle source

    # File lib/rspec/core/shared_example_group.rb, line 114
    def self.included(kls)
      kls.describe(&@shared_block)
      kls.children.first.metadata[:shared_group_name] = name
    end

### Public Instance Methods

add_const(source, name, &block) click to toggle source

    # File lib/rspec/core/shared_example_group.rb, line 100
    def add_const(source, name, &block)
      if Object.const_defined?(name)
        mod = Object.const_get(name)
        raise_name_error unless mod.created_from_caller(caller)
      end

      mod = Module.new do
        @shared_block = block
        @caller_line = caller.last

        def self.created_from_caller(other_caller)
          @caller_line == other_caller.last
        end

        def self.included(kls)
          kls.describe(&@shared_block)
          kls.children.first.metadata[:shared_group_name] = name
        end
      end

      shared_const = Object.const_set(name, mod)
      add_shared_example_group source, shared_const, block
    end

add_group(source, *args, &block) click to toggle source

    # File lib/rspec/core/shared_example_group.rb, line 82
    def add_group(source, *args, &block)
      ensure_block_has_source_location(block, caller[1])

      if key? args.first
        key = args.shift
        warn_if_key_taken source, key, block
        add_shared_example_group source, key, block
      end

      unless args.empty?
        mod = Module.new
        (class << mod; self; end).send :define_method, :extended  do |host|
          host.class_eval(&block)
        end
        RSpec.configuration.extend mod, *args
      end
    end

clear() click to toggle source

    # File lib/rspec/core/shared_example_group.rb, line 132
    def clear
      shared_example_groups.clear
    end

shared_example_groups() click to toggle source

    # File lib/rspec/core/shared_example_group.rb, line 128
    def shared_example_groups
      @shared_example_groups ||= Hash.new { |hash,key| hash[key] = Hash.new }
    end

shared_example_groups_for(*sources) click to toggle source

    # File lib/rspec/core/shared_example_group.rb, line 124
    def shared_example_groups_for(*sources)
      Collection.new(sources, shared_example_groups)
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.