Class: Coatepec::Spec::PathPolicy

Inherits:
Object
  • Object
show all
Defined in:
lib/coatepec/spec/path_policy.rb

Overview

Validates rails_spec_run's paths selectors against the allowed spec roots before any RSpec process is started, rejecting absolute paths, .. traversal, symlink escapes, non-_spec.rb files, and oversized selector lists.

Constant Summary collapse

MAX_SELECTORS =
100

Instance Method Summary collapse

Constructor Details

#initialize(project) ⇒ PathPolicy

Returns a new instance of PathPolicy.



12
13
14
# File 'lib/coatepec/spec/path_policy.rb', line 12

def initialize(project)
  @project = project
end

Instance Method Details

#validate!(selectors) ⇒ Object

Raises:



16
17
18
19
20
21
22
23
# File 'lib/coatepec/spec/path_policy.rb', line 16

def validate!(selectors)
  raise Coatepec::Error.new(:invalid_spec_path, "No spec paths given") if selectors.nil? || selectors.empty?
  if selectors.size > MAX_SELECTORS
    raise Coatepec::Error.new(:invalid_spec_path, "At most #{MAX_SELECTORS} spec paths are allowed")
  end

  selectors.map { |selector| validate_one(selector) }
end