Sha256: 3a9c874b589b63f5840a62a6bf9235a2ead0ab2b053e6e93f179bbc33d0d6763

Contents?: true

Size: 847 Bytes

Versions: 8

Compression:

Stored size: 847 Bytes

Contents

# frozen_string_literal: true

require 'dry-types'

module Helpers
  def using_test_classes
    around(:all) do |example|
      classes_before_examples = Object.constants

      save_dry_types_state

      yield

      classes_after_examples = Object.constants
      classes_created_by_block = classes_after_examples - classes_before_examples

      example.run

      clean_up_dry_types

      classes_created_by_block.each { |klass| Object.send(:remove_const, klass) }
    end
  end

  alias using_test_class using_test_classes

  private

  def save_dry_types_state
    @types = Dry::Types.container._container.keys
  end

  def clean_up_dry_types
    container = Dry::Types.container._container
    (container.keys - @types).each { |key| container.delete(key) }
    Dry::Types.instance_variable_set('@type_map', Concurrent::Map.new)
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
fortnox-api-0.8.0 spec/support/helpers/dummy_class_helper.rb
fortnox-api-0.7.2 spec/support/helpers/dummy_class_helper.rb
fortnox-api-0.7.1 spec/support/helpers/dummy_class_helper.rb
fortnox-api-0.7.0 spec/support/helpers/dummy_class_helper.rb
fortnox-api-0.6.3 spec/support/helpers/dummy_class_helper.rb
fortnox-api-0.6.2 spec/support/helpers/dummy_class_helper.rb
fortnox-api-0.6.1 spec/support/helpers/dummy_class_helper.rb
fortnox-api-0.6.0 spec/support/helpers/dummy_class_helper.rb