Module: DataModel::Testing::Minitest
- Includes:
- Minitest::Assertions
- Defined in:
- lib/data_model/testing/minitest.rb
Overview
Provides assertions for minitest
Instance Method Summary collapse
-
#assert_child_model_error(err, type, key = nil) ⇒ void
Assert that a child model error was found.
-
#assert_model_error(err, type) ⇒ void
Assert that a model error was found.
-
#refute_all_errors(err, type = nil) ⇒ void
Assert that no errors are present.
-
#refute_child_model_error(err, type = nil, key = nil) ⇒ void
Assert that no child error is found.
-
#refute_model_error(err, type = nil) ⇒ void
Assert that no base error is present.
Instance Method Details
#assert_child_model_error(err, type, key = nil) ⇒ void
This method returns an undefined value.
Assert that a child model error was found.
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/data_model/testing/minitest.rb', line 13 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 |
#assert_model_error(err, type) ⇒ void
This method returns an undefined value.
Assert that a model error was found.
28 29 30 31 32 33 34 35 36 |
# File 'lib/data_model/testing/minitest.rb', line 28 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 |
#refute_all_errors(err, type = nil) ⇒ void
This method returns an undefined value.
Assert that no errors are present
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/data_model/testing/minitest.rb', line 86 def refute_all_errors(err, type = nil) refute_nil(err) if !err.any? return end if type.nil? refute(err.all.any?, "validation was not successful #{err.inspect}") return end found = err.all.any? { |(t, _ctx)| t == type } refute(found, "#{type} error was found #{err.inspect}") end |
#refute_child_model_error(err, type = nil, key = nil) ⇒ void
This method returns an undefined value.
Assert that no child error is found
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/data_model/testing/minitest.rb', line 43 def refute_child_model_error(err, type = nil, key = nil) refute_nil(err) if !err.any? return end if type.nil? refute(err.base.any?, "validation was not successful #{err.inspect}") return end for k in key ? [key] : err.children.keys 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 |
#refute_model_error(err, type = nil) ⇒ void
This method returns an undefined value.
Assert that no base error is present
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/data_model/testing/minitest.rb', line 65 def refute_model_error(err, type = nil) refute_nil(err) if !err.any? return end if type.nil? refute(err.base.any?, "validation was not successful #{err.inspect}") return end found = err.base.any? { |(t, _ctx)| t == type } refute(found, "#{type} error was found #{err.inspect}") end |