Parent

Class/Module Index [+]

Quicksearch

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 91
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 86
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 126
def []=(key, value)
  @hash[key] = value
end
fetch(key, &block) click to toggle source
# File lib/rspec/core/memoized_helpers.rb, line 104
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 130
def preserve_accessed_lets
  hash = @hash

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

[Validate]

Generated with the Darkfish Rdoc Generator 2.