Module: DataModel::Testing::Minitest

Includes:
Minitest::Assertions
Defined in:
lib/data_model/testing/minitest.rb

Overview

Provides assertions for minitest

Instance Method Summary collapse

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.

Parameters:

  • err (Error)

    the error to check

  • type (Symbol)

    the type of error to check for

  • key (Array(Symbol)) (defaults to: nil)

    limit checking to a specific child key



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.

Parameters:

  • err (Error)

    the error to check

  • type (Symbol)

    the type of error to check for



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

Parameters:

  • err (Error)

    the error to check

  • type (Symbol) (defaults to: nil)

    the type of error to check for



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

Parameters:

  • err (Error)

    the error to check

  • type (Symbol) (defaults to: nil)

    the type of error to check for

  • key (Symbol, Array<Symbol>) (defaults to: nil)

    limit checking to a specific child key



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

Parameters:

  • err (Error)

    the error to check

  • type (Symbol) (defaults to: nil)

    the type of error to check for



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