Class: RSpec::Core::MemoizedHelpers::BeforeAllMemoizedHash

### Home Classes Methods

### In Files

- lib/rspec/core/memoized_helpers.rb

### Parent

Object

### Methods

- ::isolate_for_before_all
- ::new
- #[]=
- #fetch
- #preserve_accessed_lets

### 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::MemoizedHelpers::BeforeAllMemoizedHash

Used internally to customize the behavior of the memoized hash when used in a `before(:all)` hook.

@private

### Public Class Methods

isolate_for_before_all(example_group_instance) click to toggle source

    # File lib/rspec/core/memoized_helpers.rb, line 102
    def self.isolate_for_before_all(example_group_instance)
      example_group_instance.instance_eval do
        @__memoized = BeforeAllMemoizedHash.new(self)

        begin
          yield
        ensure
          @__memoized.preserve_accessed_lets
          @__memoized = nil
        end
      end
    end

new(example_group_instance) click to toggle source

    # File lib/rspec/core/memoized_helpers.rb, line 97
    def initialize(example_group_instance)
      @example_group_instance = example_group_instance
      @hash = {}
    end

### Public Instance Methods

[]=(key, value) click to toggle source

    # File lib/rspec/core/memoized_helpers.rb, line 137
    def []=(key, value)
      @hash[key] = value
    end

fetch(key, &block) click to toggle source

    # File lib/rspec/core/memoized_helpers.rb, line 115
    def fetch(key, &block)
      description = if key == :subject
        "subject"
      else
        "let declaration `#{key}`"
      end

      ::RSpec.warn_deprecation WARNING: #{description} accessed in a `before(:all)` hook at:  #{caller[1]}This is deprecated behavior that will not be supported in RSpec 3.`let` and `subject` declarations are not intended to be calledin a `before(:all)` hook, as they exist to define state thatis reset between each example, while `before(:all)` exists todefine state that is shared across examples in an example group.

      @hash.fetch(key, &block)
    end

preserve_accessed_lets() click to toggle source

    # File lib/rspec/core/memoized_helpers.rb, line 141
    def preserve_accessed_lets
      hash = @hash

      @example_group_instance.class.class_eval do
        hash.each do |key, value|
          undef_method(key) if method_defined?(key)
          define_method(key) { value }
        end
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.