Class: FeatureMap::Private::TestPyramidFile
- Inherits:
-
Object
- Object
- FeatureMap::Private::TestPyramidFile
- Defined in:
- lib/feature_map/private/test_pyramid_file.rb
Overview
This class is responsible for compiling a set of feature-level test pyramid statistics into a test-pyramid.yml This file can then be used as an input to a variety of engineering team utilities (e.g. PR/release announcements, documentation generation, etc).
Defined Under Namespace
Classes: FileContentError
Constant Summary collapse
- FEATURES_KEY =
'features'
Class Method Summary collapse
- .generate_content(unit_by_feature, integration_by_feature, regression_by_feature) ⇒ Object
- .header_comment ⇒ Object
- .load_features! ⇒ Object
- .path ⇒ Object
- .write!(unit_by_feature, integration_by_feature, regression_by_feature) ⇒ Object
Class Method Details
.generate_content(unit_by_feature, integration_by_feature, regression_by_feature) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/feature_map/private/test_pyramid_file.rb', line 40 def self.generate_content(unit_by_feature, integration_by_feature, regression_by_feature) CodeFeatures.all.map(&:name).each_with_object({}) do |feature_name, content| content[feature_name] = { 'unit_count' => unit_by_feature.dig(feature_name, :count) || 0, 'unit_pending' => unit_by_feature.dig(feature_name, :pending) || 0, 'integration_count' => integration_by_feature.dig(feature_name, :count) || 0, 'integration_pending' => integration_by_feature.dig(feature_name, :pending) || 0, 'regression_count' => regression_by_feature.dig(feature_name, :count) || 0, 'regression_pending' => regression_by_feature.dig(feature_name, :pending) || 0 } end end |
.header_comment ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/feature_map/private/test_pyramid_file.rb', line 26 def self.header_comment <<~HEADER # STOP! - DO NOT EDIT THIS FILE MANUALLY # This file was automatically generated by "bin/featuremap test_pyramid". The next time this file # is generated any changes will be lost. For more details: # https://github.com/Beyond-Finance/feature_map # # It is NOT recommended to commit this file into your source control. It will change or become # outdated frequently. Instead it should be regenerated when test pyramid statistics are required. # This file should be ignored by your source control, allowing the local copy to be used for other # feature analysis operations (e.g. documentation generation, etc). HEADER end |
.load_features! ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/feature_map/private/test_pyramid_file.rb', line 53 def self.load_features! test_coverage_content = YAML.load_file(path) return test_coverage_content[FEATURES_KEY] if test_coverage_content.is_a?(Hash) && test_coverage_content[FEATURES_KEY] raise FileContentError, "Unexpected content found in #{path}. Use `bin/featuremap test_coverage` to regenerate it and try again." rescue Psych::SyntaxError => e raise FileContentError, "Invalid YAML content found at #{path}. Error: #{e.} Use `bin/featuremap test_coverage` to generate it and try again." rescue Errno::ENOENT raise FileContentError, "No feature test coverage file found at #{path}. Use `bin/featuremap test_coverage` to generate it and try again." end |
.path ⇒ Object
22 23 24 |
# File 'lib/feature_map/private/test_pyramid_file.rb', line 22 def self.path Pathname.pwd.join('.feature_map/test-pyramid.yml') end |
.write!(unit_by_feature, integration_by_feature, regression_by_feature) ⇒ Object
16 17 18 19 20 |
# File 'lib/feature_map/private/test_pyramid_file.rb', line 16 def self.write!(unit_by_feature, integration_by_feature, regression_by_feature) FileUtils.mkdir_p(path.dirname) if !path.dirname.exist? content = generate_content(unit_by_feature, integration_by_feature, regression_by_feature) path.write([header_comment, "\n", { FEATURES_KEY => content }.to_yaml].join) end |