Class: RSpec::Covers::Configuration
- Inherits:
-
Object
- Object
- RSpec::Covers::Configuration
- Defined in:
- lib/rspec/covers/configuration.rb,
sig/rspec/covers.rbs
Constant Summary collapse
- VALID_MODES =
%i[executed checked].freeze
- VALID_UNDECLARED_POLICIES =
%i[ignore warn risky].freeze
- VALID_RISKY_POLICIES =
%i[fail report].freeze
Instance Attribute Summary collapse
-
#allowlist ⇒ Array[String]
Returns the value of attribute allowlist.
-
#json_events ⇒ Boolean
Returns the value of attribute json_events.
-
#mode ⇒ Symbol
Returns the value of attribute mode.
-
#production_paths ⇒ Array[String]
Returns the value of attribute production_paths.
-
#report_path ⇒ String?
Returns the value of attribute report_path.
-
#risky ⇒ Symbol
Returns the value of attribute risky.
-
#root ⇒ String
Returns the value of attribute root.
-
#strict ⇒ Boolean
Returns the value of attribute strict.
-
#suggest ⇒ Boolean
Returns the value of attribute suggest.
-
#suggestion_limit ⇒ Object
Returns the value of attribute suggestion_limit.
-
#suggestion_weights ⇒ Object
Returns the value of attribute suggestion_weights.
-
#undeclared ⇒ Symbol
Returns the value of attribute undeclared.
-
#validate_declarations ⇒ Boolean
Returns the value of attribute validate_declarations.
-
#validation_threshold ⇒ Float
Returns the value of attribute validation_threshold.
Instance Method Summary collapse
- #allowlisted?(path) ⇒ Boolean
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #production_file?(path) ⇒ Boolean
- #production_files ⇒ Object
- #relative_path(path) ⇒ Object
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/rspec/covers/configuration.rb', line 17 def initialize @strict = false @mode = :executed @undeclared = :ignore @allowlist = [] @suggest = false @root = Dir.pwd @production_paths = %w[app lib] @suggestion_weights = { nc: 1.0, ncc: 1.0, lcba: 1.0, dynamic: 1.0 } @suggestion_limit = 3 @report_path = nil @validate_declarations = true @validation_threshold = 0.2 @risky = :fail @json_events = false end |
Instance Attribute Details
#allowlist ⇒ Array[String]
Returns the value of attribute allowlist.
12 13 14 |
# File 'lib/rspec/covers/configuration.rb', line 12 def allowlist @allowlist end |
#json_events ⇒ Boolean
Returns the value of attribute json_events.
12 13 14 |
# File 'lib/rspec/covers/configuration.rb', line 12 def json_events @json_events end |
#mode ⇒ Symbol
Returns the value of attribute mode.
39 40 41 |
# File 'lib/rspec/covers/configuration.rb', line 39 def mode @mode end |
#production_paths ⇒ Array[String]
Returns the value of attribute production_paths.
12 13 14 |
# File 'lib/rspec/covers/configuration.rb', line 12 def production_paths @production_paths end |
#report_path ⇒ String?
Returns the value of attribute report_path.
12 13 14 |
# File 'lib/rspec/covers/configuration.rb', line 12 def report_path @report_path end |
#risky ⇒ Symbol
Returns the value of attribute risky.
39 40 41 |
# File 'lib/rspec/covers/configuration.rb', line 39 def risky @risky end |
#root ⇒ String
Returns the value of attribute root.
12 13 14 |
# File 'lib/rspec/covers/configuration.rb', line 12 def root @root end |
#strict ⇒ Boolean
Returns the value of attribute strict.
12 13 14 |
# File 'lib/rspec/covers/configuration.rb', line 12 def strict @strict end |
#suggest ⇒ Boolean
Returns the value of attribute suggest.
12 13 14 |
# File 'lib/rspec/covers/configuration.rb', line 12 def suggest @suggest end |
#suggestion_limit ⇒ Object
Returns the value of attribute suggestion_limit.
12 13 14 |
# File 'lib/rspec/covers/configuration.rb', line 12 def suggestion_limit @suggestion_limit end |
#suggestion_weights ⇒ Object
Returns the value of attribute suggestion_weights.
12 13 14 |
# File 'lib/rspec/covers/configuration.rb', line 12 def suggestion_weights @suggestion_weights end |
#undeclared ⇒ Symbol
Returns the value of attribute undeclared.
39 40 41 |
# File 'lib/rspec/covers/configuration.rb', line 39 def undeclared @undeclared end |
#validate_declarations ⇒ Boolean
Returns the value of attribute validate_declarations.
12 13 14 |
# File 'lib/rspec/covers/configuration.rb', line 12 def validate_declarations @validate_declarations end |
#validation_threshold ⇒ Float
Returns the value of attribute validation_threshold.
12 13 14 |
# File 'lib/rspec/covers/configuration.rb', line 12 def validation_threshold @validation_threshold end |
Instance Method Details
#allowlisted?(path) ⇒ Boolean
87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/rspec/covers/configuration.rb', line 87 def allowlisted?(path) absolute = File.(path) relative = relative_path(absolute) Array(allowlist).any? do |pattern| = File.(pattern.to_s, ) File.fnmatch?(pattern.to_s, relative, File::FNM_PATHNAME | File::FNM_EXTGLOB) || File.fnmatch?(, absolute, File::FNM_PATHNAME | File::FNM_EXTGLOB) end end |
#production_file?(path) ⇒ Boolean
68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/rspec/covers/configuration.rb', line 68 def production_file?(path) absolute = File.(path) return false unless absolute.start_with?("#{}#{File::SEPARATOR}") return false unless File.extname(absolute) == ".rb" relative = relative_path(absolute) return false if relative.start_with?("spec/", "test/", "tmp/", ".") return false if allowlisted?(absolute) production_paths.any? { |pattern| production_path_match?(relative, pattern) } end |
#production_files ⇒ Object
80 81 82 83 84 85 |
# File 'lib/rspec/covers/configuration.rb', line 80 def production_files production_paths.flat_map { |path| files_for_production_path(path) } .map { |path| File.(path) } .select { |path| production_file?(path) } .uniq end |
#relative_path(path) ⇒ Object
99 100 101 102 103 |
# File 'lib/rspec/covers/configuration.rb', line 99 def relative_path(path) Pathname.new(File.(path)).relative_path_from(Pathname.new()).to_s rescue ArgumentError File.(path) end |