Class: TestReportHandler::TestReportBuilder
- Inherits:
-
Object
- Object
- TestReportHandler::TestReportBuilder
- Defined in:
- lib/testscript_engine/testreport_handler.rb
Instance Attribute Summary collapse
-
#actions ⇒ Object
Returns the value of attribute actions.
-
#pass_count ⇒ Object
Returns the value of attribute pass_count.
-
#total_test_count ⇒ Object
Returns the value of attribute total_test_count.
Instance Method Summary collapse
- #action ⇒ Object
- #add_boilerplate(testscript_blueprint) ⇒ Object
- #build_action(action_blueprint) ⇒ Object
- #build_assert(assert_blueprint) ⇒ Object
- #build_operation(operation_blueprint) ⇒ Object
- #build_setup(setup_blueprint) ⇒ Object
- #build_teardown(teardown_blueprint) ⇒ Object
- #build_test(test_blueprint) ⇒ Object
- #clone ⇒ Object
- #clone_actions(report_phase, clone) ⇒ Object
- #error(message = nil) ⇒ Object
- #fail(message = nil) ⇒ Object
- #finalize_report ⇒ Object
-
#initialize(testscript_blueprint = nil) ⇒ TestReportBuilder
constructor
A new instance of TestReportBuilder.
- #next_action ⇒ Object
- #pass ⇒ Object
- #report ⇒ Object
- #skip(message = nil) ⇒ Object
- #store_action(action) ⇒ Object
- #warning(message = nil) ⇒ Object
Constructor Details
#initialize(testscript_blueprint = nil) ⇒ TestReportBuilder
Returns a new instance of TestReportBuilder.
95 96 97 98 99 100 101 102 103 |
# File 'lib/testscript_engine/testreport_handler.rb', line 95 def initialize(testscript_blueprint = nil) add_boilerplate(testscript_blueprint) build_setup(testscript_blueprint.setup) build_test(testscript_blueprint.test) build_teardown(testscript_blueprint.teardown) self.pass_count = 0 self.total_test_count = actions.length end |
Instance Attribute Details
#actions ⇒ Object
Returns the value of attribute actions.
85 86 87 |
# File 'lib/testscript_engine/testreport_handler.rb', line 85 def actions @actions end |
#pass_count ⇒ Object
Returns the value of attribute pass_count.
85 86 87 |
# File 'lib/testscript_engine/testreport_handler.rb', line 85 def pass_count @pass_count end |
#total_test_count ⇒ Object
Returns the value of attribute total_test_count.
85 86 87 |
# File 'lib/testscript_engine/testreport_handler.rb', line 85 def total_test_count @total_test_count end |
Instance Method Details
#action ⇒ Object
185 186 187 |
# File 'lib/testscript_engine/testreport_handler.rb', line 185 def action actions.first end |
#add_boilerplate(testscript_blueprint) ⇒ Object
166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/testscript_engine/testreport_handler.rb', line 166 def add_boilerplate(testscript_blueprint) report.result = 'pending' report.status = 'in-progress' report.tester = 'The MITRE Corporation' report.id = testscript_blueprint.id&.gsub(/(?i)testscript/, 'testreport') report.name = testscript_blueprint.name&.gsub(/(?i)testscript/, 'TestReport') report.testScript = FHIR::Reference.new({ reference: testscript_blueprint.url, type: "http://hl7.org/fhir/R4B/testscript.html" }) end |
#build_action(action_blueprint) ⇒ Object
128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/testscript_engine/testreport_handler.rb', line 128 def build_action(action_blueprint) phase = action_blueprint.class.to_s.split("::")[2] action_definition = { id: action_blueprint.id, operation: build_operation(action_blueprint.operation), assert: (build_assert(action_blueprint.assert) unless phase == 'Teardown') } "FHIR::TestReport::#{phase}::Action".constantize.new(action_definition) end |
#build_assert(assert_blueprint) ⇒ Object
153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/testscript_engine/testreport_handler.rb', line 153 def build_assert(assert_blueprint) return unless assert_blueprint assert_def = { id: assert_blueprint.label || assert_blueprint.id || 'unlabeled assert', message: assert_blueprint.description } assert = FHIR::TestReport::Setup::Action::Assert.new(assert_def) store_action(assert) assert end |
#build_operation(operation_blueprint) ⇒ Object
140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/testscript_engine/testreport_handler.rb', line 140 def build_operation(operation_blueprint) return unless operation_blueprint operation_def = { id: operation_blueprint.label || operation_blueprint.id || 'unlabeled operation', message: operation_blueprint.description } operation = FHIR::TestReport::Setup::Action::Operation.new(operation_def) store_action(operation) operation end |
#build_setup(setup_blueprint) ⇒ Object
105 106 107 108 109 110 |
# File 'lib/testscript_engine/testreport_handler.rb', line 105 def build_setup(setup_blueprint) return unless setup_blueprint actions = setup_blueprint.action.map { |action| build_action(action) } report.setup = FHIR::TestReport::Setup.new(action: actions) end |
#build_teardown(teardown_blueprint) ⇒ Object
121 122 123 124 125 126 |
# File 'lib/testscript_engine/testreport_handler.rb', line 121 def build_teardown(teardown_blueprint) return unless teardown_blueprint actions = teardown_blueprint.action.map { |action| build_action(action) } report.teardown = FHIR::TestReport::Teardown.new(action: actions) end |
#build_test(test_blueprint) ⇒ Object
112 113 114 115 116 117 118 119 |
# File 'lib/testscript_engine/testreport_handler.rb', line 112 def build_test(test_blueprint) return if test_blueprint.empty? report.test = test_blueprint.map do |test| actions = test.action.map { |action| build_action(action) } FHIR::TestReport::Test.new(action: actions) end end |
#clone ⇒ Object
229 230 231 232 233 234 235 236 237 238 239 |
# File 'lib/testscript_engine/testreport_handler.rb', line 229 def clone builder_dup = self.deep_dup builder_dup.actions.clear builder_dup.instance_eval('@report = FHIR::TestReport.new(self.report.to_hash)') clone_actions(builder_dup.report.setup, builder_dup) builder_dup.report.test.each { |test| clone_actions(test, builder_dup) } clone_actions(builder_dup.report.teardown, builder_dup) builder_dup end |
#clone_actions(report_phase, clone) ⇒ Object
241 242 243 244 245 |
# File 'lib/testscript_engine/testreport_handler.rb', line 241 def clone_actions(report_phase, clone) report_phase.try(:action)&.each do |action| clone.store_action(action.operation || action.assert) end end |
#error(message = nil) ⇒ Object
223 224 225 226 227 |
# File 'lib/testscript_engine/testreport_handler.rb', line 223 def error( = nil) action.result = 'error' action. = if next_action end |
#fail(message = nil) ⇒ Object
217 218 219 220 221 |
# File 'lib/testscript_engine/testreport_handler.rb', line 217 def fail( = nil) action.result = 'fail' action. = if next_action end |
#finalize_report ⇒ Object
178 179 180 181 182 183 |
# File 'lib/testscript_engine/testreport_handler.rb', line 178 def finalize_report report.issued = DateTime.now.to_s report.status = 'completed' report.score = (self.pass_count.to_f / self.total_test_count).round(2) * 100 report.result = (report.score == 100.0 ? 'pass' : 'fail') end |
#next_action ⇒ Object
193 194 195 196 |
# File 'lib/testscript_engine/testreport_handler.rb', line 193 def next_action actions.shift finalize_report if actions.empty? end |
#pass ⇒ Object
198 199 200 201 202 |
# File 'lib/testscript_engine/testreport_handler.rb', line 198 def pass action.result = 'pass' self.pass_count += 1 next_action end |
#report ⇒ Object
91 92 93 |
# File 'lib/testscript_engine/testreport_handler.rb', line 91 def report @report ||= FHIR::TestReport.new end |
#skip(message = nil) ⇒ Object
204 205 206 207 208 209 |
# File 'lib/testscript_engine/testreport_handler.rb', line 204 def skip( = nil) action.result = 'skip' action. = if self.total_test_count -= 1 next_action end |
#store_action(action) ⇒ Object
189 190 191 |
# File 'lib/testscript_engine/testreport_handler.rb', line 189 def store_action(action) actions.concat(Array(action)) end |
#warning(message = nil) ⇒ Object
211 212 213 214 215 |
# File 'lib/testscript_engine/testreport_handler.rb', line 211 def warning( = nil) action.result = 'warning' action. = if next_action end |