Class: RSpec::Hermetic::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/hermetic/configuration.rb,
sig/rspec/hermetic.rbs

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/rspec/hermetic/configuration.rb', line 34

def initialize
  @probes = %i[env constants globals ruby_runtime rails time randomness resources]
  @on_pollution = :risky
  @root_path = Dir.pwd
  @constant_namespaces = []
  @constant_exclude_patterns = []
  @constants_max_depth = 0
  @constants_max_entries = 1_000
  @constants_graph = true
  @constants_graph_max_depth = 3
  @constants_graph_max_nodes = 1_000
  @filesystem_paths = ["."]
  @filesystem_exclude_patterns = %w[
    .git
    .git/**
    .bundle
    .bundle/**
    vendor/bundle
    vendor/bundle/**
    node_modules
    node_modules/**
  ]
  @filesystem_content_hash_bytes = 64 * 1024
  @filesystem_max_entries = 1_000
  @filesystem_max_depth = nil
  @forensic = false
  @randomness_seed_probe = false
  @resource_process_probe = false
  @rails_config_paths = %w[
    cache_store
    time_zone
    active_job.queue_adapter
    action_mailer.delivery_method
    action_controller.allow_forgery_protection
    i18n.default_locale
  ]
  @probe_sampling = {}
  @report_probe_errors = true
  @candidate_report_path = "tmp/rspec_hermetic_candidates.json"
  @auto_reset = false
  @track_resource_origins = true
  @allowlist = Allowlist.new
  @allowlist.path "tmp/**", "log/**", ".rspec_status", "coverage/**"
end

Instance Attribute Details

#allowlistAllowlist (readonly)

Returns the value of attribute allowlist.

Returns:



32
33
34
# File 'lib/rspec/hermetic/configuration.rb', line 32

def allowlist
  @allowlist
end

#auto_resetObject

Returns the value of attribute auto_reset.

Returns:

  • (Object)


8
9
10
# File 'lib/rspec/hermetic/configuration.rb', line 8

def auto_reset
  @auto_reset
end

#candidate_report_pathString?

Returns the value of attribute candidate_report_path.

Returns:

  • (String, nil)


8
9
10
# File 'lib/rspec/hermetic/configuration.rb', line 8

def candidate_report_path
  @candidate_report_path
end

#constant_exclude_patternsArray[untyped]

Returns the value of attribute constant_exclude_patterns.

Returns:

  • (Array[untyped])


8
9
10
# File 'lib/rspec/hermetic/configuration.rb', line 8

def constant_exclude_patterns
  @constant_exclude_patterns
end

#constant_namespacesArray[untyped]

Returns the value of attribute constant_namespaces.

Returns:

  • (Array[untyped])


8
9
10
# File 'lib/rspec/hermetic/configuration.rb', line 8

def constant_namespaces
  @constant_namespaces
end

#constants_graphBoolean

Returns the value of attribute constants_graph.

Returns:

  • (Boolean)


8
9
10
# File 'lib/rspec/hermetic/configuration.rb', line 8

def constants_graph
  @constants_graph
end

#constants_graph_max_depthInteger

Returns the value of attribute constants_graph_max_depth.

Returns:

  • (Integer)


8
9
10
# File 'lib/rspec/hermetic/configuration.rb', line 8

def constants_graph_max_depth
  @constants_graph_max_depth
end

#constants_graph_max_nodesInteger

Returns the value of attribute constants_graph_max_nodes.

Returns:

  • (Integer)


8
9
10
# File 'lib/rspec/hermetic/configuration.rb', line 8

def constants_graph_max_nodes
  @constants_graph_max_nodes
end

#constants_max_depthInteger

Returns the value of attribute constants_max_depth.

Returns:

  • (Integer)


8
9
10
# File 'lib/rspec/hermetic/configuration.rb', line 8

def constants_max_depth
  @constants_max_depth
end

#constants_max_entriesInteger

Returns the value of attribute constants_max_entries.

Returns:

  • (Integer)


8
9
10
# File 'lib/rspec/hermetic/configuration.rb', line 8

def constants_max_entries
  @constants_max_entries
end

#filesystem_content_hash_bytesInteger

Returns the value of attribute filesystem_content_hash_bytes.

Returns:

  • (Integer)


8
9
10
# File 'lib/rspec/hermetic/configuration.rb', line 8

def filesystem_content_hash_bytes
  @filesystem_content_hash_bytes
end

#filesystem_exclude_patternsArray[String]

Returns the value of attribute filesystem_exclude_patterns.

Returns:

  • (Array[String])


8
9
10
# File 'lib/rspec/hermetic/configuration.rb', line 8

def filesystem_exclude_patterns
  @filesystem_exclude_patterns
end

#filesystem_max_depthInteger?

Returns the value of attribute filesystem_max_depth.

Returns:

  • (Integer, nil)


8
9
10
# File 'lib/rspec/hermetic/configuration.rb', line 8

def filesystem_max_depth
  @filesystem_max_depth
end

#filesystem_max_entriesInteger

Returns the value of attribute filesystem_max_entries.

Returns:

  • (Integer)


8
9
10
# File 'lib/rspec/hermetic/configuration.rb', line 8

def filesystem_max_entries
  @filesystem_max_entries
end

#filesystem_pathsArray[String]

Returns the value of attribute filesystem_paths.

Returns:

  • (Array[String])


8
9
10
# File 'lib/rspec/hermetic/configuration.rb', line 8

def filesystem_paths
  @filesystem_paths
end

#forensicBoolean

Returns the value of attribute forensic.

Returns:

  • (Boolean)


8
9
10
# File 'lib/rspec/hermetic/configuration.rb', line 8

def forensic
  @forensic
end

#on_pollutionSymbol

Returns the value of attribute on_pollution.

Returns:

  • (Symbol)


8
9
10
# File 'lib/rspec/hermetic/configuration.rb', line 8

def on_pollution
  @on_pollution
end

#probe_samplingHash[Symbol, Integer]

Returns the value of attribute probe_sampling.

Returns:

  • (Hash[Symbol, Integer])


8
9
10
# File 'lib/rspec/hermetic/configuration.rb', line 8

def probe_sampling
  @probe_sampling
end

#probesArray[Symbol]

Returns the value of attribute probes.

Returns:

  • (Array[Symbol])


8
9
10
# File 'lib/rspec/hermetic/configuration.rb', line 8

def probes
  @probes
end

#rails_config_pathsArray[String]

Returns the value of attribute rails_config_paths.

Returns:

  • (Array[String])


8
9
10
# File 'lib/rspec/hermetic/configuration.rb', line 8

def rails_config_paths
  @rails_config_paths
end

#randomness_seed_probeBoolean

Returns the value of attribute randomness_seed_probe.

Returns:

  • (Boolean)


8
9
10
# File 'lib/rspec/hermetic/configuration.rb', line 8

def randomness_seed_probe
  @randomness_seed_probe
end

#report_probe_errorsBoolean

Returns the value of attribute report_probe_errors.

Returns:

  • (Boolean)


8
9
10
# File 'lib/rspec/hermetic/configuration.rb', line 8

def report_probe_errors
  @report_probe_errors
end

#resource_process_probeBoolean

Returns the value of attribute resource_process_probe.

Returns:

  • (Boolean)


8
9
10
# File 'lib/rspec/hermetic/configuration.rb', line 8

def resource_process_probe
  @resource_process_probe
end

#root_pathString

Returns the value of attribute root_path.

Returns:

  • (String)


8
9
10
# File 'lib/rspec/hermetic/configuration.rb', line 8

def root_path
  @root_path
end

#track_resource_originsBoolean

Returns the value of attribute track_resource_origins.

Returns:

  • (Boolean)


8
9
10
# File 'lib/rspec/hermetic/configuration.rb', line 8

def track_resource_origins
  @track_resource_origins
end

Instance Method Details

#allow {|allowlist| ... } ⇒ Object

Yields:

Yield Parameters:

Yield Returns:

  • (Object)

Returns:

  • (Object)


79
80
81
# File 'lib/rspec/hermetic/configuration.rb', line 79

def allow
  yield allowlist
end

#auto_reset_probe?(name) ⇒ Boolean

Parameters:

  • (Symbol)

Returns:

  • (Boolean)


88
89
90
# File 'lib/rspec/hermetic/configuration.rb', line 88

def auto_reset_probe?(name)
  auto_reset == true || Array(auto_reset).map(&:to_sym).include?(name.to_sym)
end

#probe_interval(name) ⇒ Integer

Parameters:

  • (Symbol)

Returns:

  • (Integer)


83
84
85
86
# File 'lib/rspec/hermetic/configuration.rb', line 83

def probe_interval(name)
  interval = probe_sampling.fetch(name.to_sym, 1).to_i
  interval.positive? ? interval : 1
end