Class: Evilution::Integration::RSpec::StateGuard::ObjectSpaceExampleGroups

Inherits:
Object
  • Object
show all
Defined in:
lib/evilution/integration/rspec/state_guard/object_space_example_groups.rb

Instance Method Summary collapse

Instance Method Details

#release(eg_before) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/evilution/integration/rspec/state_guard/object_space_example_groups.rb', line 17

def release(eg_before)
  return unless eg_before

  ObjectSpace.each_object(Class) do |klass|
    next unless klass < ::RSpec::Core::ExampleGroup
    next if eg_before.include?(klass.object_id)

    klass.constants(false).each do |const|
      klass.send(:remove_const, const)
    rescue NameError # rubocop:disable Lint/SuppressedException
    end

    klass.instance_variables.each do |ivar|
      klass.remove_instance_variable(ivar)
    end
  rescue TypeError # rubocop:disable Lint/SuppressedException
  end
end

#snapshotObject



8
9
10
11
12
13
14
15
# File 'lib/evilution/integration/rspec/state_guard/object_space_example_groups.rb', line 8

def snapshot
  groups = Set.new
  ObjectSpace.each_object(Class) do |klass|
    groups << klass.object_id if klass < ::RSpec::Core::ExampleGroup
  rescue TypeError # rubocop:disable Lint/SuppressedException
  end
  groups
end