Class: Evilution::Integration::RSpec::StateGuard::ObjectSpaceExampleGroups
- Inherits:
-
Object
- Object
- Evilution::Integration::RSpec::StateGuard::ObjectSpaceExampleGroups
- Defined in:
- lib/evilution/integration/rspec/state_guard/object_space_example_groups.rb
Instance Method Summary collapse
Instance Method Details
#release(eg_before) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/evilution/integration/rspec/state_guard/object_space_example_groups.rb', line 20 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 # Constant may have been removed concurrently (e.g. via autoload # reload) between #constants(false) and #remove_const. Best-effort # cleanup — nothing to do if it's already gone. end klass.instance_variables.each do |ivar| klass.remove_instance_variable(ivar) end rescue TypeError # Same defensive case as #snapshot: skip classes whose `<` raises # mid-iteration. end end |
#snapshot ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 |
# 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 # ObjectSpace iteration may surface partially-initialized or anonymous # classes whose `<` comparison raises. Skipping them is safe — they # cannot be ExampleGroup descendants we need to track. end groups end |