Sha256: 7f7667361b631711688c2c60e840744e6c67445929528e682e89025c89979ab4

Contents?: true

Size: 1.09 KB

Versions: 3

Compression:

Stored size: 1.09 KB

Contents

# frozen_string_literal: true

module SpecSupport
  extend self

  # @return [String]
  ARTIFACTS_PATH = File.expand_path(File.join('..', 'artifacts'), __dir__).freeze
  # @return [String]
  FIXTURES_PATH = File.expand_path(File.join('..', 'fixtures'), __dir__).freeze

  # @param parts [Array<String>]
  # @return [String]
  def fixture_path(*parts)
    File.join(FIXTURES_PATH, *parts)
  end

  # @params [Array<String>]
  # @return [String]
  def artifact_path(*parts)
    File.join(ARTIFACTS_PATH, *parts)
  end

  # @return [Boolean]
  def test_plugins?
    !!ENV['TEST_PLUGINS']
  end

  # @param object [Any]
  # @return [String]
  def from_object_id_space_to_value_space(object)
    # NOTE: see Object#object_id source code for comments
    # NOTE: it does not work on Ruby >= 2.7.0 (works on Ruby < 2.7.0 only)

    if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.7.0')
      raise 'Object ID address detection is not supported on Ruby >= 2.7'
    end

    value_space = format('%x', (object.object_id << 1))
    alignment = '0' * (16 - value_space.size)
    "#{alignment}#{value_space}"
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
qonfig-0.28.0 spec/support/spec_support.rb
qonfig-0.27.0 spec/support/spec_support.rb
qonfig-0.26.0 spec/support/spec_support.rb