Class: Henitai::Integration::LoadedFeatures

Inherits:
Object
  • Object
show all
Defined in:
lib/henitai/integration/loaded_features.rb,
sig/henitai.rbs

Overview

Answers whether a test file has already been required, by matching it against $LOADED_FEATURES.

Both sides need normalizing: $LOADED_FEATURES holds absolute paths for required files but callers hand over repository-relative test paths, and either side may or may not carry the .rb suffix. A feature string that cannot be expanded (invalid encoding, for instance) falls back to its raw form rather than aborting the whole check — this runs inside a mutant child whose only job is diagnostics.

Instance Method Summary collapse

Instance Method Details

#candidates_for(file) ⇒ Array[String]

Parameters:

  • (String)

Returns:

  • (Array[String])


26
27
28
29
# File 'lib/henitai/integration/loaded_features.rb', line 26

def candidates_for(file)
  expanded = File.expand_path(file)
  [expanded, "#{expanded}.rb", file, "#{file}.rb"].uniq
end

#include?(file) ⇒ Boolean

Parameters:

  • (String)

Returns:

  • (Boolean)


15
16
17
18
19
20
# File 'lib/henitai/integration/loaded_features.rb', line 15

def include?(file)
  candidates = candidates_for(file)
  $LOADED_FEATURES.any? do |feature|
    candidates.include?(feature) || candidates.include?(normalize(feature))
  end
end

#map(files) ⇒ Array[[String, bool]]

Parameters:

  • (Array[String])

Returns:

  • (Array[[String, bool]])


22
# File 'lib/henitai/integration/loaded_features.rb', line 22

def map(files) = files.map { |file| [file, include?(file)] }

#normalize(feature) ⇒ String

Parameters:

  • (String)

Returns:

  • (String)


31
32
33
34
35
# File 'lib/henitai/integration/loaded_features.rb', line 31

def normalize(feature)
  File.expand_path(feature)
rescue StandardError
  feature
end