diff --git a/lib/au_core_test_kit/assert_helpers.rb b/lib/au_core_test_kit/assert_helpers.rb new file mode 100644 index 00000000..6b903975 --- /dev/null +++ b/lib/au_core_test_kit/assert_helpers.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +module AUCoreTestKit + module AssertHelpers + extend Forwardable + + def_delegators 'properties', + :conditional_skip_with_msg, + :skip_with_msg + + def act_if_with_message(act_func, condition, message) + info message if condition + + act_func.call(condition, message) + end + + def act_with_message(act_func, message) + info message + + act_func.call(message) + end + + def conditional_skip_with_msg(condition, message) + act_if_with_message(method(:skip_if), condition, message) + end + + def skip_with_msg(message) + act_with_message(method(:skip), message) + end + end +end diff --git a/lib/au_core_test_kit/must_support_test.rb b/lib/au_core_test_kit/must_support_test.rb index ad8ef6cf..ff12ed8a 100644 --- a/lib/au_core_test_kit/must_support_test.rb +++ b/lib/au_core_test_kit/must_support_test.rb @@ -2,11 +2,13 @@ require_relative 'fhir_resource_navigation' require_relative 'helpers' +require_relative 'assert_helpers' module AUCoreTestKit module MustSupportTest extend Forwardable include FHIRResourceNavigation + include AssertHelpers def_delegators 'self.class', :metadata @@ -15,7 +17,7 @@ def all_scratch_resources end def perform_must_support_test(resources) - skip_if resources.blank?, "No #{resource_type} resources were found" + conditional_skip_with_msg resources.blank?, "No #{resource_type} resources were found" missing_elements(resources) missing_slices(resources) @@ -24,7 +26,7 @@ def perform_must_support_test(resources) handle_must_support_choices if metadata.must_supports[:choices].present? pass if (missing_elements + missing_slices + missing_extensions).empty? - skip "Could not find #{missing_must_support_strings.join(', ')} element(s) in the #{resources.length} " \ + skip_with_msg "Could not find #{missing_must_support_strings.join(', ')} element(s) in the #{resources.length} " \ "provided #{resource_type} resource(s). To prevent this issue, please add the missing must support "\ "elements to at least one #{resource_type} resource on the server." end diff --git a/lib/au_core_test_kit/reference_resolution_test.rb b/lib/au_core_test_kit/reference_resolution_test.rb index 17f02707..9bd086a7 100644 --- a/lib/au_core_test_kit/reference_resolution_test.rb +++ b/lib/au_core_test_kit/reference_resolution_test.rb @@ -1,20 +1,22 @@ # frozen_string_literal: true require_relative 'fhir_resource_navigation' +require_relative 'assert_helpers' module AUCoreTestKit module ReferenceResolutionTest extend Forwardable include FHIRResourceNavigation + include AssertHelpers def_delegators 'self.class', :metadata def perform_reference_resolution_test(resources) - skip_if resources.blank?, no_resources_skip_message + conditional_skip_with_msg resources.blank?, no_resources_skip_message pass if unresolved_references(resources).empty? - skip "Could not resolve and validate any Must Support references for #{unresolved_references_strings.join(', ')}" + skip_with_msg "Could not resolve and validate any Must Support references for #{unresolved_references_strings.join(', ')}" end def unresolved_references_strings diff --git a/lib/au_core_test_kit/search_test.rb b/lib/au_core_test_kit/search_test.rb index 4a3f476f..3769966f 100644 --- a/lib/au_core_test_kit/search_test.rb +++ b/lib/au_core_test_kit/search_test.rb @@ -4,6 +4,7 @@ require_relative 'fhir_resource_navigation' require_relative 'search_test_properties' require_relative 'read_test' +require_relative 'assert_helpers' module AUCoreTestKit module SearchTest @@ -11,6 +12,7 @@ module SearchTest include DateSearchValidation include FHIRResourceNavigation include ReadTest + include AssertHelpers def_delegators 'self.class', :metadata, :provenance_metadata, :properties def_delegators 'properties', @@ -62,7 +64,7 @@ def any_valid_search_params?(search_params) def run_provenance_revinclude_search_test # TODO: skip if not supported? - skip_if !any_valid_search_params?(all_provenance_revinclude_search_params), unable_to_resolve_params_message + conditional_skip_with_msg !any_valid_search_params?(all_provenance_revinclude_search_params), unable_to_resolve_params_message provenance_resources = all_provenance_revinclude_search_params.flat_map do |_patient_id, params_list| @@ -900,7 +902,7 @@ def check_resource_against_params(resource, params) private def run_search_test_common(search_method) - skip_if !any_valid_search_params?(all_search_params), unable_to_resolve_params_message + conditional_skip_with_msg !any_valid_search_params?(all_search_params), unable_to_resolve_params_message ability_to_search_is_checked = false search_is_available = true @@ -924,7 +926,7 @@ def run_search_test_common(search_method) end end - skip_if resources_returned.empty?, no_resources_skip_message + conditional_skip_with_msg resources_returned.empty?, no_resources_skip_message return unless search_is_available == false diff --git a/lib/au_core_test_kit/special_identifier_search_test.rb b/lib/au_core_test_kit/special_identifier_search_test.rb index cc1a1bed..db523a87 100644 --- a/lib/au_core_test_kit/special_identifier_search_test.rb +++ b/lib/au_core_test_kit/special_identifier_search_test.rb @@ -2,11 +2,13 @@ require_relative 'search_test_properties' require_relative 'search_test' +require_relative 'assert_helpers' module AUCoreTestKit module SpecialIdentifierSearchTest extend Forwardable include SearchTest + include AssertHelpers def_delegators 'self.class', :metadata, :provenance_metadata, :properties def_delegators 'properties', @@ -78,15 +80,15 @@ def search_param_value(_name, resource, include_system: false) end def run_special_identifier_search_test - skip_if scratch_resources[:all].empty?, no_resources_skip_message - skip_if !any_valid_search_params?(all_search_params), unable_to_resolve_params_message + conditional_skip_with_msg scratch_resources[:all].empty?, no_resources_skip_message + conditional_skip_with_msg !any_valid_search_params?(all_search_params), unable_to_resolve_params_message resources_returned = all_search_params.flat_map do |patient_id, params_list| params_list.flat_map { |params| perform_search_with_system(params, patient_id) } end - skip_if resources_returned.empty?, no_resources_skip_message + conditional_skip_with_msg resources_returned.empty?, no_resources_skip_message end end end diff --git a/lib/au_core_test_kit/validation_test.rb b/lib/au_core_test_kit/validation_test.rb index 3c47a3e3..e78e9808 100644 --- a/lib/au_core_test_kit/validation_test.rb +++ b/lib/au_core_test_kit/validation_test.rb @@ -1,7 +1,11 @@ # frozen_string_literal: true +require_relative 'assert_helpers' + module AUCoreTestKit module ValidationTest + include AssertHelpers + DAR_CODE_SYSTEM_URL = 'http://terminology.hl7.org/CodeSystem/data-absent-reason' DAR_EXTENSION_URL = 'http://hl7.org/fhir/StructureDefinition/data-absent-reason' @@ -10,8 +14,8 @@ def perform_validation_test(resources, profile_version, skip_if_empty: true) - skip_if skip_if_empty && resources.blank?, - "No #{resource_type} resources conforming to the #{profile_url} profile were returned" + conditional_skip_with_msg skip_if_empty && resources.blank?, + "No #{resource_type} resources conforming to the #{profile_url} profile were returned" omit_if resources.blank?, "No #{resource_type} resources provided so the #{profile_url} profile does not apply"