Module: RSpec::Core::Metadata

### Home Classes Methods

### In Files

- lib/rspec/core/metadata.rb

### Namespace

- CLASS RSpec::Core::Metadata::ExampleGroupHash
- CLASS RSpec::Core::Metadata::ExampleHash
- CLASS RSpec::Core::Metadata::HashPopulator

### Methods

- ::ascend
- ::ascending
- ::backtrace_from
- ::build_hash_from
- ::deep_hash_dup
- ::relative_path
- ::relative_path_regex

### Class/Module Index

Quicksearch

- RSpec
- RSpec::Core
- RSpec::Core::AnonymousExampleGroup
- RSpec::Core::Backports
- RSpec::Core::Backports::Random
- RSpec::Core::Backports::Random::Implementation
- RSpec::Core::Backports::Random::MT19937
- RSpec::Core::BacktraceFormatter
- RSpec::Core::Configuration
- RSpec::Core::Configuration::DeprecationReporterBuffer
- RSpec::Core::Configuration::ExposeCurrentExample
- RSpec::Core::Configuration::MustBeConfiguredBeforeExampleGroupsError
- RSpec::Core::ConfigurationOptions
- RSpec::Core::DRbOptions
- RSpec::Core::DRbRunner
- RSpec::Core::DSL
- RSpec::Core::DSL::RSpec
- RSpec::Core::Example
- RSpec::Core::Example::ExecutionResult
- RSpec::Core::Example::Procsy
- RSpec::Core::ExampleGroup
- RSpec::Core::ExclusionRules
- RSpec::Core::FilterManager
- RSpec::Core::FilterRules
- RSpec::Core::FilterableItemRepository
- RSpec::Core::FilterableItemRepository::QueryOptimized
- RSpec::Core::FilterableItemRepository::UpdateOptimized
- RSpec::Core::FlatMap
- RSpec::Core::Formatters
- RSpec::Core::Formatters::BaseFormatter
- RSpec::Core::Formatters::BaseTextFormatter
- RSpec::Core::Formatters::ConsoleCodes
- RSpec::Core::Formatters::DeprecationFormatter
- RSpec::Core::Formatters::DeprecationFormatter::DelayedPrinter
- RSpec::Core::Formatters::DeprecationFormatter::FileStream
- RSpec::Core::Formatters::DeprecationFormatter::ImmediatePrinter
- RSpec::Core::Formatters::DeprecationFormatter::RaiseErrorStream
- RSpec::Core::Formatters::DocumentationFormatter
- RSpec::Core::Formatters::Helpers
- RSpec::Core::Formatters::HtmlFormatter
- RSpec::Core::Formatters::HtmlPrinter
- RSpec::Core::Formatters::JsonFormatter
- RSpec::Core::Formatters::Loader
- RSpec::Core::Formatters::ProfileFormatter
- RSpec::Core::Formatters::ProgressFormatter
- RSpec::Core::Formatters::Protocol
- RSpec::Core::Formatters::SnippetExtractor
- RSpec::Core::Formatters::SnippetExtractor::CoderayConverter
- RSpec::Core::Formatters::SnippetExtractor::NullConverter
- RSpec::Core::HashImitatable
- RSpec::Core::HashImitatable::ClassMethods
- RSpec::Core::Hooks
- RSpec::Core::Hooks::AfterContextHook
- RSpec::Core::Hooks::AfterHook
- RSpec::Core::Hooks::AroundHook
- RSpec::Core::Hooks::BeforeHook
- RSpec::Core::Hooks::Hook
- RSpec::Core::Hooks::HookCollections
- RSpec::Core::InclusionRules
- RSpec::Core::LegacyExampleGroupHash
- RSpec::Core::MemoizedHelpers
- RSpec::Core::MemoizedHelpers::ClassMethods
- RSpec::Core::MemoizedHelpers::ContextHookMemoizedHash
- RSpec::Core::MemoizedHelpers::ContextHookMemoizedHash::After
- RSpec::Core::MemoizedHelpers::ContextHookMemoizedHash::Before
- RSpec::Core::Metadata
- RSpec::Core::Metadata::ExampleGroupHash
- RSpec::Core::Metadata::ExampleHash
- RSpec::Core::Metadata::HashPopulator
- RSpec::Core::MetadataFilter
- RSpec::Core::MinitestAssertionsAdapter
- RSpec::Core::MockingAdapters
- RSpec::Core::MockingAdapters::Flexmock
- RSpec::Core::MockingAdapters::Mocha
- RSpec::Core::MockingAdapters::Null
- RSpec::Core::MockingAdapters::RR
- RSpec::Core::MockingAdapters::RSpec
- RSpec::Core::Notifications
- RSpec::Core::Notifications::DeprecationNotification
- RSpec::Core::Notifications::ExampleNotification
- RSpec::Core::Notifications::ExamplesNotification
- RSpec::Core::Notifications::FailedExampleNotification
- RSpec::Core::Notifications::NullColorizer
- RSpec::Core::Notifications::NullNotification
- RSpec::Core::Notifications::PendingExampleFailedAsExpectedNotification
- RSpec::Core::Notifications::PendingExampleFixedNotification
- RSpec::Core::Notifications::PendingExampleNotificationMethods
- RSpec::Core::Notifications::ProfileNotification
- RSpec::Core::Notifications::SeedNotification
- RSpec::Core::Notifications::SkippedExampleNotification
- RSpec::Core::Notifications::SummaryNotification
- RSpec::Core::NullReporter
- RSpec::Core::Ordering
- RSpec::Core::Ordering::ConfigurationManager
- RSpec::Core::Ordering::Custom
- RSpec::Core::Ordering::Identity
- RSpec::Core::Ordering::Random
- RSpec::Core::Ordering::Registry
- RSpec::Core::Parser
- RSpec::Core::Pending
- RSpec::Core::Pending::PendingExampleFixedError
- RSpec::Core::Pending::SkipDeclaredInExample
- RSpec::Core::ProjectInitializer
- RSpec::Core::RakeTask
- RSpec::Core::RandomNumberGenerator
- RSpec::Core::Reporter
- RSpec::Core::RubyProject
- RSpec::Core::Runner
- RSpec::Core::Sandbox
- RSpec::Core::SharedContext
- RSpec::Core::SharedExampleGroup
- RSpec::Core::SharedExampleGroup::Registry
- RSpec::Core::SharedExampleGroup::TopLevelDSL
- RSpec::Core::SharedExampleGroupInclusionStackFrame
- RSpec::Core::SharedExampleGroupModule
- RSpec::Core::SuiteHookContext
- RSpec::Core::TestUnitAssertionsAdapter
- RSpec::Core::Time
- RSpec::Core::Version
- RSpec::Core::Warnings
- RSpec::Core::World
- RSpec::ExampleGroups
- Object

No matching classes.

# RSpec::Core::Metadata

Each ExampleGroup class and Example instance owns an instance of Metadata, which is Hash extended to support lazy evaluation of values associated with keys that may or may not be used by any example or group.

In addition to metadata that is used internally, this also stores user-supplied metadata, e.g.

    describe Something, :type => :ui do
      it "does something", :slow => true do
        # ...
      end
    end

`:type => :ui` is stored in the Metadata owned by the example group, and `:slow => true` is stored in the Metadata owned by the example. These can then be used to select which examples are run using the `--tag` option on the command line, or several methods on `Configuration` used to filter a run (e.g. `filter_run_including`, `filter_run_excluding`, etc).

@see Example#metadata @see ExampleGroup.metadata @see FilterManager @see Configuration#filter_run_including @see Configuration#filter_run_excluding

### Constants

RESERVED_KEYS

  @private

### Public Class Methods

ascend(metadata) click to toggle source

@private Returns an enumerator that iteratively walks up the given metadata through all example group ancestors, yielding each metadata hash along the way.

    # File lib/rspec/core/metadata.rb, line 69
    def self.ascend(metadata)
      enum_for(:ascending, metadata)
    end

ascending(metadata) click to toggle source

@private Iteratively walks up from the given metadata through all example group ancestors, yielding each metadata hash along the way.

    # File lib/rspec/core/metadata.rb, line 56
    def self.ascending(metadata)
      yield metadata
      return unless (group_metadata = metadata.fetch(:example_group) { metadata[:parent_example_group] })

      loop do
        yield group_metadata
        break unless (group_metadata = group_metadata[:parent_example_group])
      end
    end

backtrace_from(block) click to toggle source

@private

    # File lib/rspec/core/metadata.rb, line 103
    def self.backtrace_from(block)
      return caller unless block.respond_to?(:source_location)
      [block.source_location.join(':')]
    end

build_hash_from(args, warn_about_example_group_filtering=false) click to toggle source

@private Used internally to build a hash from an args array. Symbols are converted into hash keys with a value of `true`. This is done to support simple tagging using a symbol, rather than needing to do `:symbol => true`.

    # File lib/rspec/core/metadata.rb, line 78
    def self.build_hash_from(args, warn_about_example_group_filtering=false)
      hash = args.last.is_a?(Hash) ? args.pop : {}

      hash[args.pop] = true while args.last.is_a?(Symbol)

      if warn_about_example_group_filtering && hash.key?(:example_group)
        RSpec.deprecate("Filtering by an `:example_group` subhash",
                        :replacement => "the subhash to filter directly")
      end

      hash
    end

deep_hash_dup(object) click to toggle source

@private

    # File lib/rspec/core/metadata.rb, line 92
    def self.deep_hash_dup(object)
      return object.dup if Array === object
      return object unless Hash  === object

      object.inject(object.dup) do |duplicate, (key, value)|
        duplicate[key] = deep_hash_dup(value)
        duplicate
      end
    end

relative_path(line) click to toggle source

@api private

@param line [String] current code line @return [String] relative path to line

    # File lib/rspec/core/metadata.rb, line 44
    def self.relative_path(line)
      line = line.sub(relative_path_regex, "\\1.\\2".freeze)
      line = line.sub(/\A([^:]+:\d+)$/, '\1'.freeze)
      return nil if line == '-e:1'.freeze
      line
    rescue SecurityError
      nil
    end

relative_path_regex() click to toggle source

Matches strings either at the beginning of the input or prefixed with a whitespace, containing the current path, either postfixed with the separator, or at the end of the string. Match groups are the character before and the character after the string if any.

rubular.com/r/fT0gmX6VJX rubular.com/r/duOrD4i3wb rubular.com/r/sbAMHFrOx1

    # File lib/rspec/core/metadata.rb, line 36
    def self.relative_path_regex
      @relative_path_regex ||= /(\A|\s)#{File.expand_path('.')}(#{File::SEPARATOR}|\s|\Z)/
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.