Class: InfernoRequirementsTools::Tasks::MapRequirements
- Inherits:
-
Object
- Object
- InfernoRequirementsTools::Tasks::MapRequirements
- Defined in:
- lib/inferno_requirements_tools/tasks/map_requirements.rb
Overview
This class manages the mapping of IG requirements to test kit tests. It expects a CSV file in the repo at lib/carin_for_blue_button_test_kit/requirements/Requirements.csv This file must have a column with the header ‘ID’ which holds user-designated IDs for each requirement. These requirement IDs must map to the IDs specified in the test kit using ‘verifies_requirements`
The ‘run` method generates a CSV file at lib/carin_for_blue_button_test_kit/requirements/Requirements_Coverage.csv. This file will be identical to the input spreadsheet, plus an additional column which holds a comma separated list of inferno test IDs that test each requirement. These test IDs are Inferno short form IDs that represent the position of the test within its group and suite. For example, the fifth test in the second group will have an ID of 2.05. This ID is also shown in the Inferno web UI. The output file is also sorted by requirement ID.
The ‘run_check` method will check whether the previously generated file is up-to-date.
Constant Summary collapse
- TEST_KIT_ID =
Update these constants based on the test kit.
'carin-for-blue-button-test-kit'
- TEST_SUITES =
list of suite classes
[CarinForBlueButtonTestKit::CARIN4BBV200::C4BBTestSuite].freeze
- SUITE_ID_TO_ACTOR_MAP =
{ 'c4bb_v200' => 'Health Plan' }.freeze
- TEST_KIT_CODE_FOLDER =
Derivative constants
TEST_KIT_ID.gsub('-', '_')
- INPUT_HEADERS =
['Req Set', 'ID', 'URL', 'Requirement', 'Conformance', 'Actor', 'Sub-Requirement(s)', 'Conditionality'].freeze
- SHORT_ID_HEADER =
'Short ID(s)'
- FULL_ID_HEADER =
'Full ID(s)'
- INPUT_FILE_NAME =
"#{TEST_KIT_ID}_requirements.csv"
- INPUT_FILE =
File.join('lib', TEST_KIT_CODE_FOLDER, 'requirements', INPUT_FILE_NAME).freeze
- NOT_TESTED_FILE_NAME =
"#{TEST_KIT_ID}_out_of_scope_requirements.csv"
- NOT_TESTED_FILE =
File.join('lib', TEST_KIT_CODE_FOLDER, 'requirements', NOT_TESTED_FILE_NAME).freeze
- OUTPUT_FILE_NAME =
"#{TEST_KIT_ID}_requirements_coverage.csv"
- OUTPUT_FILE_DIRECTORY =
File.join('lib', TEST_KIT_CODE_FOLDER, 'requirements', 'generated').freeze
- OUTPUT_FILE =
File.join(OUTPUT_FILE_DIRECTORY, OUTPUT_FILE_NAME).freeze
- BOM =
"\xEF\xBB\xBF"
Instance Method Summary collapse
-
#inferno_requirements_map ⇒ Object
Of the form: { ‘req-id-1’: [ { short_id: ‘short-id-1’, full_id: ‘long-id-1’, suite_id: ‘suite-id-1’ }, { short_id: ‘short-id-2’, full_id: ‘long-id-2’, suite_id: ‘suite-id-2’ } ], ‘req-id-2’: [{ short_id: ‘short-id-3’, full_id: ‘long-id-3’, suite_id: ‘suite-id-3’ }], … }.
- #input_requirement_ids ⇒ Object
- #input_rows ⇒ Object
- #load_not_tested_requirements ⇒ Object
- #map_group_requirements(group, suite_id, requirements_map) ⇒ Object
- #new_csv ⇒ Object
- #not_tested_requirements_map ⇒ Object
- #old_csv ⇒ Object
-
#output_requirements_map_table(requirements_map) ⇒ Object
Output the requirements in the map like so:.
- #run ⇒ Object
- #run_check ⇒ Object
- #serialize_requirements(runnable, short_id, suite_id, requirements_map) ⇒ Object
-
#unmatched_requirements_map ⇒ Object
The requirements present in Inferno that aren’t in the input spreadsheet.
Instance Method Details
#inferno_requirements_map ⇒ Object
Of the form: {
'req-id-1': [
{ short_id: 'short-id-1', full_id: 'long-id-1', suite_id: 'suite-id-1' },
{ short_id: 'short-id-2', full_id: 'long-id-2', suite_id: 'suite-id-2' }
],
'req-id-2': [{ short_id: 'short-id-3', full_id: 'long-id-3', suite_id: 'suite-id-3' }],
...
}
77 78 79 80 81 82 83 84 |
# File 'lib/inferno_requirements_tools/tasks/map_requirements.rb', line 77 def inferno_requirements_map @inferno_requirements_map ||= TEST_SUITES.each_with_object({}) do |suite, requirements_map| serialize_requirements(suite, 'suite', suite.id, requirements_map) suite.groups.each do |group| map_group_requirements(group, suite.id, requirements_map) end end end |
#input_requirement_ids ⇒ Object
124 125 126 |
# File 'lib/inferno_requirements_tools/tasks/map_requirements.rb', line 124 def input_requirement_ids @input_requirement_ids ||= input_rows.map { |row| "#{row['Req Set']}##{row['ID']}" } end |
#input_rows ⇒ Object
45 46 47 48 49 50 |
# File 'lib/inferno_requirements_tools/tasks/map_requirements.rb', line 45 def input_rows @input_rows ||= CSV.parse(File.open(INPUT_FILE, 'r:bom|utf-8'), headers: true).map do |row| row.to_h.slice(*INPUT_HEADERS) end end |
#load_not_tested_requirements ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/inferno_requirements_tools/tasks/map_requirements.rb', line 56 def load_not_tested_requirements return {} unless File.exist?(NOT_TESTED_FILE) not_tested_requirements = {} CSV.parse(File.open(NOT_TESTED_FILE, 'r:bom|utf-8'), headers: true).each do |row| row_hash = row.to_h not_tested_requirements["#{row_hash['Req Set']}##{row_hash['ID']}"] = row_hash end not_tested_requirements end |
#map_group_requirements(group, suite_id, requirements_map) ⇒ Object
205 206 207 208 209 |
# File 'lib/inferno_requirements_tools/tasks/map_requirements.rb', line 205 def map_group_requirements(group, suite_id, requirements_map) serialize_requirements(group, group.short_id, suite_id, requirements_map) group.tests&.each { |test| serialize_requirements(test, test.short_id, suite_id, requirements_map) } group.groups&.each { |subgroup| map_group_requirements(subgroup, suite_id, requirements_map) } end |
#new_csv ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/inferno_requirements_tools/tasks/map_requirements.rb', line 86 def new_csv @new_csv ||= CSV.generate do |csv| output_headers = TEST_SUITES.each_with_object(INPUT_HEADERS.dup) do |suite, headers| headers << "#{suite.title} #{SHORT_ID_HEADER}" headers << "#{suite.title} #{FULL_ID_HEADER}" end csv << output_headers input_rows.each do |row| # NOTE: use row order from source file row_actor = row['Actor'] TEST_SUITES.each do |suite| suite_actor = SUITE_ID_TO_ACTOR_MAP[suite.id] if row_actor&.include?(suite_actor) set_and_req_id = "#{row['Req Set']}##{row['ID']}" suite_requirement_items = inferno_requirements_map[set_and_req_id]&.filter do |item| item[:suite_id] == suite.id end short_ids = suite_requirement_items&.map { |item| item[:short_id] } full_ids = suite_requirement_items&.map { |item| item[:full_id] } if short_ids.blank? && not_tested_requirements_map.has_key?(set_and_req_id) row["#{suite.title} #{SHORT_ID_HEADER}"] = 'Not Tested' row["#{suite.title} #{FULL_ID_HEADER}"] = 'Not Tested' else row["#{suite.title} #{SHORT_ID_HEADER}"] = short_ids&.join(', ') row["#{suite.title} #{FULL_ID_HEADER}"] = full_ids&.join(', ') end else row["#{suite.title} #{SHORT_ID_HEADER}"] = 'NA' row["#{suite.title} #{FULL_ID_HEADER}"] = 'NA' end end csv << row.values end end end |
#not_tested_requirements_map ⇒ Object
52 53 54 |
# File 'lib/inferno_requirements_tools/tasks/map_requirements.rb', line 52 def not_tested_requirements_map @not_tested_requirements_map ||= load_not_tested_requirements end |
#old_csv ⇒ Object
135 136 137 |
# File 'lib/inferno_requirements_tools/tasks/map_requirements.rb', line 135 def old_csv @old_csv ||= File.read(OUTPUT_FILE) end |
#output_requirements_map_table(requirements_map) ⇒ Object
Output the requirements in the map like so:
requirement_id | short_id | full_id —————------------
———- req-id-1 | short-id-1 | full-id-1 req-id-2 | short-id-2 | full-id-2
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 |
# File 'lib/inferno_requirements_tools/tasks/map_requirements.rb', line 226 def output_requirements_map_table(requirements_map) headers = %w[requirement_id short_id full_id] col_widths = headers.map(&:length) col_widths[0] = [col_widths[0], requirements_map.keys.map(&:length).max].max col_widths[1] = ([col_widths[1]] + requirements_map.values.flatten.map { |item| item[:short_id].length }).max col_widths[2] = ([col_widths[2]] + requirements_map.values.flatten.map { |item| item[:full_id].length }).max col_widths.map { |width| width + 3 } puts [ headers[0].ljust(col_widths[0]), headers[1].ljust(col_widths[1]), headers[2].ljust(col_widths[2]) ].join(' | ') puts col_widths.map { |width| '-' * width }.join('-+-') requirements_map.each do |requirement_id, runnables| runnables.each do |runnable| puts [ requirement_id.ljust(col_widths[0]), runnable[:short_id].ljust(col_widths[1]), runnable[:full_id].ljust(col_widths[2]) ].join(' | ') end end puts end |
#run ⇒ Object
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/inferno_requirements_tools/tasks/map_requirements.rb', line 139 def run unless File.exist?(INPUT_FILE) puts "Could not find input file: #{INPUT_FILE}. Aborting requirements mapping..." exit(1) end if unmatched_requirements_map.any? puts "WARNING: The following requirements indicated in the test kit are not present in #{INPUT_FILE_NAME}" output_requirements_map_table(unmatched_requirements_map) end if File.exist?(OUTPUT_FILE) if old_csv == (BOM + new_csv) puts "'#{OUTPUT_FILE_NAME}' file is up to date." return else puts 'Requirements mapping has changed.' end else puts "No existing #{OUTPUT_FILE_NAME}." end puts "Writing to file #{OUTPUT_FILE}..." FileUtils.mkdir_p(OUTPUT_FILE_DIRECTORY) File.write(OUTPUT_FILE, BOM + new_csv) puts 'Done.' end |
#run_check ⇒ Object
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/inferno_requirements_tools/tasks/map_requirements.rb', line 167 def run_check unless File.exist?(INPUT_FILE) puts "Could not find input file: #{INPUT_FILE}. Aborting requirements mapping check..." exit(1) end if unmatched_requirements_map.any? puts "The following requirements indicated in the test kit are not present in #{INPUT_FILE_NAME}" output_requirements_map_table(unmatched_requirements_map) end if File.exist?(OUTPUT_FILE) if old_csv == (BOM + new_csv) puts "'#{OUTPUT_FILE_NAME}' file is up to date." return unless unmatched_requirements_map.any? else puts <<~MESSAGE #{OUTPUT_FILE_NAME} file is out of date. To regenerate the file, run: bundle exec rake requirements:map_requirements MESSAGE end else puts <<~MESSAGE No existing #{OUTPUT_FILE_NAME} file. To generate the file, run: bundle exec rake requirementss:map_requirements MESSAGE end puts 'Check failed.' exit(1) end |
#serialize_requirements(runnable, short_id, suite_id, requirements_map) ⇒ Object
211 212 213 214 215 216 217 218 |
# File 'lib/inferno_requirements_tools/tasks/map_requirements.rb', line 211 def serialize_requirements(runnable, short_id, suite_id, requirements_map) runnable.verifies_requirements&.each do |requirement_id| requirement_id_string = requirement_id.to_s requirements_map[requirement_id_string] ||= [] requirements_map[requirement_id_string] << { short_id:, full_id: runnable.id, suite_id: } end end |
#unmatched_requirements_map ⇒ Object
The requirements present in Inferno that aren’t in the input spreadsheet
129 130 131 132 133 |
# File 'lib/inferno_requirements_tools/tasks/map_requirements.rb', line 129 def unmatched_requirements_map @unmatched_requirements_map ||= inferno_requirements_map.filter do |requirement_id, _| !input_requirement_ids.include?(requirement_id) end end |