Class: RSpec::Core::MemoizedHelpers::ContextHookMemoized

Inherits:
Object
  • Object
show all
Defined in:
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/memoized_helpers.rb

Overview

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

Direct Known Subclasses

After, Before

Defined Under Namespace

Classes: After, Before

Class Method Summary collapse

Class Method Details

.fetch_or_store(key, &_block) ⇒ Object



222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/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) ⇒ Object



201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/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