lib/data_model/testing/minitest.rb in data_model-0.4.0 vs lib/data_model/testing/minitest.rb in data_model-0.5.0

- old
+ new

@@ -1,36 +1,50 @@ -# typed: strict - require "minitest/assertions" module DataModel + # Provides assertions for minitest module Testing::Minitest - extend T::Sig include Minitest::Assertions - include Kernel - sig { params(err: Error, type: Symbol, key: T.nilable(Symbol)).void } + # Assert that a child model error was found. + # @param err [Error] the error to check + # @param type [Symbol] the type of error to check for + # @param key [Array(Symbol)] limit checking to a specific child key + # @return [void] def assert_child_model_error(err, type, key = nil) + refute_nil(err) + assert(err.children.any?, "validate was successful, but should not have been") for k in key ? [key] : err.children.keys found = err.children[k]&.any? { |(t, _ctx)| t == type } assert(found, "validation was not successful, but #{type} error was not found #{err.inspect}") end end - sig { params(err: Error, type: Symbol).void } + # Assert that a model error was found. + # @param err [Error] the error to check + # @param type [Symbol] the type of error to check for + # @return [void] def assert_model_error(err, type) + refute_nil err + assert(err.base.any?, "validate was successful, but should not have been") found = err.base.any? { |(t, _ctx)| t == type } assert(found, "validation was not successful, but #{type} error was not found #{err.inspect}") end - sig { params(err: Error, type: T.nilable(Symbol), key: T.nilable(Symbol)).void } + # Assert that no child error is found + # @param err [Error] the error to check + # @param type [Symbol] the type of error to check for + # @param key [Symbol, Array<Symbol>] limit checking to a specific child key + # @return [void] def refute_child_model_error(err, type = nil, key = nil) + refute_nil(err) + if !err.any? return end if type.nil? @@ -42,12 +56,17 @@ found = err.children[k]&.any? { |(t, _ctx)| t == type } refute(found, "validation was not successful, but #{type} error was not found #{err.inspect}") end end - sig { params(err: Error, type: T.nilable(Symbol)).void } + # Assert that no base error is present + # @param err [Error] the error to check + # @param type [Symbol] the type of error to check for + # @return [void] def refute_model_error(err, type = nil) + refute_nil(err) + if !err.any? return end if type.nil? @@ -58,11 +77,16 @@ found = err.base.any? { |(t, _ctx)| t == type } refute(found, "#{type} error was found #{err.inspect}") end - sig { params(err: Error, type: T.nilable(Symbol)).void } + # Assert that no errors are present + # @param err [Error] the error to check + # @param type [Symbol] the type of error to check for + # @return [void] def refute_all_errors(err, type = nil) + refute_nil(err) + if !err.any? return end if type.nil?