Class: RSpec::Core::MemoizedHelpers::ContextHookMemoized Private
Do not use. This class is for internal use only.
Relationships & Source Files | |
Namespace Children | |
Classes:
| |
Extension / Inclusion / Inheritance Descendants | |
Subclasses:
RSpec::Core::MemoizedHelpers::ContextHookMemoized::After, RSpec::Core::MemoizedHelpers::ContextHookMemoized::Before
|
|
Inherits: | Object |
Defined in: | rspec-core/lib/rspec/core/memoized_helpers.rb |
Overview
Used internally to customize the behavior of the memoized hash when used in a ‘before(:context)` hook.
Class Method Summary
- .fetch_or_store(key, &_block) Internal use only
- .isolate_for_context_hook(example_group_instance) Internal use only
Class Method Details
.fetch_or_store(key, &_block)
[ GitHub ]# File 'rspec-core/lib/rspec/core/memoized_helpers.rb', line 222
def self.fetch_or_store(key, &_block) description = if key == :subject "subject" else "let declaration `#{key}`" end raise <<-EOS #{description} accessed in #{article} #{hook_expression} hook at: #{CallerFilter.first_non_rspec_line} `let` and `subject` declarations are not intended to be called in #{article} #{hook_expression} hook, as they exist to define state that is reset between each example, while #{hook_expression} exists to #{hook_intention}. EOS end
.isolate_for_context_hook(example_group_instance)
[ GitHub ]# File 'rspec-core/lib/rspec/core/memoized_helpers.rb', line 201
def self.isolate_for_context_hook(example_group_instance) exploding_memoized = self example_group_instance.instance_exec do @__memoized = exploding_memoized begin yield ensure # This is doing a reset instead of just isolating for context hook. # Really, this should set the old @__memoized back into place. # # Caller is the before and after context hooks # which are both called from self.run # I didn't look at why it made tests fail, maybe an object was getting reused in RSpec tests, # if so, then that probably already works, and its the tests that are wrong. __init_memoized end end end